diff --git a/src/Message/MessageHelpers.tsx b/src/Message/MessageHelpers.tsx index d58fa2112..2eff254b5 100644 --- a/src/Message/MessageHelpers.tsx +++ b/src/Message/MessageHelpers.tsx @@ -58,7 +58,10 @@ function checkForMessagesToSend(): void { throw new Error("The world daemon is not a server???? Please un-break reality"); } //If the daemon can be hacked, send the player icarus.msg - if (Player.skills.hacking >= worldDaemon.requiredHackingSkill) { + if ( + Player.skills.hacking >= worldDaemon.requiredHackingSkill && + (Player.sourceFiles.size === 0 || !recvd(MessageFilename.RedPill)) + ) { sendMessage(MessageFilename.RedPill, Player.sourceFiles.size === 0); } //If the daemon cannot be hacked, send the player truthgazer.msg a single time. diff --git a/test/jest/Messages/MessageHelper.test.ts b/test/jest/Messages/MessageHelper.test.ts new file mode 100644 index 000000000..9c266f5f3 --- /dev/null +++ b/test/jest/Messages/MessageHelper.test.ts @@ -0,0 +1,62 @@ +import { checkForMessagesToSend } from "../../../src/Message/MessageHelpers"; +import * as dialogBoxCreate from "../../../src/ui/React/DialogBox"; +import { Player } from "@player"; +import "../../../src/ui/GameRoot"; +import { AugmentationName } from "@enums"; +import { AddToAllServers } from "../../../src/Server/AllServers"; +import { Server } from "../../../src/Server/Server"; +import { installAugmentations } from "../../../src/Augmentation/AugmentationHelpers"; +import { initSourceFiles } from "../../../src/SourceFile/SourceFiles"; + +jest.mock("../../../src/ui/GameRoot", () => ({ + Router: { + page: () => ({}), + toPage: () => ({}), + }, +})); + +jest.mock("../../../src/ui/React/DialogBox", () => ({ + dialogBoxCreate: jest.fn(), +})); + +AddToAllServers(new Server({ hostname: "home" })); + +describe("MessageHelpers tests", () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + it("Should repeatedly send the Icarus message on the player's first bitnode", () => { + Player.queueAugmentation(AugmentationName.TheRedPill); + installAugmentations(); + Player.gainHackingExp(2 ** 200); + + const showMessageSpy = jest.spyOn(dialogBoxCreate, "dialogBoxCreate"); + + checkForMessagesToSend(); + checkForMessagesToSend(); + + // Called once for installing augmentations, and once for each + // checkForMessagesToSend() sending an Icarus message + expect(showMessageSpy).toHaveBeenCalledTimes(3); + }); + + it("Should not repeatedly send the Icarus message after the player's first bitnode completion", () => { + initSourceFiles(); + Player.sourceFiles.set(1, 1); + Player.queueAugmentation(AugmentationName.TheRedPill); + installAugmentations(); + Player.gainHackingExp(2 ** 200); + + const showMessageSpy = jest.spyOn(dialogBoxCreate, "dialogBoxCreate"); + + checkForMessagesToSend(); + checkForMessagesToSend(); + checkForMessagesToSend(); + checkForMessagesToSend(); + + // Called once for installing augmentations, and only once for any number of + // checkForMessagesToSend() ( sending an Icarus message only the first time) + expect(showMessageSpy).toHaveBeenCalledTimes(2); + }); +});