Repository navigation
Expand file tree
/
Copy pathNodeRequestInfoPlugin.test.ts
More file actions
65 lines (57 loc) · 1.68 KB
/
Copy pathNodeRequestInfoPlugin.test.ts
File metadata and controls
65 lines (57 loc) · 1.68 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
import { describe, expect, test } from "vitest";
import { EventContext, EventPluginContext, ExceptionlessClient, KnownEventDataKeys, RequestInfo } from "@exceptionless/core";
import { NodeRequestInfoPlugin } from "../../src/plugins/NodeRequestInfoPlugin.js";
describe("NodeRequestInfoPlugin", () => {
const run = async (request: Record<string, unknown>): Promise<RequestInfo | undefined> => {
const client = new ExceptionlessClient();
const eventContext = new EventContext();
eventContext[KnownEventDataKeys.RequestInfo] = request;
const context = new EventPluginContext(
client,
{
data: {}
},
eventContext
);
await new NodeRequestInfoPlugin().run(context);
return context.event.data?.[KnownEventDataKeys.RequestInfo];
};
test("should set query_string from the request query instead of route params", async () => {
const requestInfo = await run({
method: "GET",
secure: false,
ip: "127.0.0.1",
hostname: "localhost",
path: "/users/42",
headers: {
host: "localhost:3000",
"user-agent": "test"
},
params: {
id: "42"
},
query: {
search: "abc",
page: "2"
}
});
expect(requestInfo?.path).toBe("/users/42");
expect(requestInfo?.query_string).toEqual({
search: "abc",
page: "2"
});
});
test("should omit query_string when the request has no query", async () => {
const requestInfo = await run({
method: "GET",
path: "/users/42",
headers: {
"user-agent": "test"
},
params: {
id: "42"
}
});
expect(requestInfo?.query_string).toBeUndefined();
});
});