]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
Move typescript utils in its own directory
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / mock-servers / mock-plugin-blocklist.ts
CommitLineData
41fb13c3 1import express, { Request, Response } from 'express'
7820a54e 2import { Server } from 'http'
d1bfbdeb 3import { getPort, randomListen, terminateServer } from './utils'
8bff1fe0
C
4
5type BlocklistResponse = {
6 data: {
7 value: string
8 action?: 'add' | 'remove'
91b8e675 9 updatedAt?: string
8bff1fe0
C
10 }[]
11}
12
13export class MockBlocklist {
14 private body: BlocklistResponse
7820a54e 15 private server: Server
8bff1fe0 16
d1bfbdeb
C
17 async initialize () {
18 const app = express()
8bff1fe0 19
d1bfbdeb
C
20 app.get('/blocklist', (req: Request, res: Response) => {
21 return res.json(this.body)
8bff1fe0 22 })
d1bfbdeb
C
23
24 this.server = await randomListen(app)
25
26 return getPort(this.server)
8bff1fe0
C
27 }
28
29 replace (body: BlocklistResponse) {
30 this.body = body
31 }
7820a54e
C
32
33 terminate () {
70430c27 34 return terminateServer(this.server)
7820a54e 35 }
8bff1fe0 36}