]>
Commit | Line | Data |
---|---|---|
8bff1fe0 | 1 | import * as express from 'express' |
7820a54e | 2 | import { Server } from 'http' |
8bff1fe0 C |
3 | |
4 | type BlocklistResponse = { | |
5 | data: { | |
6 | value: string | |
7 | action?: 'add' | 'remove' | |
91b8e675 | 8 | updatedAt?: string |
8bff1fe0 C |
9 | }[] |
10 | } | |
11 | ||
12 | export class MockBlocklist { | |
13 | private body: BlocklistResponse | |
7820a54e | 14 | private server: Server |
8bff1fe0 C |
15 | |
16 | initialize () { | |
17 | return new Promise(res => { | |
18 | const app = express() | |
19 | ||
20 | app.get('/blocklist', (req: express.Request, res: express.Response) => { | |
21 | return res.json(this.body) | |
22 | }) | |
23 | ||
7820a54e | 24 | this.server = app.listen(42100, () => res()) |
8bff1fe0 C |
25 | }) |
26 | } | |
27 | ||
28 | replace (body: BlocklistResponse) { | |
29 | this.body = body | |
30 | } | |
7820a54e C |
31 | |
32 | terminate () { | |
33 | if (this.server) this.server.close() | |
34 | } | |
8bff1fe0 | 35 | } |