Re-roll testing
This commit is contained in:
parent
ecfcb0476b
commit
58d2a19ada
@ -4865,3 +4865,6 @@ router.post("/:id?", async (req, res /*, next*/) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
||||||
|
// Export helpers for unit testing
|
||||||
|
export { processTies, processGameOrder };
|
||||||
|
@ -93,10 +93,12 @@ process.on("SIGINT", () => {
|
|||||||
server.close(() => process.exit(1));
|
server.close(() => process.exit(1));
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Opening server.");
|
if (process.env['NODE_ENV'] !== 'test') {
|
||||||
server.listen(serverConfig.port, () => {
|
console.log("Opening server.");
|
||||||
console.log(`http/ws server listening on ${serverConfig.port}`);
|
server.listen(serverConfig.port, () => {
|
||||||
});
|
console.log(`http/ws server listening on ${serverConfig.port}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
server.on("error", function (error: any) {
|
server.on("error", function (error: any) {
|
||||||
if (error.syscall !== "listen") {
|
if (error.syscall !== "listen") {
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
const { app } = require('../src/app');
|
const { app } = require('../src/app');
|
||||||
|
const gamesModule = require('../../server/routes/games');
|
||||||
|
|
||||||
|
// Import helpers for direct testing (exported for tests)
|
||||||
|
const { processTies } = gamesModule;
|
||||||
|
|
||||||
describe('Server Routes', () => {
|
describe('Server Routes', () => {
|
||||||
it('should respond to GET /', async () => {
|
it('should respond to GET /', async () => {
|
||||||
@ -8,4 +12,43 @@ describe('Server Routes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Add more tests as needed
|
// Add more tests as needed
|
||||||
|
it('resolves ties and preserves earlier rolls precedence', () => {
|
||||||
|
/* Build fake players to simulate the scenario:
|
||||||
|
* - James rolled 2
|
||||||
|
* - Guest rolled 2
|
||||||
|
* - Incognito rolled 5
|
||||||
|
* Expectation: Incognito 1st, Guest 2nd, James 3rd
|
||||||
|
* To simulate tie re-roll, processTies should mark ties and pad singleton orders.
|
||||||
|
*/
|
||||||
|
const players = [
|
||||||
|
{ name: 'James', color: 'R', order: 2, orderRoll: 2, position: '', orderStatus: '', tied: false },
|
||||||
|
{ name: 'Guest', color: 'B', order: 2, orderRoll: 2, position: '', orderStatus: '', tied: false },
|
||||||
|
{ name: 'Incognito', color: 'O', order: 5, orderRoll: 5, position: '', orderStatus: '', tied: false },
|
||||||
|
];
|
||||||
|
|
||||||
|
// First sort like the server does (descending by order)
|
||||||
|
players.sort((A: any, B: any) => B.order - A.order);
|
||||||
|
|
||||||
|
// Invoke processTies to simulate the server behavior
|
||||||
|
const hadTies = processTies(players as any);
|
||||||
|
|
||||||
|
// There should be ties among the two players who rolled 2
|
||||||
|
expect(hadTies).toBe(true);
|
||||||
|
|
||||||
|
// Incognito should be placed 1st and not tied
|
||||||
|
const inc = players.find((p: any) => p.name === 'Incognito');
|
||||||
|
expect(inc).toBeDefined();
|
||||||
|
expect(inc!.position).toBe('1st');
|
||||||
|
expect(inc!.tied).toBe(false);
|
||||||
|
|
||||||
|
// The two players who tied should have been marked tied and have orderRoll reset
|
||||||
|
const james = players.find((p: any) => p.name === 'James');
|
||||||
|
const guest = players.find((p: any) => p.name === 'Guest');
|
||||||
|
expect(james).toBeDefined();
|
||||||
|
expect(guest).toBeDefined();
|
||||||
|
expect(james!.tied).toBe(true);
|
||||||
|
expect(guest!.tied).toBe(true);
|
||||||
|
expect(james!.orderRoll).toBe(0);
|
||||||
|
expect(guest!.orderRoll).toBe(0);
|
||||||
|
});
|
||||||
});
|
});
|
Loading…
x
Reference in New Issue
Block a user