Files
OpenFrontIO/tests/AllianceExtensionExecution.test.ts
evanpelle 5b5ac7bfca allow alliance extension Fixes #491 (#1314)
## Description:

About 30s before an alliance is about to expire, both players receive a
prompt to extend the alliance. If both players agree the alliance is
extended.

## 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 understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

evan
2025-07-02 15:25:20 -07:00

73 lines
2.2 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", () => {
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();
});
});