Skip to content

Commit a3a67ca

Browse files
committed
v1.5.0
1 parent 0f236bc commit a3a67ca

File tree

14 files changed

+784
-673
lines changed

14 files changed

+784
-673
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "OpenAPI DevTools",
4-
"version": "1.4.2",
4+
"version": "1.5.0",
55
"devtools_page": "index.html",
66
"permissions": [],
77
"icons": {

resources/dist.zip

812 Bytes
Binary file not shown.

src/lib/RequestStore.test.ts

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { it, expect, vi } from "vitest";
2-
import { createSimpleRequest } from "./__fixtures__/simple-request";
3-
import RequestStore from "./RequestStore";
4-
import { defaultOptions } from "./store-helpers/persist-options";
1+
import { expect, it, vi } from "vitest";
52

6-
vi.mock('./store-helpers/persist-options', async () => {
3+
import { createSimpleRequest } from "./__fixtures__/simple-request.js";
4+
import RequestStore from "./RequestStore.js";
5+
import { defaultOptions } from "./store-helpers/persist-options.js";
6+
7+
vi.mock("./store-helpers/persist-options", async () => {
78
const actual = await vi.importActual("./store-helpers/persist-options");
89
return {
910
// @ts-expect-error ignored
@@ -17,11 +18,17 @@ const host = "test.com";
1718
const base = `https://${host}`;
1819
const POST = "POST";
1920

20-
const getResBodyJSONTypes = (store: RequestStore, host: string, path: string, propName = 'foo') => {
21-
const match = store.get()[host].lookup(path);
21+
const getResBodyJSONTypes = (
22+
store: RequestStore,
23+
host: string,
24+
path: string,
25+
propName = "foo",
26+
) => {
27+
const match = store.get()[host]?.lookup(path);
2228
if (!match) throw new Error("Could not match path");
2329
const properties =
24-
match.data.methods[POST][200].response['application/json'].body?.properties?.[propName].type;
30+
match.data.methods[POST]?.response?.[200]?.["application/json"]?.body
31+
?.properties?.[propName]?.type || undefined;
2532
return properties;
2633
};
2734

@@ -70,16 +77,25 @@ it("sets leafMap correctly after multiple add and parameterise operations", () =
7077
store.parameterise(1, "/dynamicPath/2/:param2", host);
7178
const expected = {
7279
[host]: {
73-
'/1/:param1/:param2': expect.any(Object),
74-
'/dynamicPath/:param1/:param2': expect.any(Object),
75-
'/staticPath/2/3/4/5': expect.any(Object),
76-
}
80+
"/1/:param1/:param2": expect.any(Object),
81+
"/dynamicPath/:param1/:param2": expect.any(Object),
82+
"/staticPath/2/3/4/5": expect.any(Object),
83+
},
7784
};
7885
// @ts-expect-error accessing private property
7986
expect(store.leafMap).toEqual(expected);
80-
expect(getResBodyJSONTypes(store, host, "/1/x/x")).toEqual(["null", "integer", "string"]);
81-
expect(getResBodyJSONTypes(store, host, "/dynamicPath/2/x")).toEqual(["integer", "string"]);
82-
expect(getResBodyJSONTypes(store, host, "/staticPath/2/3/4/5")).toBe('string');
87+
expect(getResBodyJSONTypes(store, host, "/1/x/x")).toEqual([
88+
"null",
89+
"integer",
90+
"string",
91+
]);
92+
expect(getResBodyJSONTypes(store, host, "/dynamicPath/2/x")).toEqual([
93+
"integer",
94+
"string",
95+
]);
96+
expect(getResBodyJSONTypes(store, host, "/staticPath/2/3/4/5")).toBe(
97+
"string",
98+
);
8399
});
84100

85101
it("sets leafMap correctly after many parameterise operations", () => {
@@ -97,16 +113,19 @@ it("sets leafMap correctly after many parameterise operations", () => {
97113
store.parameterise(3, "/1/2/3/4/:param4", host);
98114
const expected = {
99115
[host]: {
100-
'/1/2/3/:param3/:param4': expect.any(Object),
101-
'/1/2/b': expect.any(Object),
102-
'/1/x/y/:param3/b': expect.any(Object),
103-
}
116+
"/1/2/3/:param3/:param4": expect.any(Object),
117+
"/1/2/b": expect.any(Object),
118+
"/1/x/y/:param3/b": expect.any(Object),
119+
},
104120
};
105121
// @ts-expect-error accessing private property
106122
expect(store.leafMap).toEqual(expected);
107-
expect(getResBodyJSONTypes(store, host, "/1/2/3/ANY/ANY")).toEqual(["null", "string"]);
123+
expect(getResBodyJSONTypes(store, host, "/1/2/3/ANY/ANY")).toEqual([
124+
"null",
125+
"string",
126+
]);
108127
expect(getResBodyJSONTypes(store, host, "/1/2/b")).toBe("boolean");
109-
expect(getResBodyJSONTypes(store, host, "/1/x/y/ANY/b")).toBe('integer');
128+
expect(getResBodyJSONTypes(store, host, "/1/x/y/ANY/b")).toBe("integer");
110129
});
111130

112131
it("collapses into a single route when paramaterised", () => {
@@ -121,12 +140,16 @@ it("collapses into a single route when paramaterised", () => {
121140
store.parameterise(4, "/1/2/3/:param3/a", host);
122141
const expected = {
123142
[host]: {
124-
'/1/2/3/:param3/:param4': expect.any(Object),
125-
}
143+
"/1/2/3/:param3/:param4": expect.any(Object),
144+
},
126145
};
127146
// @ts-expect-error accessing private property
128147
expect(store.leafMap).toEqual(expected);
129-
expect(getResBodyJSONTypes(store, host, "/1/2/3/ANY/ANY")).toEqual(["null", "integer", "string"]);
148+
expect(getResBodyJSONTypes(store, host, "/1/2/3/ANY/ANY")).toEqual([
149+
"null",
150+
"integer",
151+
"string",
152+
]);
130153
});
131154

132155
it("can parameterise paths that are subsets of another path", () => {
@@ -138,9 +161,9 @@ it("can parameterise paths that are subsets of another path", () => {
138161
store.parameterise(1, "/1/2", host);
139162
const expected = {
140163
[host]: {
141-
'/1/2/a': expect.any(Object),
142-
'/1/:param1': expect.any(Object),
143-
}
164+
"/1/2/a": expect.any(Object),
165+
"/1/:param1": expect.any(Object),
166+
},
144167
};
145168
// @ts-expect-error accessing private property
146169
expect(store.leafMap).toEqual(expected);
@@ -163,11 +186,11 @@ it("can parameterise paths that exist along the same segment", () => {
163186
store.parameterise(1, "/1/2", host);
164187
const expected = {
165188
[host]: {
166-
'/1': expect.any(Object),
167-
'/1/2/3/4': expect.any(Object),
168-
'/1/:param1/a': expect.any(Object),
169-
'/1/:param1': expect.any(Object),
170-
}
189+
"/1": expect.any(Object),
190+
"/1/2/3/4": expect.any(Object),
191+
"/1/:param1/a": expect.any(Object),
192+
"/1/:param1": expect.any(Object),
193+
},
171194
};
172195
// @ts-expect-error accessing private property
173196
expect(store.leafMap).toEqual(expected);
@@ -186,9 +209,9 @@ it("parameterising a path catches future requests to the same path", () => {
186209
store.insert(req2, { foo: 1 });
187210
const expected = {
188211
[host]: {
189-
'/1/:param1/a': expect.any(Object),
190-
'/1/2/b': expect.any(Object),
191-
}
212+
"/1/:param1/a": expect.any(Object),
213+
"/1/2/b": expect.any(Object),
214+
},
192215
};
193216
// @ts-expect-error accessing private property
194217
expect(store.leafMap).toEqual(expected);
@@ -197,17 +220,24 @@ it("parameterising a path catches future requests to the same path", () => {
197220
it("parameterisation works after export and import", () => {
198221
const store = new RequestStore();
199222
const req = createSimpleRequest(`${base}/1/2/a`);
223+
const options = { enableMoreInfo: true };
224+
store.options(options);
200225
store.insert(req, { foo: 1 });
201226
store.parameterise(2, "/1/2/a", host);
202227
const exported = store.export();
203228
store.clear();
204229
store.import(exported);
205230
store.insert(req, { foo: 1 });
206-
const expected = {
231+
const expectedLeafMap = {
207232
[host]: {
208-
'/1/2/:param2': expect.any(Object),
209-
}
233+
"/1/2/:param2": expect.any(Object),
234+
},
235+
};
236+
const expectedOptions = {
237+
enableMoreInfo: true,
210238
};
211239
// @ts-expect-error accessing private property
212-
expect(store.leafMap).toEqual(expected);
240+
expect(store.leafMap).toEqual(expectedLeafMap);
241+
// @ts-expect-error accessing private property
242+
expect(store.storeOptions).toEqual(expectedOptions);
213243
});

0 commit comments

Comments
 (0)