mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-11-20 22:13:59 +01:00
refactor: extract verify view + admin routes from index.js god-file
Begin splitting the 2029-line index.js. No behaviour change. - src/views/verifyPage.js: the inline provably-fair verification HTML page, now with the interpolated values HTML-escaped (defense in depth). - src/routes/admin.js: all 15 /api/admin/* endpoints + adminAuth, as a dependency-injected factory createAdminRoutes(ctx). Handler bodies are byte-for-byte identical; alertService is late-bound via the shared ctx object (set when the payment system starts). index.js: 2029 -> 1047 lines. Adds adminRoutes.test.js asserting all 15 routes register. Full suite: 21 suites / 154 tests.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* Admin routes extraction smoke test (Phase 4.1).
|
||||
*
|
||||
* Verifies the extracted admin route factory loads and registers all expected routes
|
||||
* with a stub ctx — catches load-time/reference errors from the index.js -> routes/admin.js
|
||||
* split without needing a live server.
|
||||
*/
|
||||
|
||||
const createAdminRoutes = require('../src/routes/admin');
|
||||
|
||||
function stubCtx() {
|
||||
return {
|
||||
db: { query: jest.fn(), getClient: jest.fn() },
|
||||
gameModeManager: {},
|
||||
walletRPCService: {},
|
||||
socketHandlers: {},
|
||||
io: {},
|
||||
alertService: null
|
||||
};
|
||||
}
|
||||
|
||||
describe('admin routes factory', () => {
|
||||
test('builds a router and registers the expected admin endpoints', () => {
|
||||
const router = createAdminRoutes(stubCtx());
|
||||
expect(typeof router).toBe('function'); // express router is a middleware function
|
||||
const paths = router.stack.filter(l => l.route).map(l => l.route.path);
|
||||
|
||||
const expected = [
|
||||
'/api/admin/refund/payment',
|
||||
'/api/admin/credits/adjust',
|
||||
'/api/admin/alerts/test-email',
|
||||
'/api/admin/queue',
|
||||
'/api/admin/queue/remove',
|
||||
'/api/admin/chat',
|
||||
'/api/admin/chat/:id',
|
||||
'/api/admin/users/:id/chat-ban',
|
||||
'/api/admin/users/search',
|
||||
'/api/admin/stats/overview',
|
||||
'/api/admin/stats/payouts',
|
||||
'/api/admin/stats/games',
|
||||
'/api/admin/users',
|
||||
'/api/admin/users/:id',
|
||||
'/api/admin/payouts/:id/retry'
|
||||
];
|
||||
for (const p of expected) {
|
||||
expect(paths).toContain(p);
|
||||
}
|
||||
expect(paths.length).toBe(expected.length);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user