group code popup
This commit is contained in:
@@ -41,7 +41,8 @@ async function harness(records = new Map()) {
|
||||
const body = JSON.parse(options.body); calls.push({ url, body });
|
||||
if (controls.offline) throw new TypeError('offline');
|
||||
let status = 200, payload;
|
||||
if (body.release) payload = { released: true };
|
||||
if (body.heartbeat && !controls.locked) { status = 204; payload = {}; }
|
||||
else if (body.release) payload = { released: true };
|
||||
else if (controls.locked && !body.replace) { status = 423; payload = { details: { code: 'point-locked', replace: 'old-secret' } }; }
|
||||
else payload = { token: 'our-secret', version: controls.version, mediaVersion: controls.mediaVersion, poi: structuredClone(poi) };
|
||||
return { ok: status === 200, status, json: async () => payload };
|
||||
@@ -131,3 +132,23 @@ test('offline drafts remain editable without claiming a server lock and a late l
|
||||
assert.equal(await opening, null);
|
||||
assert.equal(Object.keys(h.api.headersFor('/routes/7/pois/8')).length, 0);
|
||||
});
|
||||
|
||||
|
||||
test('only actual editor activity refreshes a point lock, while passive time and status checks do not', async () => {
|
||||
const h = await harness();
|
||||
await h.api.begin(7, h.poi);
|
||||
await h.api.keepActive();
|
||||
assert.equal(h.calls.filter(call => call.body.heartbeat).length, 0);
|
||||
h.api.noteActivity(); await h.api.keepActive(); await h.api.keepActive();
|
||||
assert.equal(h.calls.filter(call => call.body.heartbeat).length, 1);
|
||||
assert.equal(h.api.headersFor('/routes/7/pois/8')['If-Poi-Match'], 'v1');
|
||||
h.controls.offline = true;
|
||||
h.api.noteActivity(); await h.api.keepActive();
|
||||
h.controls.offline = false; await h.api.keepActive();
|
||||
assert.equal(h.calls.filter(call => call.body.heartbeat).length, 3);
|
||||
let lost = 0; h.context.document.addEventListener('wegwichtel:point-lock-lost', () => { lost += 1; });
|
||||
h.controls.locked = true; h.api.noteActivity(); await h.api.keepActive();
|
||||
assert.equal(lost, 1);
|
||||
assert.equal(h.calls.at(-1).body.heartbeat, true);
|
||||
assert.equal(h.calls.at(-1).body.replace, undefined);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user