Skip to content

Commit cbf8c79

Browse files
test: cover encrypted: false case for discussion creation
Adds the inverse assertion suggested in review: with the encrypted toggle left off on an unencrypted parent room, the rooms.createDiscussion endpoint is called with encrypted: false. Guards against the field being accidentally hardcoded truthy in a future change.
1 parent d065200 commit cbf8c79

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

‎apps/meteor/client/components/CreateDiscussion/CreateDiscussion.spec.tsx‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,52 @@ describe('CreateDiscussion', () => {
109109
);
110110
});
111111
});
112+
113+
it('should send encrypted: false to the API when the encrypted toggle is left off for an unencrypted parent room', async () => {
114+
const createDiscussionEndpoint = jest.fn().mockReturnValue({
115+
success: true,
116+
discussion: {
117+
...createFakeRoom({ _id: 'discussion-id', t: 'p' as const, prid: room2._id }),
118+
rid: 'discussion-id',
119+
} as any,
120+
});
121+
122+
const appRootWithSpy = mockAppRoot()
123+
.withEndpoint('POST', '/v1/rooms.createDiscussion', createDiscussionEndpoint)
124+
.withEndpoint('GET', '/v1/rooms.autocomplete.channelAndPrivate', () => ({ items: [room1, room2] }) as any)
125+
.withTranslations('en', 'core', {
126+
Encrypted: 'Encrypted',
127+
Name: 'Name',
128+
Create: 'Create',
129+
Discussion_target_channel: 'Parent channel or team',
130+
})
131+
.build();
132+
133+
render(<CreateDiscussion onClose={jest.fn()} />, { wrapper: appRootWithSpy });
134+
135+
const parentRoomSelect = screen.getByRole('textbox', { name: 'Parent channel or team' });
136+
await userEvent.click(parentRoomSelect);
137+
await waitFor(() => {
138+
expect(screen.getByText('Unencrypted Room 2')).toBeInTheDocument();
139+
});
140+
await userEvent.click(screen.getByText('Unencrypted Room 2'));
141+
142+
await userEvent.type(screen.getByLabelText('Name'), 'My public discussion');
143+
144+
// leave the encrypted toggle off
145+
146+
await userEvent.click(screen.getByRole('button', { name: 'Create' }));
147+
148+
await waitFor(() => {
149+
expect(createDiscussionEndpoint).toHaveBeenCalledWith(
150+
expect.objectContaining({
151+
prid: room2._id,
152+
t_name: 'My public discussion',
153+
encrypted: false,
154+
}),
155+
);
156+
});
157+
});
112158
});
113159

114160
describe('Encrypted parent room behavior', () => {

0 commit comments

Comments
 (0)