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.
This commit is contained in:
@@ -15,17 +15,19 @@ test('GET /healthz reports ok + version', async () => {
|
||||
assert.equal(typeof r.body.uptime, 'number');
|
||||
});
|
||||
|
||||
test('register -> login -> refresh rotates the refresh token', async () => {
|
||||
const reg = await S.json('POST', '/api/auth/register', { email: 'a@test.dev', pass: 'secret123', name: 'Alice' });
|
||||
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' });
|
||||
assert.equal(reg.status, 200);
|
||||
assert.ok(reg.body.idToken && reg.body.refreshToken && reg.body.uid);
|
||||
|
||||
const login = await S.json('POST', '/api/auth/login', { email: 'A@test.dev ', pass: 'secret123' });
|
||||
const login = await S.json('POST', '/api/auth/login', { login: ' ALICE ', pass: 'secret123' });
|
||||
assert.equal(login.status, 200);
|
||||
assert.equal(login.body.uid, reg.body.uid);
|
||||
assert.equal(login.body.name, 'Alice');
|
||||
|
||||
const me = await S.json('GET', '/api/me', undefined, login.body.idToken);
|
||||
assert.equal(me.body.uid, reg.body.uid);
|
||||
assert.equal(me.body.admin, false);
|
||||
|
||||
const r1 = await S.json('POST', '/api/auth/refresh', { refreshToken: login.body.refreshToken });
|
||||
assert.equal(r1.status, 200);
|
||||
@@ -33,7 +35,25 @@ test('register -> login -> refresh rotates the refresh token', async () => {
|
||||
assert.equal(r2.status, 401, 'an already used refresh token is rejected');
|
||||
});
|
||||
|
||||
test('wrong password is rejected', async () => {
|
||||
const r = await S.json('POST', '/api/auth/login', { email: 'a@test.dev', pass: 'nope-nope' });
|
||||
assert.equal(r.status, 400);
|
||||
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');
|
||||
});
|
||||
|
||||
test('wrong password is rejected', async () => {
|
||||
const r = await S.json('POST', '/api/auth/login', { login: 'alice', pass: 'nope-nope' });
|
||||
assert.equal(r.status, 400);
|
||||
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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user