diff --git a/project/tests/generators/BotGenerator.test.ts b/project/tests/generators/BotGenerator.test.ts index c40defbe..442fc243 100644 --- a/project/tests/generators/BotGenerator.test.ts +++ b/project/tests/generators/BotGenerator.test.ts @@ -20,10 +20,46 @@ describe("BotGenerator", () => vi.restoreAllMocks(); }); - describe("prepareAndGenerateBots", () => + // describe("prepareAndGenerateBots", () => + // { + // it("should return a single generated assault bot", () => + // { + // const mockPlayerProfile = { + // Info: { + // Nickname: "Player Nickname", + // Level: 1 + // } + // }; + + // vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + // vi.spyOn(botGenerator.botEquipmentFilterService.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + // vi.spyOn(botGenerator.botInventoryGenerator.botWeaponGenerator.botEquipmentModGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + + // const sessionId = "12345"; + // const generationDetails: BotGenerationDetails = { + // isPmc: false, + // role: "assault", + // side: "Savage", + // playerLevel: 1, + // botRelativeLevelDeltaMax: 10, + // botCountToGenerate: 1, + // botDifficulty: "easy", + // isPlayerScav: false + // }; + + // const result = botGenerator.prepareAndGenerateBots(sessionId, generationDetails); + + // expect(result.length).toBe(1); + // expect(result[0].Info.Side).toBe("Savage"); + // }); + // }); + + describe("generateBotNickname", () => { - it("should return a single generated assault bot", () => + it("should return single name `test` for non pscav assault bot name ", () => { + botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 0; + const mockPlayerProfile = { Info: { Nickname: "Player Nickname", @@ -32,25 +68,122 @@ describe("BotGenerator", () => }; vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); - vi.spyOn(botGenerator.botEquipmentFilterService.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); - vi.spyOn(botGenerator.botInventoryGenerator.botWeaponGenerator.botEquipmentModGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); - const sessionId = "12345"; - const generationDetails: BotGenerationDetails = { - isPmc: false, - role: "assault", - side: "Savage", - playerLevel: 1, - botRelativeLevelDeltaMax: 10, - botCountToGenerate: 1, - botDifficulty: "easy", - isPlayerScav: false + const botJsonTemplate = { + firstName: ["test"], + lastName: [] }; - const result = botGenerator.prepareAndGenerateBots(sessionId, generationDetails); + const sessionId = "sessionId"; + const isPlayerScav = false; + const botRole = "assault"; - expect(result.length).toBe(1); - expect(result[0].Info.Side).toBe("Savage"); + const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId); + expect(result).toBe("test"); + }); + + it("should return `test assault` for non pscav assault bot with `showTypeInNickname` enabled ", () => + { + botGenerator.botConfig.showTypeInNickname = true; + + const mockPlayerProfile = { + Info: { + Nickname: "Player Nickname", + Level: 1 + } + }; + vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + + const botJsonTemplate = { + firstName: ["test"], + lastName: [] + }; + + const sessionId = "sessionId"; + const isPlayerScav = false; + const botRole = "assault"; + + const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId); + expect(result).toBe("test assault"); + }); + + it("should return name `test Player` for bot with same name as player and `addPrefixToSameNamePMCAsPlayerChance` 100%", () => + { + botGenerator.botConfig.showTypeInNickname = false; + botGenerator.pmcConfig.addPrefixToSameNamePMCAsPlayerChance = 100; + + const mockPlayerProfile = { + Info: { + Nickname: "Player", + Level: 1 + } + }; + vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + vi.spyOn(botGenerator.localisationService, "getRandomTextThatMatchesPartialKey").mockReturnValue("test"); + + const botJsonTemplate = { + firstName: ["Player"], + lastName: [] + }; + + const sessionId = "sessionId"; + const isPlayerScav = false; + const botRole = "assault"; + + const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId); + expect(result).toBe("test Player"); + }); + + it("should return name `test` for player scav bot", () => + { + botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 100; + + const mockPlayerProfile = { + Info: { + Nickname: "Player", + Level: 1 + } + }; + vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + + const botJsonTemplate = { + firstName: ["test"], + lastName: [] + }; + + const sessionId = "sessionId"; + const isPlayerScav = true; + const botRole = "assault"; + + const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId); + expect(result).toBe("test"); + }); + + it("should return name `test (usec)` for player scav bot", () => + { + botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 100; + botGenerator.databaseServer.getTables().bots.types["usec"].firstName = ["usec"]; + botGenerator.databaseServer.getTables().bots.types["bear"].firstName = []; + + const mockPlayerProfile = { + Info: { + Nickname: "Player", + Level: 1 + } + }; + vi.spyOn(botGenerator.profileHelper, "getPmcProfile").mockReturnValue(mockPlayerProfile); + + const botJsonTemplate = { + firstName: ["test"], + lastName: [] + }; + + const sessionId = "sessionId"; + const isPlayerScav = false; + const botRole = "assault"; + + const result = botGenerator.generateBotNickname(botJsonTemplate, isPlayerScav, botRole, sessionId); + expect(result).toBe("test (usec)"); }); }); });