-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdialer.tests.ts
88 lines (69 loc) · 2.5 KB
/
dialer.tests.ts
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
import { join } from "path";
import { DialerContext } from "./dialer.types";
import { DialerRegistry } from "./dialer";
const dialPath = join("example", "dialer.ts");
describe("DialerRegistry interaction", () => {
it("initializes the dialer registry with the dialer file", async () => {
// Act
const actual = new DialerRegistry(dialPath);
// Assert
expect(actual).toBeInstanceOf(DialerRegistry);
});
it("correctly executes registered pre-dialer", async () => {
// Arrange
const mockPreDialer = jest.fn();
const registry = new DialerRegistry(dialPath);
registry.registerPreDialer(mockPreDialer);
// Act
await registry.executePreDialers({} as any as DialerContext);
// Assert
expect(mockPreDialer).toHaveBeenCalledTimes(1);
});
it("correctly executes registered post-dialer", async () => {
// Arrange
const mockPostDialer = jest.fn();
const registry = new DialerRegistry(dialPath);
registry.registerPostDialer(mockPostDialer);
// Act
await registry.executePostDialers({} as any as DialerContext);
// Assert
expect(mockPostDialer).toHaveBeenCalledTimes(1);
});
it("all the pre-dialers are executed", async () => {
// Arrange
const mockPreDialer1 = jest.fn();
const mockPreDialer2 = jest.fn();
const registry = new DialerRegistry(dialPath);
registry.registerPreDialer(mockPreDialer1);
registry.registerPreDialer(mockPreDialer2);
// Act
await registry.executePreDialers({} as any as DialerContext);
// Assert
expect(mockPreDialer1).toHaveBeenCalledTimes(1);
expect(mockPreDialer2).toHaveBeenCalledTimes(1);
});
it("all the post-dialers are executed", async () => {
// Arrange
const mockPostDialer1 = jest.fn();
const mockPostDialer2 = jest.fn();
const registry = new DialerRegistry(dialPath);
registry.registerPostDialer(mockPostDialer1);
registry.registerPostDialer(mockPostDialer2);
// Act
await registry.executePostDialers({} as any as DialerContext);
// Assert
expect(mockPostDialer1).toHaveBeenCalledTimes(1);
expect(mockPostDialer2).toHaveBeenCalledTimes(1);
});
it("early exits when specified dialer file is not found", async () => {
// Arrange
jest.spyOn(process, "exit").mockImplementation(() => {
throw new Error("process.exit was called");
});
const registry = new DialerRegistry("non-existent.js");
// Act & Assert
expect(registry.registerDialers()).rejects.toThrow(
"process.exit was called"
);
});
});