]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/extra-utils/plugins/mock-blocklist.ts
Introduce bulk command
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / plugins / mock-blocklist.ts
1 import * as express from 'express'
2 import { Server } from 'http'
3 import { randomInt } from '@shared/core-utils'
4
5 type BlocklistResponse = {
6 data: {
7 value: string
8 action?: 'add' | 'remove'
9 updatedAt?: string
10 }[]
11 }
12
13 export class MockBlocklist {
14 private body: BlocklistResponse
15 private server: Server
16
17 initialize () {
18 return new Promise<number>(res => {
19 const app = express()
20
21 app.get('/blocklist', (req: express.Request, res: express.Response) => {
22 return res.json(this.body)
23 })
24
25 const port = 42201 + randomInt(1, 100)
26 this.server = app.listen(port, () => res(port))
27 })
28 }
29
30 replace (body: BlocklistResponse) {
31 this.body = body
32 }
33
34 terminate () {
35 if (this.server) this.server.close()
36 }
37 }