]>
Commit | Line | Data |
---|---|---|
41fb13c3 | 1 | import express, { Request, Response } from 'express' |
7820a54e | 2 | import { Server } from 'http' |
63da15eb | 3 | import { randomInt } from '@shared/core-utils' |
70430c27 | 4 | import { terminateServer } from './utils' |
8bff1fe0 C |
5 | |
6 | type BlocklistResponse = { | |
7 | data: { | |
8 | value: string | |
9 | action?: 'add' | 'remove' | |
91b8e675 | 10 | updatedAt?: string |
8bff1fe0 C |
11 | }[] |
12 | } | |
13 | ||
14 | export class MockBlocklist { | |
15 | private body: BlocklistResponse | |
7820a54e | 16 | private server: Server |
8bff1fe0 C |
17 | |
18 | initialize () { | |
63da15eb | 19 | return new Promise<number>(res => { |
8bff1fe0 C |
20 | const app = express() |
21 | ||
41fb13c3 | 22 | app.get('/blocklist', (req: Request, res: Response) => { |
8bff1fe0 C |
23 | return res.json(this.body) |
24 | }) | |
25 | ||
63da15eb C |
26 | const port = 42201 + randomInt(1, 100) |
27 | this.server = app.listen(port, () => res(port)) | |
8bff1fe0 C |
28 | }) |
29 | } | |
30 | ||
31 | replace (body: BlocklistResponse) { | |
32 | this.body = body | |
33 | } | |
7820a54e C |
34 | |
35 | terminate () { | |
70430c27 | 36 | return terminateServer(this.server) |
7820a54e | 37 | } |
8bff1fe0 | 38 | } |