-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbox-api-yaml.test.ts
More file actions
118 lines (100 loc) · 3.89 KB
/
box-api-yaml.test.ts
File metadata and controls
118 lines (100 loc) · 3.89 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as fs from "fs";
import * as path from "path";
import yaml from "js-yaml";
import { OpenapiToCommands, CliCommand } from "../src/openapi-to-commands";
import { CommandSearch } from "../src/command-search";
import { Profile } from "../src/profile-store";
// Load YAML spec — tests YAML format support
const specPath = path.join(__dirname, "fixtures", "box-openapi.yaml");
const fixtureExists = fs.existsSync(specPath);
const spec = fixtureExists
? (yaml.load(fs.readFileSync(specPath, "utf-8")) as Record<string, unknown>)
: ({} as Record<string, unknown>);
const profile: Profile = {
name: "box",
apiBaseUrl: "https://api.box.com/2.0",
apiBasicAuth: "",
apiBearerToken: "",
authValues: {},
openapiSpecSource: "",
openapiSpecCache: "",
includeEndpoints: [],
excludeEndpoints: [],
commandPrefix: "",
customHeaders: {},
};
const describeIfFixture = fixtureExists ? describe : describe.skip;
describeIfFixture("Box API — YAML spec (258 endpoints)", () => {
let commands: CliCommand[];
let searcher: CommandSearch;
beforeAll(() => {
commands = new OpenapiToCommands().buildCommands(spec, profile);
searcher = new CommandSearch();
searcher.load(commands);
});
describe("YAML spec parsing", () => {
it("parses 250+ endpoints from YAML", () => {
expect(commands.length).toBeGreaterThan(250);
});
it("generates unique command names", () => {
const names = new Set(commands.map((c) => c.name));
expect(names.size).toBe(commands.length);
});
it("every command has valid fields", () => {
for (const cmd of commands) {
expect(cmd.name).toBeTruthy();
expect(cmd.method).toMatch(/^(get|post|put|delete|patch|head|options)$/);
expect(cmd.path).toMatch(/^\//);
}
});
it("preserves descriptions from YAML", () => {
const withDesc = commands.filter((c) => c.description);
expect(withDesc.length).toBeGreaterThan(100);
});
});
describe("BM25 search on YAML-loaded spec", () => {
it("finds file operations", () => {
const results = searcher.search("upload file", 5);
expect(results.length).toBeGreaterThan(0);
expect(results.some((r) => r.path.includes("file"))).toBe(true);
});
it("finds folder operations", () => {
const results = searcher.search("create folder items", 5);
expect(results.length).toBeGreaterThan(0);
expect(results.some((r) => r.path.includes("folder"))).toBe(true);
});
it("finds collaboration endpoints", () => {
const results = searcher.search("collaboration invite share", 5);
expect(results.length).toBeGreaterThan(0);
expect(results.some((r) => r.path.includes("collaborat"))).toBe(true);
});
it("finds comment endpoints", () => {
const results = searcher.search("comment on file", 5);
expect(results.length).toBeGreaterThan(0);
expect(results.some((r) => r.path.includes("comment"))).toBe(true);
});
it("finds user/group management", () => {
const results = searcher.search("user group membership", 5);
expect(results.length).toBeGreaterThan(0);
});
it("finds webhook/event endpoints", () => {
const results = searcher.search("webhook event notification", 5);
expect(results.length).toBeGreaterThan(0);
});
it("finds metadata endpoints", () => {
const results = searcher.search("metadata template", 5);
expect(results.length).toBeGreaterThan(0);
expect(results.some((r) => r.path.includes("metadata"))).toBe(true);
});
});
describe("regex search on YAML-loaded spec", () => {
it("finds all file-related endpoints", () => {
const results = searcher.searchRegex("/files/", 100);
expect(results.length).toBeGreaterThan(10);
});
it("finds all folder-related endpoints", () => {
const results = searcher.searchRegex("/folders/", 100);
expect(results.length).toBeGreaterThan(5);
});
});
});