153 lines
6.7 KiB
TypeScript
153 lines
6.7 KiB
TypeScript
jest.mock('../../src/db/services/Database');
|
|
|
|
|
|
import { MountainPhase } from '../../src/phases/mountain';
|
|
import GameState, { PHASE_ENUM } from '../../src/game/gameState';
|
|
import { Comment } from '../../src/rdrama/models/Comment';
|
|
import { DatabaseService } from '../../src/db/services/Database';
|
|
|
|
|
|
|
|
describe('MountainPhase', () => {
|
|
let gameState: GameState;
|
|
let mockComment: Comment = {
|
|
author_id: 123,
|
|
author_name: "TestUser",
|
|
body: "!!oregon 3",
|
|
body_html: "<p>!!oregon 3</p>",
|
|
created_utc: 1712512562,
|
|
deleted_utc: 0,
|
|
distinguished: false,
|
|
downvotes: 0,
|
|
edited_utc: 0,
|
|
id: 6227144,
|
|
is_banned: false,
|
|
is_bot: false,
|
|
is_nsfw: false,
|
|
level: 1,
|
|
permalink: "/comment/6227144#context",
|
|
pinned: '',
|
|
post_id: 0,
|
|
replies: [],
|
|
reports: {},
|
|
score: 1,
|
|
upvotes: 1
|
|
};
|
|
|
|
beforeEach(async () => {
|
|
(DatabaseService.loadGameState as jest.Mock).mockResolvedValue(null); // Assume no pre-existing state
|
|
(DatabaseService.saveGameState as jest.Mock).mockResolvedValue(undefined);
|
|
|
|
// Use the static method to load GameState
|
|
gameState = await GameState.load(mockComment);
|
|
console.log(JSON.stringify(gameState, null, 4));
|
|
gameState.phase = PHASE_ENUM.MOUNTAIN;
|
|
gameState.totalMileageWholeTrip = 0;
|
|
gameState.clearSouthPassFlag = false;
|
|
gameState.clearBlueMountainsFlag = false;
|
|
gameState.blizzardFlag = false;
|
|
gameState.amountSpentOnFood = 100;
|
|
gameState.amountSpentOnMiscellaneousSupplies = 100;
|
|
gameState.amountSpentOnAmmunition = 500;
|
|
gameState.amountSpentOnClothing = 20;
|
|
});
|
|
|
|
it('should not encounter mountains when totalMileageWholeTrip is less than 950', async () => {
|
|
gameState.totalMileageWholeTrip = 900;
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.lastPrompt).toBe('The mountains are distant... for now.\n');
|
|
});
|
|
|
|
it('should encounter mountains when totalMileageWholeTrip is greater than or equal to 950', async () => {
|
|
gameState.totalMileageWholeTrip = 1000;
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.lastPrompt).toContain('Mountain Passage');
|
|
});
|
|
|
|
it('should handle getting lost scenario', async () => {
|
|
gameState.totalMileageWholeTrip = 1000;
|
|
jest.spyOn(global.Math, 'random').mockReturnValueOnce(9).mockReturnValueOnce(0.2);
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.totalMileageWholeTrip).toBe(940);
|
|
expect(gameState.lastPrompt).toContain('You got lost');
|
|
});
|
|
|
|
it('should handle wagon damage scenario', async () => {
|
|
gameState.totalMileageWholeTrip = 1000;
|
|
jest.spyOn(global.Math, 'random').mockReturnValueOnce(9).mockReturnValueOnce(0.12);
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.amountSpentOnMiscellaneousSupplies).toBe(95);
|
|
expect(gameState.amountSpentOnAmmunition).toBe(300);
|
|
expect(gameState.totalMileageWholeTrip).toBeGreaterThanOrEqual(970);
|
|
expect(gameState.totalMileageWholeTrip).toBeLessThanOrEqual(1000);
|
|
expect(gameState.lastPrompt).toContain('Wagon damaged');
|
|
});
|
|
|
|
it('should handle slow going scenario', async () => {
|
|
gameState.totalMileageWholeTrip = 1000;
|
|
jest.spyOn(global.Math, 'random').mockReturnValueOnce(9).mockReturnValueOnce(0.09);
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.totalMileageWholeTrip).toBeGreaterThanOrEqual(955);
|
|
expect(gameState.totalMileageWholeTrip).toBeLessThanOrEqual(957);
|
|
expect(gameState.lastPrompt).toContain('The going gets slow');
|
|
});
|
|
|
|
it('should clear South Pass without snow', async () => {
|
|
gameState.totalMileageWholeTrip = 1000;
|
|
jest.spyOn(global.Math, 'random').mockReturnValueOnce(0).mockReturnValueOnce(0.7);
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.clearSouthPassFlag).toBe(true);
|
|
expect(gameState.lastPrompt).toContain('You made it safely through South Pass');
|
|
});
|
|
|
|
it('should clear South Pass with snow', async () => {
|
|
gameState.totalMileageWholeTrip = 1000;
|
|
jest.spyOn(global.Math, 'random').mockReturnValueOnce(0).mockReturnValueOnce(0.9);
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.clearSouthPassFlag).toBe(true);
|
|
expect(gameState.lastPrompt).not.toContain('You made it safely through South Pass');
|
|
});
|
|
|
|
it('should encounter blizzard in Blue Mountains', async () => {
|
|
gameState.totalMileageWholeTrip = 1800;
|
|
jest.spyOn(global.Math, 'random').mockReturnValueOnce(0).mockReturnValueOnce(0.6);
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.clearBlueMountainsFlag).toBe(true);
|
|
expect(gameState.blizzardFlag).toBe(true);
|
|
expect(gameState.amountSpentOnFood).toBe(75);
|
|
expect(gameState.amountSpentOnMiscellaneousSupplies).toBe(90);
|
|
expect(gameState.amountSpentOnAmmunition).toBe(200);
|
|
expect(gameState.totalMileageWholeTrip).toBeGreaterThanOrEqual(1760);
|
|
expect(gameState.totalMileageWholeTrip).toBeLessThanOrEqual(1800);
|
|
expect(gameState.lastPrompt).toContain('Blizzard in mountain pass');
|
|
});
|
|
|
|
it('should not encounter blizzard in Blue Mountains', async () => {
|
|
gameState.totalMileageWholeTrip = 1800;
|
|
jest.spyOn(global.Math, 'random').mockReturnValueOnce(0).mockReturnValueOnce(0.8);
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.clearBlueMountainsFlag).toBe(true);
|
|
expect(gameState.blizzardFlag).toBe(false);
|
|
expect(gameState.amountSpentOnFood).toBe(100);
|
|
expect(gameState.amountSpentOnMiscellaneousSupplies).toBe(100);
|
|
expect(gameState.amountSpentOnAmmunition).toBe(500);
|
|
expect(gameState.totalMileageWholeTrip).toBe(1800);
|
|
expect(gameState.lastPrompt).not.toContain('Blizzard in mountain pass');
|
|
});
|
|
|
|
it('should handle not enough clothing during blizzard', async () => {
|
|
gameState.totalMileageWholeTrip = 1800;
|
|
gameState.amountSpentOnClothing = 15;
|
|
jest.spyOn(global.Math, 'random').mockReturnValueOnce(0).mockReturnValueOnce(0.6);
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.lastPrompt).toContain('Not enough clothing for the cold. This could be dire.');
|
|
});
|
|
|
|
it('should update phase and subPhase correctly', async () => {
|
|
gameState.totalMileageWholeTrip = 1000;
|
|
await MountainPhase.handleMountain(gameState);
|
|
expect(gameState.phase).toBe(PHASE_ENUM.START_TURN);
|
|
expect(gameState.subPhase).toBe(0);
|
|
});
|
|
});
|