Skip to content

Commit b2e76ba

Browse files
committed
test: add mock wrapper
1 parent e67ecd8 commit b2e76ba

File tree

9 files changed

+184
-297
lines changed

9 files changed

+184
-297
lines changed

src/mocks/autoAPIMock.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { HttpResponseResolver, JsonBodyType } from "msw";
2+
import { HttpResponse } from "msw";
3+
4+
type ResponseResolverInfo = Parameters<HttpResponseResolver>[0];
5+
6+
type OverrideFn<T> = (data: T, info: ResponseResolverInfo) => Response;
7+
8+
export interface AutoAPIMockInstance<T> {
9+
generatedHandler: HttpResponseResolver;
10+
override: (fn: OverrideFn<T>) => AutoAPIMockInstance<T>;
11+
reset: () => AutoAPIMockInstance<T>;
12+
defaultValue: T;
13+
}
14+
15+
// Registry to track all instances for bulk reset
16+
const registry: Set<AutoAPIMockInstance<unknown>> = new Set();
17+
18+
export function AutoAPIMock<T>(defaultValue: T): AutoAPIMockInstance<T> {
19+
let overrideFn: OverrideFn<T> | null = null;
20+
21+
const instance: AutoAPIMockInstance<T> = {
22+
defaultValue,
23+
24+
generatedHandler(info: ResponseResolverInfo) {
25+
if (overrideFn) {
26+
return overrideFn(defaultValue, info);
27+
}
28+
return HttpResponse.json(defaultValue as JsonBodyType);
29+
},
30+
31+
override(fn: OverrideFn<T>) {
32+
overrideFn = fn;
33+
return instance;
34+
},
35+
36+
reset() {
37+
overrideFn = null;
38+
return instance;
39+
},
40+
};
41+
42+
registry.add(instance as AutoAPIMockInstance<unknown>);
43+
44+
return instance;
45+
}
46+
47+
export function resetAllAutoAPIMocks(): void {
48+
for (const instance of registry) {
49+
instance.reset();
50+
}
51+
}

src/mocks/fixtures/registry_v0_1_servers/get.ts

