Fix standalone TTR preview route without saved match ID
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 1m0s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 1m0s
This commit is contained in:
39
backend/tests/ttrPreviewController.node.test.mjs
Normal file
39
backend/tests/ttrPreviewController.node.test.mjs
Normal file
@@ -0,0 +1,39 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const source = readFileSync(new URL('../controllers/matchController.js', import.meta.url), 'utf8')
|
||||
.replace(/^import .*;\n/gm, '')
|
||||
.replace(/^export const /gm, 'const ');
|
||||
|
||||
test('the literal standalone route resolves players without a match lookup or cache mutation', async () => {
|
||||
const calls = [];
|
||||
const context = vm.createContext({
|
||||
console,
|
||||
Op: { ne: Symbol('ne') },
|
||||
Match: { findByPk() { throw new Error('Standalone must not look up a saved match'); } },
|
||||
sequelize: { query() { throw new Error('Standalone must not access the match cache'); } },
|
||||
Member: { findAll: async () => [] },
|
||||
Club: { findAll: async () => [] },
|
||||
checkAccess: async (_token, clubId) => { assert.equal(clubId, 7); },
|
||||
myTischtennisService: {}, myTischtennisClient: {},
|
||||
resolveTtrPreview: async input => {
|
||||
calls.push(input);
|
||||
return { players: [{ side: 'home', name: 'Anna Wolf', ttr: 680 }], diagnostics: [] };
|
||||
},
|
||||
});
|
||||
vm.runInContext(source + '\nglobalThis.standaloneHandler = getStandaloneTtrPreviewPlayers;', context);
|
||||
const req = { params: {}, headers: { authcode: 'test-token' }, body: {
|
||||
clubId: 7, homePlayers: [{ firstname: 'Anna', lastname: 'Wolf' }],
|
||||
}, user: { id: 3 } };
|
||||
let payload;
|
||||
const res = {
|
||||
status(code) { assert.fail(`Unexpected HTTP ${code}`); },
|
||||
json(body) { payload = body; },
|
||||
};
|
||||
await context.standaloneHandler(req, res);
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0].homePlayers[0].firstname, 'Anna');
|
||||
assert.equal(payload.players[0].ttr, 680);
|
||||
});
|
||||
Reference in New Issue
Block a user