forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest-context.service.spec.ts
More file actions
48 lines (39 loc) · 1.38 KB
/
Copy pathrequest-context.service.spec.ts
File metadata and controls
48 lines (39 loc) · 1.38 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
import { Test, TestingModule } from "@nestjs/testing";
import { RequestContextService } from "./request-context.service";
import { StructuredLogger } from "./structured-logger.service";
describe("RequestContextService", () => {
let service: RequestContextService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [RequestContextService, StructuredLogger],
}).compile();
service = module.get(RequestContextService);
});
it("propagates correlationId across async boundaries", async () => {
const seen: string[] = [];
await service.runWithContext(
{ correlationId: "corr-1", traceId: "corr-1" },
async () => {
seen.push(service.getCorrelationId() ?? "");
await Promise.resolve();
seen.push(service.getCorrelationId() ?? "");
},
);
expect(seen).toEqual(["corr-1", "corr-1"]);
});
it("inherits traceId in child worker context", async () => {
let childTraceId: string | undefined;
await service.runWithWorkerContext(
{ workerName: "horizon-watcher", correlationId: "worker-corr" },
async () => {
await service.runWithChildContext(
{ correlationId: "horizon:tx-123" },
async () => {
childTraceId = service.getTraceId();
},
);
},
);
expect(childTraceId).toBe("worker-corr");
});
});