-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcontainer.test.ts
More file actions
60 lines (48 loc) · 1.77 KB
/
container.test.ts
File metadata and controls
60 lines (48 loc) · 1.77 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
import { createContainer } from 'container';
import * as configModule from 'infra/config';
jest.mock('infra/config');
const mockLoadConfig = configModule.loadConfig as jest.MockedFunction<
typeof configModule.loadConfig
>;
describe('createContainer', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should create container with all dependencies', () => {
mockLoadConfig.mockReturnValue({
documentReferenceBucket: 'test-doc-ref-bucket',
environment: 'test',
unscannedFilesBucket: 'test-unscanned-bucket',
unscannedFilesPathPrefix: 'dev',
eventPublisherEventBusArn:
'arn:aws:events:us-east-1:123456789012:event-bus/test',
eventPublisherDlqUrl: 'https://sqs.us-east-1.amazonaws.com/dlq',
dlMetricsNamespace: 'test-namespace',
});
const container = createContainer();
expect(container).toHaveProperty('eventPublisher');
expect(container).toHaveProperty('logger');
expect(container).toHaveProperty('fileScanner');
expect(mockLoadConfig).toHaveBeenCalledTimes(1);
});
it('should call loadConfig to get configuration', () => {
const mockConfig = {
documentReferenceBucket: 'test-bucket',
environment: 'test',
unscannedFilesBucket: 'test-unscanned',
unscannedFilesPathPrefix: 'dev',
eventPublisherEventBusArn: 'arn:test',
eventPublisherDlqUrl: 'url:test',
dlMetricsNamespace: 'test-namespace',
};
mockLoadConfig.mockReturnValue(mockConfig);
createContainer();
expect(mockLoadConfig).toHaveBeenCalled();
});
it('should propagate config errors', () => {
mockLoadConfig.mockImplementation(() => {
throw new Error('Missing required config');
});
expect(() => createContainer()).toThrow('Missing required config');
});
});