mirror of https://github.com/Chocobozzz/PeerTube
39 lines
813 B
TypeScript
39 lines
813 B
TypeScript
import express, { Request, Response } from 'express'
|
|
import { Server } from 'http'
|
|
import { randomInt } from '@shared/core-utils'
|
|
import { terminateServer } from './utils'
|
|
|
|
type BlocklistResponse = {
|
|
data: {
|
|
value: string
|
|
action?: 'add' | 'remove'
|
|
updatedAt?: string
|
|
}[]
|
|
}
|
|
|
|
export class MockBlocklist {
|
|
private body: BlocklistResponse
|
|
private server: Server
|
|
|
|
initialize () {
|
|
return new Promise<number>(res => {
|
|
const app = express()
|
|
|
|
app.get('/blocklist', (req: Request, res: Response) => {
|
|
return res.json(this.body)
|
|
})
|
|
|
|
const port = 45000 + randomInt(1, 1000)
|
|
this.server = app.listen(port, () => res(port))
|
|
})
|
|
}
|
|
|
|
replace (body: BlocklistResponse) {
|
|
this.body = body
|
|
}
|
|
|
|
terminate () {
|
|
return terminateServer(this.server)
|
|
}
|
|
}
|