1
0
Fork 0
peertube/server/tests/shared/mock-servers/mock-plugin-blocklist.ts
2021-12-17 12:24:03 +01:00

36 lines
716 B
TypeScript

import express, { Request, Response } from 'express'
import { Server } from 'http'
import { getPort, randomListen, terminateServer } from './shared'
type BlocklistResponse = {
data: {
value: string
action?: 'add' | 'remove'
updatedAt?: string
}[]
}
export class MockBlocklist {
private body: BlocklistResponse
private server: Server
async initialize () {
const app = express()
app.get('/blocklist', (req: Request, res: Response) => {
return res.json(this.body)
})
this.server = await randomListen(app)
return getPort(this.server)
}
replace (body: BlocklistResponse) {
this.body = body
}
terminate () {
return terminateServer(this.server)
}
}