Skip to content

Commit ffbb112

Browse files
Add test case
1 parent 92025e5 commit ffbb112

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

test/storage/utils/object.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,29 @@ describe('Storage Object Utils tests', () => {
6464
assert.strictEqual(called.length, 1);
6565
assert.strictEqual(called[0], 'https://localhost/api/v1/syncadmin?doc=https://admin.da.live/source/a/b/c.html');
6666
});
67+
68+
it('Should not throw when collab returns a null-body response (e.g. 204)', async () => {
69+
// Reproduces the case where da-collab's deleteAdmin handler returns
70+
// `new Response(null, { status: 204 })` — common when a doc is open in
71+
// another window and gets invalidated. In that case `resp.body` is null,
72+
// and calling `.cancel()` on it would throw if not optional-chained.
73+
const called = [];
74+
const env = {
75+
dacollab: {
76+
fetch: async (url) => {
77+
called.push(url);
78+
// Mirror the shape of a Workers Response with a 204 status:
79+
// body is null, so resp.body.cancel() would TypeError without `?.`.
80+
return { status: 204, body: null };
81+
},
82+
},
83+
};
84+
85+
await assert.doesNotReject(
86+
() => notifyCollab('deleteadmin', 'https://admin.da.live/source/a/b/c.html', env),
87+
'notifyCollab must tolerate a null response body',
88+
);
89+
assert.strictEqual(called.length, 1);
90+
assert.strictEqual(called[0], 'https://localhost/api/v1/deleteadmin?doc=https://admin.da.live/source/a/b/c.html');
91+
});
6792
});

0 commit comments

Comments
 (0)