-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdeps.test.ts
More file actions
84 lines (69 loc) · 2.29 KB
/
Copy pathdeps.test.ts
File metadata and controls
84 lines (69 loc) · 2.29 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: 12_960,
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");
const { SQSClient } = jest.requireMock("@aws-sdk/client-sqs");
const pinoMock = jest.requireMock("pino");
const { LetterRepository, MIRepository } = jest.requireMock(
"@internal/datastore",
);
// allow re-import of deps to leverage mocks
// eslint-disable-next-line @typescript-eslint/no-require-imports
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.mock.calls[0];
expect(letterRepoCtorArgs[2]).toEqual({
lettersTableName: "LettersTable",
lettersTtlHours: 12_960,
});
expect(MIRepository).toHaveBeenCalledTimes(1);
const miRepoCtorArgs = MIRepository.mock.calls[0];
expect(miRepoCtorArgs[2]).toEqual({
miTableName: "MITable",
miTtlHours: 2160,
});
expect(deps.env).toEqual(env);
});
});