Found while resetting the live test world: joinWorld's comment promised POST /worlds/:id/join but no route existed, so after reset-world (accounts kept) nobody could found a POP again. Added POST /me/join (default: first running world; 409 if already joined), a join card on the POP screen, en/nb strings, API.md + openapi. Client no longer polls /movements while it has no operator (that 404ed). Tested: npm test 209/209 (new test/me-join.test.js incl. response contract), openapi check, npm run e2e (new check: account without a POP sees the join card and founds one). NOT tested: joining a second/other world (only the default-world path in the browser), nb text of the card visually. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
25 lines
1.4 KiB
JavaScript
25 lines
1.4 KiB
JavaScript
'use strict';
|
|
/* An account with no operator (world reset) joins again over HTTP; a second join conflicts; unknown world is 404. */
|
|
const test = require('node:test');
|
|
const assert = require('node:assert');
|
|
const { createTestServer } = require('./helpers');
|
|
|
|
test('POST /me/join: founds a POP for an account without an operator', async () => {
|
|
const t = await createTestServer({ contract: true });
|
|
try {
|
|
const a = await t.signup('alice');
|
|
assert.equal((await t.api('/me/join', { method: 'POST', body: {} }, a.token)).body.error.code, 'conflict', 'already joined');
|
|
assert.equal((await t.api('/me/join', { method: 'POST', body: {} })).status, 401);
|
|
t.srv.db.run('DELETE FROM buildings WHERE town_id = ?', a.townId);
|
|
t.srv.db.run('DELETE FROM towns WHERE owner_id = ?', a.operatorId);
|
|
t.srv.db.run('DELETE FROM operators WHERE id = ?', a.operatorId);
|
|
assert.deepEqual((await t.api('/me', {}, a.token)).body.operators, []);
|
|
assert.equal((await t.api('/me/join', { method: 'POST', body: { worldId: 99 } }, a.token)).status, 404);
|
|
const r = await t.api('/me/join', { method: 'POST', body: {} }, a.token);
|
|
assert.equal(r.status, 201);
|
|
assert.equal(r.body.operators.length, 1);
|
|
assert.equal(r.body.operators[0].towns[0].isCapital, true);
|
|
const town = await t.api('/towns/' + r.body.operators[0].towns[0].id, {}, a.token);
|
|
assert.equal(town.status, 200);
|
|
} finally { await t.close(); }
|
|
});
|