PeerTube/server/tests/shared/mock-servers/mock-plugin-blocklist.ts

37 lines
716 B
TypeScript
Raw Normal View History

2021-08-27 07:32:44 -05:00
import express, { Request, Response } from 'express'
import { Server } from 'http'
import { getPort, randomListen, terminateServer } from './shared'
2020-05-07 09:32:54 -05:00
type BlocklistResponse = {
data: {
value: string
action?: 'add' | 'remove'
2020-05-07 10:08:16 -05:00
updatedAt?: string
2020-05-07 09:32:54 -05:00
}[]
}
export class MockBlocklist {
private body: BlocklistResponse
private server: Server
2020-05-07 09:32:54 -05:00
2021-10-22 07:31:38 -05:00
async initialize () {
const app = express()
2020-05-07 09:32:54 -05:00
2021-10-22 07:31:38 -05:00
app.get('/blocklist', (req: Request, res: Response) => {
return res.json(this.body)
2020-05-07 09:32:54 -05:00
})
2021-10-22 07:31:38 -05:00
this.server = await randomListen(app)
return getPort(this.server)
2020-05-07 09:32:54 -05:00
}
replace (body: BlocklistResponse) {
this.body = body
}
terminate () {
2021-09-06 01:13:11 -05:00
return terminateServer(this.server)
}
2020-05-07 09:32:54 -05:00
}