Lines changed: 40 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
export default {
1+
import type { GetRegistryV01ServersResponse } from "@api/types.gen";
2+
import { AutoAPIMock } from "@mocks";
3+
4+
export default AutoAPIMock<GetRegistryV01ServersResponse>({
25
servers: [
36
{
47
server: {
5-
title: "consequat",
8+
title: "AWS Nova Canvas",
69
name: "awslabs/aws-nova-canvas",
710
version: "1.0.0",
811
description:
@@ -13,48 +16,23 @@ export default {
1316
url: "https://github.com/awslabs/aws-nova-canvas",
1417
},
1518
_meta: {
16-
ullamco_566: false,
17-
"io.modelcontextprotocol.registry/publisher-provided": {
18-
est_84: {},
19-
sed3: {},
20-
voluptate_: {},
21-
},
19+
"io.modelcontextprotocol.registry/publisher-provided": {},
2220
},
2321
icons: [
2422
{
25-
sizes: ["nostrud"],
26-
mimeType: "laboris",
27-
src: "http://AZUjhw.iemoiU+bM+FdKbi8L+QcXuAdmepZez7WVN,gwb6k.fLABJ",
23+
sizes: ["32x32"],
24+
mimeType: "image/x-icon",
25+
src: "https://www.amazon.com/favicon.ico",
2826
},
2927
],
3028
packages: [
3129
{
32-
version: "velit occaecat",
30+
version: "1.0.0",
3331
environmentVariables: [
3432
{
35-
name: "nisi labore anim laborum",
36-
description: "occaecat nostrud ipsum sit non",
37-
choices: ["sunt reprehenderit"],
38-
default: "cillum",
39-
format: "reprehenderit Ut sit",
40-
},
41-
],
42-
packageArguments: [
43-
{
44-
name: "incididunt dolore aute",
45-
description: "reprehenderit veniam est labore",
46-
choices: ["dolor Lorem"],
47-
default: "veniam in elit",
48-
format: "aliqua aute",
49-
},
50-
],
51-
runtimeArguments: [
52-
{
53-
name: "pariatur laboris",
54-
description: "culpa elit do",
55-
choices: ["dolore laborum cupidatat velit sint"],
56-
default: "aliquip dolore nisi cupidatat",
57-
format: "ea",
33+
name: "AWS_ACCESS_KEY_ID",
34+
description: "AWS Access Key ID",
35+
format: "string",
5836
},
5937
],
6038
},
@@ -70,14 +48,14 @@ export default {
7048
_meta: {
7149
"io.modelcontextprotocol.registry/official": {
7250
isLatest: false,
73-
publishedAt: "1928-01-16T07:47:41.0Z",
74-
status: "Lorem",
51+
publishedAt: "2024-01-16T07:47:41.0Z",
52+
status: "active",
7553
},
7654
},
7755
},
7856
{
7957
server: {
80-
title: "nisi in consectetur ut dolore",
58+
title: "AgentQL MCP",
8159
name: "tinyfish/agentql-mcp",
8260
version: "1.0.1",
8361
description: "A powerful MCP server for building AI agents",
@@ -87,51 +65,10 @@ export default {
8765
url: "https://github.com/tinyfish/agentql-mcp",
8866
},
8967
_meta: {
90-
id58a: -54358865.657930315,
91-
qui2: -45037479,
92-
"io.modelcontextprotocol.registry/publisher-provided": {
93-
id949: {},
94-
},
68+
"io.modelcontextprotocol.registry/publisher-provided": {},
9569
},
96-
icons: [
97-
{
98-
sizes: ["irure"],
99-
mimeType: "nostrud",
100-
src: "http://qpklHhfRUakxqQziHQlJvkYBCQ.schO4z0B",
101-
},
102-
],
103-
packages: [
104-
{
105-
version: "anim aute",
106-
environmentVariables: [
107-
{
108-
name: "veniam",
109-
description: "dolore aliqua",
110-
choices: ["velit ex in et magna"],
111-
default: "Lorem quis cillum sit dolore",
112-
format: "sint sed",
113-
},
114-
],
115-
packageArguments: [
116-
{
117-
name: "id nostrud cupidatat exercitation",
118-
description: "ullamco tempor Excepteur fugiat et",
119-
choices: ["fugiat eu mollit"],
120-
default: "sint nostrud",
121-
format: "proident occaecat pariatur",
122-
},
123-
],
124-
runtimeArguments: [
125-
{
126-
name: "eiusmod",
127-
description: "anim Lorem",
128-
choices: ["culpa exercitation minim"],
129-
default: "labore cupidatat ea qui voluptate",
130-
format: "minim exercitation dolor",
131-
},
132-
],
133-
},
134-
],
70+
icons: [],
71+
packages: [],
13572
remotes: [
13673
{
13774
type: "http",
@@ -141,18 +78,16 @@ export default {
14178
],
14279
},
14380
_meta: {
144-
dolor_3e9: 35203589,
145-
consequat_a: 71612484,
14681
"io.modelcontextprotocol.registry/official": {
14782
isLatest: true,
148-
publishedAt: "1906-02-09T18:53:24.0Z",
149-
status: "aute",
83+
publishedAt: "2024-02-09T18:53:24.0Z",
84+
status: "active",
15085
},
15186
},
15287
},
15388
{
15489
server: {
155-
title: "id",
90+
title: "Astra DB MCP",
15691
name: "datastax/astra-db-mcp",
15792
version: "1.0.2",
15893
description: "Integrate AI assistants with Astra DB",
@@ -162,52 +97,10 @@ export default {
16297
url: "https://github.com/datastax/astra-db-mcp",
16398
},
16499
_meta: {
165-
laborum_c_4: 59098891.74366808,
166-
"io.modelcontextprotocol.registry/publisher-provided": {
167-
culpabcc: {},
168-
dolor0: {},
169-
consectetur_5: {},
170-
},
100+
"io.modelcontextprotocol.registry/publisher-provided": {},
171101
},
172-
icons: [
173-
{
174-
sizes: ["sint est dolor exercitation"],
175-
mimeType: "deserunt in ea",
176-
src: "https://tN.xun..YtDqhkkWdXBxzPIXssrZHM.O5d",
177-
},
178-
],
179-
packages: [
180-
{
181-
version: "exercitation culpa mollit",
182-
environmentVariables: [
183-
{
184-
name: "nostrud sint",
185-
description: "qui eiusmod",
186-
choices: ["in in ad elit anim"],
187-
default: "culpa sed fugiat laboris",
188-
format: "quis eiusmod",
189-
},
190-
],
191-
packageArguments: [
192-
{
193-
name: "ullamco in officia esse",
194-
description: "magna in qui eu adipisicing",
195-
choices: ["do quis"],
196-
default: "reprehenderit",
197-
format: "voluptate sint consequat cupidatat irure",
198-
},
199-
],
200-
runtimeArguments: [
201-
{
202-
name: "in exercitation",
203-
description: "occaecat",
204-
choices: ["enim"],
205-
default: "officia eu qui elit sed",
206-
format: "voluptate ipsum dolore ullamco",
207-
},
208-
],
209-
},
210-
],
102+
icons: [],
103+
packages: [],
211104
remotes: [
212105
{
213106
type: "http",
@@ -219,14 +112,14 @@ export default {
219112
_meta: {
220113
"io.modelcontextprotocol.registry/official": {
221114
isLatest: true,
222-
publishedAt: "1941-06-16T06:09:48.0Z",
223-
status: "magna aliqua consequat deserunt",
115+
publishedAt: "2024-06-16T06:09:48.0Z",
116+
status: "active",
224117
},
225118
},
226119
},
227120
{
228121
server: {
229-
title: "microsoft azure",
122+
title: "Microsoft Azure",
230123
name: "microsoft/azure-mcp",
231124
version: "1.0.0",
232125
description: "Connect AI assistants to Azure services",
@@ -256,7 +149,7 @@ export default {
256149
},
257150
{
258151
server: {
259-
title: "google workspace",
152+
title: "Google Workspace",
260153
name: "google/mcp-google-apps",
261154
version: "1.0.0",
262155
description:
@@ -287,7 +180,7 @@ export default {
287180
},
288181
{
289182
server: {
290-
title: "figma desktop",
183+
title: "Figma Desktop",
291184
name: "figma/mcp-desktop",
292185
version: "1.0.0",
293186
description:
@@ -318,7 +211,7 @@ export default {
318211
},
319212
{
320213
server: {
321-
title: "slack workspace",
214+
title: "Slack Workspace",
322215
name: "slack/mcp-slack",
323216
version: "1.0.0",
324217
description:
@@ -349,7 +242,7 @@ export default {
349242
},
350243
{
351244
server: {
352-
title: "github api",
245+
title: "GitHub API",
353246
name: "github/mcp-github",
354247
version: "1.0.0",
355248
description:
@@ -380,7 +273,7 @@ export default {
380273
},
381274
{
382275
server: {
383-
title: "stripe payments",
276+
title: "Stripe Payments",
384277
name: "stripe/mcp-stripe",
385278
version: "1.0.0",
386279
description: "Manage Stripe payments, subscriptions, and customer data",
@@ -410,7 +303,7 @@ export default {
410303
},
411304
{
412305
server: {
413-
title: "notion workspace",
306+
title: "Notion Workspace",
414307
name: "notion/mcp-notion",
415308
version: "1.0.0",
416309
description: "Access and manage Notion pages, databases, and content",
@@ -440,7 +333,7 @@ export default {
440333
},
441334
{
442335
server: {
443-
title: "salesforce crm",
336+
title: "Salesforce CRM",
444337
name: "salesforce/mcp-salesforce",
445338
version: "1.0.0",
446339
description:
@@ -471,7 +364,7 @@ export default {
471364
},
472365
{
473366
server: {
474-
title: "hubspot marketing",
367+
title: "HubSpot Marketing",
475368
name: "hubspot/mcp-hubspot",
476369
version: "1.0.0",
477370
description: "Integrate with HubSpot for marketing automation and CRM",
@@ -501,7 +394,7 @@ export default {
501394
},
502395
{
503396
server: {
504-
title: "linear project",
397+
title: "Linear Project",
505398
name: "linear/mcp-linear",
506399
version: "1.0.0",
507400
description: "Manage Linear issues, projects, and team workflows",
@@ -531,7 +424,7 @@ export default {
531424
},
532425
{
533426
server: {
534-
title: "trello boards",
427+
title: "Trello Boards",
535428
name: "trello/mcp-trello",
536429
version: "1.0.0",
537430
description: "Access and manage Trello boards, cards, and lists",
@@ -561,7 +454,7 @@ export default {
561454
},
562455
{
563456
server: {
564-
title: "jira management",
457+
title: "Jira Management",
565458
name: "atlassian/mcp-jira",
566459
version: "1.0.0",
567460
description:
@@ -590,4 +483,4 @@ export default {
590483
count: 15,
591484
nextCursor: "next-page",
592485
},
593-
};
486+
});

0 commit comments

Comments
 (0)