Spaces:
Runtime error
Runtime error
File size: 2,199 Bytes
46252cd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import { GroupController } from './group.controller';
import { GroupService } from './group.service';
describe('GroupController join + settings', () => {
const build = (service: Partial<Record<keyof GroupService, jest.Mock>>) => {
const controller = new GroupController(service as unknown as GroupService);
return { controller, service };
};
it('POST join returns the success envelope with the group id', async () => {
const { controller, service } = build({
joinGroupViaInviteCode: jest.fn().mockResolvedValue('120363000@g.us'),
});
await expect(controller.join('s1', { inviteCode: 'CODE123' })).resolves.toEqual({
success: true,
groupId: '120363000@g.us',
});
expect(service.joinGroupViaInviteCode).toHaveBeenCalledWith('s1', 'CODE123');
});
it('GET :groupId/settings delegates to the service (404 mapping lives there)', async () => {
const { controller, service } = build({
getGroupSettings: jest.fn().mockResolvedValue({ announce: true, locked: false, ephemeralSeconds: 86400 }),
});
await expect(controller.getSettings('s1', 'g1')).resolves.toEqual({
announce: true,
locked: false,
ephemeralSeconds: 86400,
});
expect(service.getGroupSettings).toHaveBeenCalledWith('s1', 'g1');
});
it('PUT :groupId/settings forwards the patch and returns the success envelope', async () => {
const { controller, service } = build({ updateGroupSettings: jest.fn().mockResolvedValue(undefined) });
const dto = { announce: true, ephemeralSeconds: 0 };
await expect(controller.updateSettings('s1', 'g1', dto)).resolves.toEqual({
success: true,
message: 'Group settings updated',
});
expect(service.updateGroupSettings).toHaveBeenCalledWith('s1', 'g1', dto);
});
it('PUT :groupId/settings propagates a service rejection (empty patch / 501 passthrough)', async () => {
const { controller } = build({
updateGroupSettings: jest
.fn()
.mockRejectedValue(new Error('At least one of announce, locked, ephemeralSeconds must be provided')),
});
await expect(controller.updateSettings('s1', 'g1', {})).rejects.toThrow(/At least one/);
});
});
|