From 86a06821a551349cdb9bcff76243d15848dac828 Mon Sep 17 00:00:00 2001 From: Brandon Yi Date: Sat, 26 Jul 2025 01:10:47 -0700 Subject: [PATCH] Ensuring that MutableAlliance::extend is called in test case (#1582) ## Description: A test case for AllianceExtensionExecution was not actually checking if the alliance was extended correctly. The method to extend the alliance, MutableAlliance::extend, was never called during execution of AllianceExtensionExecution. The reason the extend() method was not being called is because both mock players were not alive. This PR spies on the MutableAlliance object to verify that extend() is correctly called. Related: https://github.com/openfrontio/OpenFrontIO/pull/1536 ## 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 agreement (only required once). ## Please put your Discord username so you can be contacted if a bug or regression is found: bypie5 --- tests/AllianceExtensionExecution.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/AllianceExtensionExecution.test.ts b/tests/AllianceExtensionExecution.test.ts index 98bd93af1..8e4cbcebb 100644 --- a/tests/AllianceExtensionExecution.test.ts +++ b/tests/AllianceExtensionExecution.test.ts @@ -33,6 +33,9 @@ describe("AllianceExtensionExecution", () => { test("Successfully extends existing alliance", () => { jest.spyOn(player1, "canSendAllianceRequest").mockReturnValue(true); + jest.spyOn(player2, "isAlive").mockReturnValue(true); + jest.spyOn(player1, "isAlive").mockReturnValue(true); + game.addExecution(new AllianceRequestExecution(player1, player2.id())); game.executeNextTick(); game.executeNextTick(); @@ -47,11 +50,15 @@ describe("AllianceExtensionExecution", () => { expect(player2.allianceWith(player1)).toBeTruthy(); const allianceBefore = player1.allianceWith(player2)!; + const allianceSpy = jest.spyOn(allianceBefore, "extend"); const expirationBefore = allianceBefore.createdAt() + game.config().allianceDuration(); game.addExecution(new AllianceExtensionExecution(player1, player2.id())); game.executeNextTick(); + expect(allianceSpy).toHaveBeenCalledTimes(0); // both players must agree to extend + game.addExecution(new AllianceExtensionExecution(player2, player1.id())); + game.executeNextTick(); const allianceAfter = player1.allianceWith(player2)!; @@ -61,6 +68,7 @@ describe("AllianceExtensionExecution", () => { allianceAfter.createdAt() + game.config().allianceDuration(); expect(expirationAfter).toBeGreaterThanOrEqual(expirationBefore); + expect(allianceSpy).toHaveBeenCalledTimes(1); }); test("Fails gracefully if no alliance exists", () => {