-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupTests.ts
83 lines (74 loc) · 2.64 KB
/
setupTests.ts
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
/* istanbul disable file */
import { afterAll, afterEach, beforeAll } from 'vitest';
import { setupServer } from 'msw/node';
import { HttpResponse, http, RequestHandler } from 'msw';
import { initializeAPIClient } from './src/base.js';
import {
status,
success,
districts,
pointCategories,
honors,
studentRankings,
schoolRankings,
ballot,
ballotResults,
campus,
citation,
citationCategory,
vote,
} from './testData.js';
const url = 'http://localhost:10010/v2';
initializeAPIClient({ API_URL: url, RETRY_DELAY: 10 });
export const handlers: RequestHandler[] = [
http.get(`${url}/status`, () => HttpResponse.json(status)),
http.get(`${url}/districts`, () => HttpResponse.json(districts)),
http.get(`${url}/points/categories`, () =>
HttpResponse.json(pointCategories),
),
http.get(`${url}/rankings/student`, () =>
HttpResponse.json(studentRankings),
),
http.get(`${url}/rankings/school`, () => HttpResponse.json(schoolRankings)),
http.get(`${url}/honors`, () => HttpResponse.json(honors)),
http.get(`${url}/ballots`, () => HttpResponse.json([ballot])),
http.post(`${url}/ballots`, () => HttpResponse.json(success)),
http.get(`${url}/ballots/:ballotId`, () => HttpResponse.json(ballot)),
http.put(`${url}/ballots/:ballotId`, () => HttpResponse.json(success)),
http.get(`${url}/ballots/:ballotId/results`, () =>
HttpResponse.json(ballotResults),
),
http.get(`${url}/ballots/:ballotId/votes`, () => HttpResponse.json([vote])),
http.post(`${url}/ballots/:ballotId/votes`, () =>
HttpResponse.json(success),
),
http.get(`${url}/campus`, () => HttpResponse.json(campus)),
http.post(`${url}/certs/membership`, () => HttpResponse.text('Success')),
http.get(`${url}/citations`, () => HttpResponse.json([citation])),
http.post(`${url}/members/:memberId/citations`, () =>
HttpResponse.json(success),
),
http.put(`${url}/citations`, () => HttpResponse.json(success)),
http.patch(`${url}/citations/:citationId`, () =>
HttpResponse.json(success),
),
http.delete(`${url}/members/:memberId/citations/:citationId`, () =>
HttpResponse.json(success),
),
http.get(`${url}/citations/categories`, () =>
HttpResponse.json([citationCategory]),
),
];
export const server = setupServer(...handlers);
// Start server before all tests
beforeAll(() => {
server.listen({ onUnhandledRequest: 'error' });
});
// Close server after all tests
afterAll(() => {
server.close();
});
// Reset handlers after each test `important for test isolation`
afterEach(() => {
server.resetHandlers();
});