2026-11-19 01:40:31 +01:00
|
|
|
'use strict';
|
|
|
|
|
const { test, before, after } = require('node:test');
|
|
|
|
|
const assert = require('node:assert/strict');
|
|
|
|
|
const { startServer } = require('./helpers');
|
|
|
|
|
|
|
|
|
|
let S;
|
|
|
|
|
before(async () => { S = await startServer(); });
|
|
|
|
|
after(() => S.close());
|
|
|
|
|
|
|
|
|
|
test('GET /healthz reports ok + version', async () => {
|
|
|
|
|
const r = await S.json('GET', '/healthz');
|
|
|
|
|
assert.equal(r.status, 200);
|
|
|
|
|
assert.equal(r.body.ok, true);
|
|
|
|
|
assert.equal(r.body.version, require('../package.json').version);
|
|
|
|
|
assert.equal(typeof r.body.uptime, 'number');
|
|
|
|
|
});
|
|
|
|
|
|
feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)
Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a
WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset.
BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
2026-11-19 01:52:30 +01:00
|
|
|
test('register by name -> login by name (any case) -> refresh rotates the token', async () => {
|
|
|
|
|
const reg = await S.json('POST', '/api/auth/register', { name: 'Alice', pass: 'secret123' });
|
2026-11-19 01:40:31 +01:00
|
|
|
assert.equal(reg.status, 200);
|
|
|
|
|
assert.ok(reg.body.idToken && reg.body.refreshToken && reg.body.uid);
|
|
|
|
|
|
feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)
Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a
WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset.
BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
2026-11-19 01:52:30 +01:00
|
|
|
const login = await S.json('POST', '/api/auth/login', { login: ' ALICE ', pass: 'secret123' });
|
2026-11-19 01:40:31 +01:00
|
|
|
assert.equal(login.status, 200);
|
|
|
|
|
assert.equal(login.body.uid, reg.body.uid);
|
feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)
Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a
WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset.
BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
2026-11-19 01:52:30 +01:00
|
|
|
assert.equal(login.body.name, 'Alice');
|
2026-11-19 01:40:31 +01:00
|
|
|
|
|
|
|
|
const me = await S.json('GET', '/api/me', undefined, login.body.idToken);
|
|
|
|
|
assert.equal(me.body.uid, reg.body.uid);
|
feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)
Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a
WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset.
BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
2026-11-19 01:52:30 +01:00
|
|
|
assert.equal(me.body.admin, false);
|
2026-11-19 01:40:31 +01:00
|
|
|
|
|
|
|
|
const r1 = await S.json('POST', '/api/auth/refresh', { refreshToken: login.body.refreshToken });
|
|
|
|
|
assert.equal(r1.status, 200);
|
|
|
|
|
const r2 = await S.json('POST', '/api/auth/refresh', { refreshToken: login.body.refreshToken });
|
|
|
|
|
assert.equal(r2.status, 401, 'an already used refresh token is rejected');
|
|
|
|
|
});
|
|
|
|
|
|
feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)
Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a
WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset.
BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
2026-11-19 01:52:30 +01:00
|
|
|
test('register: optional e-mail works as login too; duplicates and weak passwords are refused', async () => {
|
|
|
|
|
const r = await S.json('POST', '/api/auth/register', { name: 'Bob', pass: 'secret123', email: 'Bob@Test.dev' });
|
|
|
|
|
assert.equal(r.status, 200);
|
|
|
|
|
assert.equal((await S.json('POST', '/api/auth/login', { login: 'bob@test.dev', pass: 'secret123' })).status, 200);
|
|
|
|
|
assert.equal((await S.json('POST', '/api/auth/register', { name: 'bob', pass: 'secret123' })).body.error, 'NAME_EXISTS');
|
|
|
|
|
assert.equal((await S.json('POST', '/api/auth/register', { name: 'Carl', pass: 'short' })).body.error, 'WEAK_PASSWORD');
|
|
|
|
|
assert.equal((await S.json('POST', '/api/auth/register', { name: 'x', pass: 'secret123' })).body.error, 'BAD_NAME');
|
|
|
|
|
});
|
|
|
|
|
|
2026-11-19 09:59:19 +01:00
|
|
|
test('DELETE /api/me removes the account, its save and its tokens', async () => {
|
|
|
|
|
const r = await S.json('POST', '/api/auth/register', { name: 'Leaver', pass: 'secret123' });
|
|
|
|
|
await S.json('GET', '/api/online', undefined, r.body.idToken);
|
|
|
|
|
assert.equal((await S.json('DELETE', '/api/me', undefined, r.body.idToken)).body.ok, true);
|
|
|
|
|
assert.equal((await S.json('POST', '/api/auth/login', { login: 'leaver', pass: 'secret123' })).status, 400);
|
|
|
|
|
assert.equal((await S.json('POST', '/api/auth/refresh', { refreshToken: r.body.refreshToken })).status, 401);
|
|
|
|
|
});
|
|
|
|
|
|
2026-11-19 01:40:31 +01:00
|
|
|
test('wrong password is rejected', async () => {
|
feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)
Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a
WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset.
BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
2026-11-19 01:52:30 +01:00
|
|
|
const r = await S.json('POST', '/api/auth/login', { login: 'alice', pass: 'nope-nope' });
|
2026-11-19 01:40:31 +01:00
|
|
|
assert.equal(r.status, 400);
|
feat(server)!: websocket lobby, server-run matches, server economy, new schema (P1-2, P1-4, P2-1, P2-1b, P2-5)
Replaces the Firebase-style /db facade (rtdb, rules, nodes tree) with explicit REST endpoints and a
WebSocket hub. Login by name or optional e-mail, seed accounts via npm run db:reset.
BREAKING CHANGE: old clients (lobby/netfight over /db) no longer work against this server; database is new.
2026-11-19 01:52:30 +01:00
|
|
|
assert.equal(r.body.error, 'INVALID_LOGIN');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('guest accounts get a token and an online save', async () => {
|
|
|
|
|
const g = await S.json('POST', '/api/auth/guest', { name: 'Gast' });
|
|
|
|
|
assert.equal(g.status, 200);
|
|
|
|
|
assert.equal(g.body.guest, true);
|
|
|
|
|
const s = await S.json('GET', '/api/online', undefined, g.body.idToken);
|
|
|
|
|
assert.equal(s.body.money, 800);
|
2026-11-19 01:40:31 +01:00
|
|
|
});
|