Skip to content

Commit cd09111

Browse files
Update
1 parent df6512a commit cd09111

File tree

1 file changed

+57
-41
lines changed

1 file changed

+57
-41
lines changed

__tests__/mocks/handlers.ts

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import { PathParams, rest, RestRequest } from 'msw';
1+
import { readFileSync } from 'node:fs';
22
import { resolve } from 'path';
3-
import { readFileSync } from 'fs';
3+
import { PathParams, RestRequest, rest } from 'msw';
4+
45
import { MsgSetMswInterceptedDataFromApi } from '../../bin/frameworks/messages/messages';
6+
57
import mockFigmaFiles from './responses/mockFigmaFiles.json';
68
import mockFigmaFilesVersions from './responses/mockFigmaFilesVersions.json';
79
import mockFigmaImages from './responses/mockFigmaImages.json';
810

911
const FIGMA_API = 'https://api.figma.com/v1';
10-
const FIGMA_BUCKET_URL = 'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img';
12+
const FIGMA_BUCKET_URL =
13+
'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img';
1114

1215
const logInterceptedRequest = (req: RestRequest<any, PathParams>) =>
1316
console.log(MsgSetMswInterceptedDataFromApi(req.url.href));
@@ -21,8 +24,8 @@ export const handlers = [
2124
ctx.status(403),
2225
ctx.json({
2326
status: 403,
24-
err: 'Not allowed'
25-
})
27+
err: 'Not allowed',
28+
}),
2629
);
2730
}
2831

@@ -36,71 +39,84 @@ export const handlers = [
3639
logInterceptedRequest(req);
3740
return res(ctx.status(200), ctx.json(mockFigmaImages));
3841
}),
39-
rest.get(`${FIGMA_BUCKET_URL}/2f0d/1106/be444c1f7c5a79484c415e50e9010847`, (req, res, ctx) => {
40-
logInterceptedRequest(req);
41-
return res(
42-
ctx.status(200),
43-
ctx.text(
44-
`<svg width="55" height="56" viewBox="0 0 55 56" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.11131 28.0662L17.0333 51.499L52.1723 1.43805" stroke="#219653" stroke-width="5"/></svg>`
45-
)
46-
);
47-
}),
48-
rest.get(`${FIGMA_BUCKET_URL}/8ba5/2322/bac5a41a1a59a9a76a12bbe21e0cd781`, (req, res, ctx) => {
49-
logInterceptedRequest(req);
50-
return res(
51-
ctx.status(200),
52-
ctx.text(
53-
`<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="16" cy="25" r="3" fill="black"/><circle cx="25" cy="25" r="3" fill="black"/><circle cx="34" cy="25" r="3" fill="black"/><circle cx="25" cy="25" r="23.5" stroke="#333333" stroke-width="3"/></svg>`
54-
)
55-
);
56-
}),
57-
rest.get(`${FIGMA_BUCKET_URL}/3e15/3c93/1e96386d904b25bf987abc4b87c62ee1`, (req, res, ctx) => {
58-
logInterceptedRequest(req);
59-
return res(
60-
ctx.status(200),
61-
ctx.text(
62-
`<svg width="54" height="54" viewBox="0 0 54 54" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.78311 1.7831L52.2169 52.2169M1.78311 52.2169L52.2169 1.7831" stroke="black" stroke-width="5"/></svg>`
63-
)
64-
);
65-
}),
42+
rest.get(
43+
`${FIGMA_BUCKET_URL}/2f0d/1106/be444c1f7c5a79484c415e50e9010847`,
44+
(req, res, ctx) => {
45+
logInterceptedRequest(req);
46+
return res(
47+
ctx.status(200),
48+
ctx.text(
49+
`<svg width="55" height="56" viewBox="0 0 55 56" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M2.11131 28.0662L17.0333 51.499L52.1723 1.43805" stroke="#219653" stroke-width="5"/></svg>`,
50+
),
51+
);
52+
},
53+
),
54+
rest.get(
55+
`${FIGMA_BUCKET_URL}/8ba5/2322/bac5a41a1a59a9a76a12bbe21e0cd781`,
56+
(req, res, ctx) => {
57+
logInterceptedRequest(req);
58+
return res(
59+
ctx.status(200),
60+
ctx.text(
61+
`<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="16" cy="25" r="3" fill="black"/><circle cx="25" cy="25" r="3" fill="black"/><circle cx="34" cy="25" r="3" fill="black"/><circle cx="25" cy="25" r="23.5" stroke="#333333" stroke-width="3"/></svg>`,
62+
),
63+
);
64+
},
65+
),
66+
rest.get(
67+
`${FIGMA_BUCKET_URL}/3e15/3c93/1e96386d904b25bf987abc4b87c62ee1`,
68+
(req, res, ctx) => {
69+
logInterceptedRequest(req);
70+
return res(
71+
ctx.status(200),
72+
ctx.text(
73+
`<svg width="54" height="54" viewBox="0 0 54 54" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1.78311 1.7831L52.2169 52.2169M1.78311 52.2169L52.2169 1.7831" stroke="black" stroke-width="5"/></svg>`,
74+
),
75+
);
76+
},
77+
),
6678
rest.get(
6779
'https://localhost/v1/files/lkhjtkl34kljf-fg3kj3443.hjt3hjk.net/.kj34jkl34',
6880
(req, res) => {
6981
logInterceptedRequest(req);
7082
return res.networkError('Connection Refused');
71-
}
83+
},
7284
),
7385
rest.get(
7486
'https://s3-us-west-2.amazonaws.com/figma-alpha-api/img/0882/9cc7/c4731c8d0df07592cd6f7dc0519bb3bb-asdf',
7587
(req, res, ctx) => {
7688
logInterceptedRequest(req);
7789
return res(ctx.status(403));
78-
}
90+
},
7991
),
8092
rest.get(
8193
'https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png',
8294
(req, res, ctx) => {
8395
logInterceptedRequest(req);
8496

85-
const imageBuffer = readFileSync(resolve(__dirname, './files/googlelogo_color_272x92dp.png'));
97+
const imageBuffer = readFileSync(
98+
resolve(__dirname, './files/googlelogo_color_272x92dp.png'),
99+
);
86100
return res(
87101
ctx.set('Content-Length', imageBuffer.byteLength.toString()),
88102
ctx.set('Content-Type', 'image/jpeg'),
89-
ctx.body(imageBuffer)
103+
ctx.body(imageBuffer),
90104
);
91-
}
105+
},
92106
),
93107
rest.get(
94108
'https://upload.wikimedia.org/wikipedia/commons/5/53/Google_%22G%22_Logo.svg',
95109
(req, res, ctx) => {
96110
logInterceptedRequest(req);
97111

98-
const imageBuffer = readFileSync(resolve(__dirname, './files/Google__G__Logo.svg'));
112+
const imageBuffer = readFileSync(
113+
resolve(__dirname, './files/Google__G__Logo.svg'),
114+
);
99115
return res(
100116
ctx.set('Content-Length', imageBuffer.byteLength.toString()),
101117
ctx.set('Content-Type', 'image/jpeg'),
102-
ctx.body(imageBuffer)
118+
ctx.body(imageBuffer),
103119
);
104-
}
105-
)
120+
},
121+
),
106122
];

0 commit comments

Comments
 (0)