]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - shared/server-commands/mock-servers/mock-plugin-blocklist.ts
Move typescript utils in its own directory
[github/Chocobozzz/PeerTube.git] / shared / server-commands / mock-servers / mock-plugin-blocklist.ts
1 import express, { Request, Response } from 'express'
2 import { Server } from 'http'
3 import { getPort, randomListen, terminateServer } from './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 async initialize () {
18 const app = express()
19
20 app.get('/blocklist', (req: Request, res: Response) => {
21 return res.json(this.body)
22 })
23
24 this.server = await randomListen(app)
25
26 return getPort(this.server)
27 }
28
29 replace (body: BlocklistResponse) {
30 this.body = body
31 }
32
33 terminate () {
34 return terminateServer(this.server)
35 }
36 }