Reinstalled Node packages, Implemented test suite
parent
4d0f4a7589
commit
f84404a8fc
File diff suppressed because it is too large
Load Diff
|
@ -16,14 +16,19 @@
|
|||
"sqlite3": "^5.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.12",
|
||||
"@types/node": "^20.11.19",
|
||||
"copyfiles": "^2.4.1",
|
||||
"jest": "^29.7.0",
|
||||
"jest-watch-typeahead": "^2.2.2",
|
||||
"ts-jest": "^29.1.2",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist/*.js dist/db/migrations dist/messages",
|
||||
"build": "npm run clean && tsc && copyfiles -u 3 \"src/db/migrations/*.sql\" dist/db/migrations && copyfiles -u 3 \"src/db/seed/*.sql\" dist/db/seed && copyfiles -u 2 \"src/messages/*.txt\" dist/messages",
|
||||
"start": "npm run build && node dist/index.js",
|
||||
"test": "tsc -p tsconfig.tests.json"
|
||||
"test": "jest --watchAll",
|
||||
"test:coverage": "jest --coverage"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
import { CommentFetcher } from "../../src/rdrama/services/CommentFetcher";
|
||||
import SessionManager from "../../src/rdrama/session/SessionManager"
|
||||
|
||||
main();
|
||||
|
||||
async function main(): Promise<void> {
|
||||
console.log('1')
|
||||
const axiosSession = SessionManager.getInstance()
|
||||
console.log('2')
|
||||
let maxPages = 5
|
||||
for (let page = 1; page <= maxPages; page++) {
|
||||
const newComments = await CommentFetcher.fetchComments(page)
|
||||
}
|
||||
console.log('3')
|
||||
await axiosSession.shutdown()
|
||||
console.log('4')
|
||||
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
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);
|
||||
});
|
||||
});
|
|
@ -6,15 +6,22 @@
|
|||
"es2022"
|
||||
],
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"rootDir": "./",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"types": [
|
||||
"node"
|
||||
"node",
|
||||
"jest"
|
||||
],
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"typeAcquisition": {
|
||||
"include": [
|
||||
"jest"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
"src/**/*",
|
||||
"tests/**/*"
|
||||
]
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist-tests",
|
||||
"rootDir": "./"
|
||||
},
|
||||
"include": [
|
||||
"tests/**/*"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue