-
Notifications
You must be signed in to change notification settings - Fork 309
Expand file tree
/
Copy pathadmin-evidence.controller.spec.ts
More file actions
94 lines (80 loc) · 2.66 KB
/
admin-evidence.controller.spec.ts
File metadata and controls
94 lines (80 loc) · 2.66 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Test, TestingModule } from '@nestjs/testing';
import { BadRequestException } from '@nestjs/common';
import { AdminEvidenceController } from './admin-evidence.controller';
import { EvidenceFormsService } from '../evidence-forms/evidence-forms.service';
jest.mock('../auth/platform-admin.guard', () => ({
PlatformAdminGuard: class {
canActivate() {
return true;
}
},
}));
jest.mock('../auth/auth.server', () => ({
auth: { api: {} },
}));
jest.mock('@db', () => ({ db: {} }));
describe('AdminEvidenceController', () => {
let controller: AdminEvidenceController;
const mockService = {
getFormStatuses: jest.fn(),
getFormWithSubmissions: jest.fn(),
};
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [AdminEvidenceController],
providers: [
{ provide: EvidenceFormsService, useValue: mockService },
],
}).compile();
controller = module.get<AdminEvidenceController>(AdminEvidenceController);
jest.clearAllMocks();
});
describe('listFormStatuses', () => {
it('should return form statuses', async () => {
const statuses = {
'access-request': { lastSubmittedAt: '2026-01-01' },
meeting: { lastSubmittedAt: null },
};
mockService.getFormStatuses.mockResolvedValue(statuses);
const result = await controller.listFormStatuses('org_1');
expect(mockService.getFormStatuses).toHaveBeenCalledWith('org_1');
expect(result).toEqual(statuses);
});
});
describe('getFormWithSubmissions', () => {
it('should return form with submissions', async () => {
const detail = {
form: { type: 'meeting', label: 'Meeting' },
submissions: [],
total: 0,
};
mockService.getFormWithSubmissions.mockResolvedValue(detail);
const mockReq = { userId: 'usr_admin1' };
const result = await controller.getFormWithSubmissions(
'org_1',
'meeting',
mockReq,
);
expect(mockService.getFormWithSubmissions).toHaveBeenCalledWith({
organizationId: 'org_1',
authContext: expect.objectContaining({
userId: 'usr_admin1',
isPlatformAdmin: true,
isApiKey: false,
userRoles: ['admin'],
}),
formType: 'meeting',
search: undefined,
limit: undefined,
offset: undefined,
});
expect(result).toEqual(detail);
});
it('should reject empty formType', async () => {
const mockReq = { userId: 'usr_admin1' };
await expect(
controller.getFormWithSubmissions('org_1', '', mockReq),
).rejects.toThrow(BadRequestException);
});
});
});