]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/plugins/mock-blocklist.ts
Close mock blocklit server when tests end
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / plugins / mock-blocklist.ts
1 import * as express from 'express'
2 import { Server } from 'http'
3
4 type BlocklistResponse = {
5 data: {
6 value: string
7 action?: 'add' | 'remove'
8 updatedAt?: string
9 }[]
10 }
11
12 export class MockBlocklist {
13 private body: BlocklistResponse
14 private server: Server
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
24 this.server = app.listen(42100, () => res())
25 })
26 }
27
28 replace (body: BlocklistResponse) {
29 this.body = body
30 }
31
32 terminate () {
33 if (this.server) this.server.close()
34 }
35 }