-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathserver.ts
More file actions
67 lines (62 loc) · 1.69 KB
/
server.ts
File metadata and controls
67 lines (62 loc) · 1.69 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
import {
DefaultBodyType,
PathParams,
ResponseComposition,
rest,
RestContext,
RestRequest
} from 'msw';
import { setupServer } from 'msw/node';
import { testAddress, testNetwork } from './accountConfig';
import {
account,
blocks,
dappConfig,
economics,
networkConfig,
socketResponse,
websocketConfig
} from './data';
import { testToken } from './data/testToken';
import { wrapEgldContract } from './data/wrapEgldContract';
export const mockResponse =
<T extends DefaultBodyType>(body: T) =>
(
_req: RestRequest<never, PathParams<string>>,
res: ResponseComposition<DefaultBodyType>,
ctx: RestContext
) => {
return res(ctx.status(200), ctx.json(body));
};
const handlers = [
rest.get(`${testNetwork.apiAddress}/dapp/config`, mockResponse(dappConfig)),
rest.get(
`${testNetwork.apiAddress}/network/config`,
mockResponse(networkConfig)
),
rest.get(
`https://${websocketConfig.url}/socket.io/`,
mockResponse(socketResponse)
),
rest.get(
`${testNetwork.apiAddress}/websocket/config`,
mockResponse(websocketConfig)
),
rest.get(`${testNetwork.apiAddress}/economics`, mockResponse(economics)),
rest.get(
`${testNetwork.apiAddress}/accounts/${testAddress}`,
mockResponse(account)
),
rest.get(
`${testNetwork.apiAddress}/tokens/${testToken.identifier}`,
mockResponse(testToken)
),
rest.get(
`${testNetwork.apiAddress}/accounts/${wrapEgldContract.address}`,
mockResponse(wrapEgldContract)
),
rest.get(`${testNetwork.apiAddress}/blocks`, mockResponse(blocks))
];
// This configures a request mocking server with the given request handlers.
const server = setupServer(...handlers);
export { server, rest };