-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeps.test.ts
More file actions
84 lines (68 loc) · 2.34 KB
/
deps.test.ts
File metadata and controls
84 lines (68 loc) · 2.34 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
import type { Deps } from '../deps';
describe('createDependenciesContainer', () => {
const env = {
LETTERS_TABLE_NAME: 'LettersTable',
LETTER_TTL_HOURS: 12960,
MI_TABLE_NAME: 'MITable',
MI_TTL_HOURS: 2160,
SUPPLIER_ID_HEADER: 'nhsd-supplier-id',
APIM_CORRELATION_HEADER: 'nhsd-correlation-id',
DOWNLOAD_URL_TTL_SECONDS: 60
};
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(),
}));
jest.mock('@aws-sdk/client-sqs', () => ({
SQSClient: jest.fn(),
}));
// Repo client
jest.mock('@internal/datastore', () => ({
LetterRepository: jest.fn(),
MIRepository: jest.fn(),
DBHealthcheck: jest.fn()
}));
// Env
jest.mock('../env', () => ({envVars: env}));
});
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 { SQSClient } = jest.requireMock('@aws-sdk/client-sqs') as { SQSClient: jest.Mock };
const pinoMock = jest.requireMock('pino') as { default: jest.Mock };
const { LetterRepository, MIRepository } = jest.requireMock('@internal/datastore') as {
LetterRepository: jest.Mock,
MIRepository: jest.Mock
};
const { createDependenciesContainer } = require('../deps');
const deps: Deps = createDependenciesContainer();
expect(S3Client).toHaveBeenCalledTimes(1);
expect(SQSClient).toHaveBeenCalledTimes(1);
expect(pinoMock.default).toHaveBeenCalledTimes(1);
expect(LetterRepository).toHaveBeenCalledTimes(1);
const letterRepoCtorArgs = (LetterRepository as jest.Mock).mock.calls[0];
expect(letterRepoCtorArgs[2]).toEqual({
lettersTableName: 'LettersTable',
lettersTtlHours: 12960
});
expect(MIRepository).toHaveBeenCalledTimes(1);
const miRepoCtorArgs = (MIRepository as jest.Mock).mock.calls[0];
expect(miRepoCtorArgs[2]).toEqual({
miTableName: 'MITable',
miTtlHours: 2160
});
expect(deps.env).toEqual(env);
});
});