-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathtools.test.js
More file actions
76 lines (67 loc) · 2.27 KB
/
tools.test.js
File metadata and controls
76 lines (67 loc) · 2.27 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
import { describe, expect, test } from "bun:test";
import { formatResult } from "../src/mcp-server/tools.js";
describe("formatResult link normalization", () => {
test("rewrites app.launchdarkly.com href to response origin", async () => {
const origin = "https://random-domain.example.test";
const input = {
_links: {
site: {
href: "https://app.launchdarkly.com/default/production/features/flag-a",
},
},
};
const response = {
headers: new Headers({ "content-type": "application/json" }),
url: `${origin}/api/v2/flags/default/flag-a`,
};
const result = await formatResult(input, { response });
const text = result.content[0];
expect(text?.type).toBe("text");
const parsed = JSON.parse(text.text);
expect(parsed._links.site.href).toBe(
`${origin}/default/production/features/flag-a`,
);
});
test("rewrites app.launchdarkly.us href to response origin", async () => {
const origin = "https://federal-alt.example.test";
const input = {
_links: {
site: {
href: "https://app.launchdarkly.us/default/production/features/flag-c",
},
},
};
const response = {
headers: new Headers({ "content-type": "application/json" }),
url: `${origin}/api/v2/flags/default/flag-c`,
};
const result = await formatResult(input, { response });
const text = result.content[0];
expect(text?.type).toBe("text");
const parsed = JSON.parse(text.text);
expect(parsed._links.site.href).toBe(
`${origin}/default/production/features/flag-c`,
);
});
test("expands relative href against response origin", async () => {
const origin = "https://another-random.example.test";
const input = {
_links: {
site: {
href: "/default/production/features/flag-b",
},
},
};
const response = {
headers: new Headers({ "content-type": "application/json" }),
url: `${origin}/api/v2/flags/default/flag-b`,
};
const result = await formatResult(input, { response });
const text = result.content[0];
expect(text?.type).toBe("text");
const parsed = JSON.parse(text.text);
expect(parsed._links.site.href).toBe(
`${origin}/default/production/features/flag-b`,
);
});
});