mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 22:41:57 +00:00
585cf8fdb8
## Description: Prevent unholly alliances with the undead. ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced - [x] I have read and accepted the CLA aggreement (only required once). ## Please put your Discord username so you can be contacted if a bug or regression is found: IngloriousTom
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { AllianceExtensionExecution } from "../src/core/execution/alliance/AllianceExtensionExecution";
|
|
import { AllianceRequestExecution } from "../src/core/execution/alliance/AllianceRequestExecution";
|
|
import { AllianceRequestReplyExecution } from "../src/core/execution/alliance/AllianceRequestReplyExecution";
|
|
import { Game, Player, PlayerType } from "../src/core/game/Game";
|
|
import { playerInfo, setup } from "./util/Setup";
|
|
|
|
let game: Game;
|
|
let player1: Player;
|
|
let player2: Player;
|
|
|
|
describe("AllianceExtensionExecution", () => {
|
|
beforeEach(async () => {
|
|
game = await setup(
|
|
"ocean_and_land",
|
|
{
|
|
infiniteGold: true,
|
|
instantBuild: true,
|
|
infiniteTroops: true,
|
|
},
|
|
[
|
|
playerInfo("player1", PlayerType.Human),
|
|
playerInfo("player2", PlayerType.Human),
|
|
],
|
|
);
|
|
|
|
player1 = game.player("player1");
|
|
player2 = game.player("player2");
|
|
|
|
while (game.inSpawnPhase()) {
|
|
game.executeNextTick();
|
|
}
|
|
});
|
|
|
|
test("Successfully extends existing alliance", () => {
|
|
jest.spyOn(player1, "canSendAllianceRequest").mockReturnValue(true);
|
|
game.addExecution(new AllianceRequestExecution(player1, player2.id()));
|
|
game.executeNextTick();
|
|
game.executeNextTick();
|
|
|
|
game.addExecution(
|
|
new AllianceRequestReplyExecution(player1.id(), player2, true),
|
|
);
|
|
game.executeNextTick();
|
|
game.executeNextTick();
|
|
|
|
expect(player1.allianceWith(player2)).toBeTruthy();
|
|
expect(player2.allianceWith(player1)).toBeTruthy();
|
|
|
|
const allianceBefore = player1.allianceWith(player2)!;
|
|
const expirationBefore =
|
|
allianceBefore.createdAt() + game.config().allianceDuration();
|
|
|
|
game.addExecution(new AllianceExtensionExecution(player1, player2.id()));
|
|
game.executeNextTick();
|
|
|
|
const allianceAfter = player1.allianceWith(player2)!;
|
|
|
|
expect(allianceAfter.id()).toBe(allianceBefore.id());
|
|
|
|
const expirationAfter =
|
|
allianceAfter.createdAt() + game.config().allianceDuration();
|
|
|
|
expect(expirationAfter).toBeGreaterThanOrEqual(expirationBefore);
|
|
});
|
|
|
|
test("Fails gracefully if no alliance exists", () => {
|
|
game.addExecution(new AllianceExtensionExecution(player1, player2.id()));
|
|
game.executeNextTick();
|
|
|
|
expect(player1.allianceWith(player2)).toBeFalsy();
|
|
expect(player2.allianceWith(player1)).toBeFalsy();
|
|
});
|
|
});
|