-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeps.test.ts
More file actions
68 lines (58 loc) · 1.99 KB
/
deps.test.ts
File metadata and controls
68 lines (58 loc) · 1.99 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
import type { Deps } from '../deps';
describe('createDependenciesContainer', () => {
beforeEach(() => {
jest.clearAllMocks();
jest.resetModules();
// pino
jest.mock('pino', () => ({
__esModule: true,
default: jest.fn(() => ({
info: jest.fn(),
error: jest.fn(),
warn: jest.fn(),
debug: jest.fn(),
})),
}));
jest.mock('@aws-sdk/client-s3', () => ({
S3Client: jest.fn(),
}));
// Repo client
jest.mock('../../../../../internal/datastore', () => ({
LetterRepository: jest.fn(),
DBHealthcheck: jest.fn()
}));
// Env
jest.mock('../env', () => ({
envVars: {
LETTERS_TABLE_NAME: 'LettersTable',
LETTER_TTL_HOURS: 12960,
SUPPLIER_ID_HEADER: 'nhsd-supplier-id',
APIM_CORRELATION_HEADER: 'nhsd-correlation-id',
DOWNLOAD_URL_TTL_SECONDS: 60
},
}));
});
test('constructs deps and wires repository config correctly', async () => {
// get current mock instances
const { S3Client } = jest.requireMock('@aws-sdk/client-s3') as { S3Client: jest.Mock };
const pinoMock = jest.requireMock('pino') as { default: jest.Mock };
const { LetterRepository } = jest.requireMock('../../../../../internal/datastore') as { LetterRepository: jest.Mock };
const { createDependenciesContainer } = require('../deps');
const deps: Deps = createDependenciesContainer();
expect(S3Client).toHaveBeenCalledTimes(1);
expect(pinoMock.default).toHaveBeenCalledTimes(1);
expect(LetterRepository).toHaveBeenCalledTimes(1);
const repoCtorArgs = (LetterRepository as jest.Mock).mock.calls[0];
expect(repoCtorArgs[2]).toEqual({
lettersTableName: 'LettersTable',
ttlHours: 12960
});
expect(deps.env).toEqual({
LETTERS_TABLE_NAME: 'LettersTable',
LETTER_TTL_HOURS: 12960,
SUPPLIER_ID_HEADER: 'nhsd-supplier-id',
APIM_CORRELATION_HEADER: 'nhsd-correlation-id',
DOWNLOAD_URL_TTL_SECONDS: 60
});
});
});