Added notifcation when a player wants to renew (#2391)

## Description:

Describe the PR.

Added a new chat message from the server once player wants to renew the
alliance, to the other player.

## Please complete the following:

- [x] I have added screenshots for all UI updates

<img width="572" height="256" alt="image"
src="https://github.com/user-attachments/assets/7feec21f-fff5-4544-8992-caf99c45913d"
/>

- [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

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

DISCORD_USERNAME

notifxy (1379678982676676639)
This commit is contained in:
Rj Manhas
2025-11-08 13:48:05 -08:00
committed by GitHub
parent ffe1ad0e81
commit 6a78494404
4 changed files with 94 additions and 13 deletions
+47 -1
View File
@@ -1,7 +1,7 @@
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 { Game, MessageType, Player, PlayerType } from "../src/core/game/Game";
import { playerInfo, setup } from "./util/Setup";
let game: Game;
@@ -119,4 +119,50 @@ describe("AllianceExtensionExecution", () => {
expect(expirationAfter).toBeGreaterThan(expirationBefore);
expect(allianceSpy).toHaveBeenCalledTimes(1);
});
test("Sends message to other player when one player requests renewal", () => {
jest.spyOn(player1, "canSendAllianceRequest").mockReturnValue(true);
jest.spyOn(player2, "isAlive").mockReturnValue(true);
jest.spyOn(player1, "isAlive").mockReturnValue(true);
// Create alliance between player1 and player2
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();
// Spy on displayMessage to verify it's called
const displayMessageSpy = jest.spyOn(game, "displayMessage");
// Player1 requests renewal
game.addExecution(new AllianceExtensionExecution(player1, player2.id()));
game.executeNextTick();
// Verify message was sent to player2
expect(displayMessageSpy).toHaveBeenCalledWith(
"events_display.wants_to_renew_alliance",
MessageType.RENEW_ALLIANCE,
player2.id(),
undefined,
{ name: player1.displayName() },
);
expect(displayMessageSpy).toHaveBeenCalledTimes(1);
// Request again - should not send duplicate message
game.addExecution(new AllianceExtensionExecution(player1, player2.id()));
game.executeNextTick();
// Should still be called only once (no duplicate)
expect(displayMessageSpy).toHaveBeenCalledTimes(1);
displayMessageSpy.mockRestore();
});
});