-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
82 lines (72 loc) · 1.83 KB
/
index.ts
File metadata and controls
82 lines (72 loc) · 1.83 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
import pino from "pino";
import { microservice, healthcheck } from "../../../src/index";
jest.mock("register-server-handlers");
jest.mock("sourced-repo-typeorm", () => {
return {
Repository: jest.fn(),
persistenceLayer: {
connect: jest.fn(() => Promise.resolve(true)),
disconnect: jest.fn(() => Promise.resolve(true)),
},
};
});
jest.mock("express", () => {
const m: any = {
__esModule: true,
Router: jest.fn(() => ({
use: jest.fn(),
get: jest.fn(),
post: jest.fn(),
})),
};
m.default = jest.fn(() => ({
use: jest.fn(),
get: jest.fn(),
post: jest.fn(),
listen: jest.fn(() => ({
close: jest.fn(),
})),
close: jest.fn(),
}));
m.default.urlencoded = jest.fn();
m.default.json = jest.fn();
return m;
});
jest.spyOn(process, "exit").mockImplementation(() => {
return undefined as never;
});
describe("src/index.ts", () => {
it("should start our service", async () => {
const { server, logger, onListen, shutdown } = await microservice({
handlers: {
path: "path",
options: {
enableSyncSendToDenormalizer: true,
enableEventPublishing: true,
},
},
logger: pino(),
});
expect(server.use).toBeCalledTimes(4);
const { persistenceLayer } = await import("sourced-repo-typeorm");
onListen(3000)();
await shutdown(persistenceLayer)();
expect(server.close).toBeCalled();
expect(persistenceLayer.disconnect).toBeCalled();
});
});
describe("healthcheck", () => {
it("should respond with 200", () => {
const send = jest.fn();
const json = jest.fn();
const reply = {
status: jest.fn(() => ({
send,
json,
})),
};
healthcheck({}, reply);
expect(reply.status).toBeCalledWith(200);
expect(send).toBeCalledWith("ok");
});
});