good forst commit
This commit is contained in:
@@ -1,11 +1,25 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GroupsController } from './groups.controller';
|
||||
import { GroupsService } from './groups.service';
|
||||
import type { TenantContext } from '../../common/tenant-context';
|
||||
|
||||
const ctx: TenantContext = { tenantId: 'tnt-A', adminId: 'adm_1', role: 'OWNER' };
|
||||
|
||||
const mockGroups = [
|
||||
{ id: 'grp_1', name: 'Alpha', platform: 'whatsapp', platformId: '111@g.us', isActive: true, accountId: 'acc_1' },
|
||||
{ id: 'grp_1', name: 'Alpha', platform: 'whatsapp', platformId: '111@g.us', isActive: true, accountId: 'acc_1', tenantId: 'tnt-A' },
|
||||
];
|
||||
const mockService = { list: jest.fn().mockResolvedValue(mockGroups) };
|
||||
|
||||
const mockService = {
|
||||
list: jest.fn().mockResolvedValue(mockGroups),
|
||||
listShared: jest.fn().mockResolvedValue([]),
|
||||
listSharedByMe: jest.fn().mockResolvedValue([]),
|
||||
getClaimTokenInfo: jest.fn(),
|
||||
claimWithToken: jest.fn(),
|
||||
share: jest.fn(),
|
||||
unshare: jest.fn(),
|
||||
regenerateToken: jest.fn(),
|
||||
listUnclaimed: jest.fn().mockResolvedValue([]),
|
||||
};
|
||||
|
||||
describe('GroupsController', () => {
|
||||
let controller: GroupsController;
|
||||
@@ -22,9 +36,29 @@ describe('GroupsController', () => {
|
||||
controller = module.get<GroupsController>(GroupsController);
|
||||
});
|
||||
|
||||
it('returns groups from service', async () => {
|
||||
const result = await controller.list();
|
||||
it('list() delegates to service', async () => {
|
||||
const result = await controller.list(ctx);
|
||||
expect(result).toEqual(mockGroups);
|
||||
expect(mockService.list).toHaveBeenCalled();
|
||||
expect(mockService.list).toHaveBeenCalledWith('tnt-A');
|
||||
});
|
||||
|
||||
it('listShared() delegates to service', async () => {
|
||||
await controller.listShared(ctx);
|
||||
expect(mockService.listShared).toHaveBeenCalledWith('tnt-A');
|
||||
});
|
||||
|
||||
it('claimWithToken() delegates to service', async () => {
|
||||
await controller.claimWithToken(ctx, { token: 'abc123' });
|
||||
expect(mockService.claimWithToken).toHaveBeenCalledWith('abc123', 'adm_1');
|
||||
});
|
||||
|
||||
it('share() delegates to service', async () => {
|
||||
await controller.share(ctx, 'grp_1', { targetTenantId: 'tnt-B' });
|
||||
expect(mockService.share).toHaveBeenCalledWith('tnt-A', 'adm_1', 'grp_1', 'tnt-B');
|
||||
});
|
||||
|
||||
it('listUnclaimed() delegates to service', async () => {
|
||||
await controller.listUnclaimed();
|
||||
expect(mockService.listUnclaimed).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user