From b33d8de95638b2057dc3f731a00ad8587f5757ea Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 1 Nov 2026 02:04:14 +0100 Subject: [PATCH] estate tests: pin the failed-filing refusal, a non-DM refusal leaving m.direct alone, and awaitMyJoin's event name Co-Authored-By: Claude Sonnet 5.5 --- .../features/estate/joinEstateRoom.test.ts | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/app/features/estate/joinEstateRoom.test.ts b/src/app/features/estate/joinEstateRoom.test.ts index 0bc61a9f..932e7cce 100644 --- a/src/app/features/estate/joinEstateRoom.test.ts +++ b/src/app/features/estate/joinEstateRoom.test.ts @@ -96,6 +96,7 @@ const dmClient = (opts: { errcode?: string; refuse?: boolean; drop?: boolean; + failWrite?: boolean; invites: Record; }) => { let direct: Record | undefined; @@ -117,6 +118,7 @@ const dmClient = (opts: { }), getAccountData: () => (direct ? { getContent: () => direct } : undefined), setAccountData: async (_t: string, content: Record) => { + if (opts.failWrite) throw new Error('account data write failed'); await new Promise((r) => { setTimeout(r, 5); }); @@ -177,6 +179,29 @@ describe('activateEstateRoom when the join gets no answer', () => { }); }); +describe('activateEstateRoom when the filing cannot be written', () => { + it('reports the failure and sends no join', async () => { + const c = dmClient({ failWrite: true, invites: { '!dm1:test': '@friend:test' } }); + const result = await activateEstateRoom(c.mx, tap('!dm1:test')); + expect(result).toEqual({ kind: 'refused', message: 'account data write failed' }); + expect(c.joined).toEqual([]); + }); +}); + +describe('activateEstateRoom when a room that is not a direct message refuses', () => { + it('reports the refusal and leaves m.direct alone', async () => { + const joinRoom = vi + .fn() + .mockRejectedValue( + Object.assign(new Error('no'), { httpStatus: 403, errcode: 'M_FORBIDDEN' }) + ); + const { mx, calls } = recordingClient(joinRoom); + const result = await activateEstateRoom(mx, room('joinable')); + expect(result.kind).toBe('refused'); + expect(calls).toEqual(['joinRoom']); + }); +}); + describe('activateEstateRoom refusal bounds', () => { it.each([400, 429, 499])('unfiles the room on a %i that carries an errcode', async (status) => { const c = dmClient({ @@ -278,8 +303,12 @@ describe('awaitMyJoin', () => { return { mx: { getRoom: () => (membership ? { getMyMembership: () => membership! } : null), - on: (_e: string, h: (room: { roomId: string }, m: string) => void) => handlers.add(h), - off: (_e: string, h: (room: { roomId: string }, m: string) => void) => handlers.delete(h), + on: (e: string, h: (room: { roomId: string }, m: string) => void) => { + if (e === 'Room.myMembership') handlers.add(h); + }, + off: (e: string, h: (room: { roomId: string }, m: string) => void) => { + if (e === 'Room.myMembership') handlers.delete(h); + }, }, handlers, become: (roomId: string, m: string) => {