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