PeerTube/shared/extra-utils/plugins/mock-blocklist.ts

36 lines
666 B
TypeScript
Raw Normal View History

2020-05-07 09:32:54 -05:00
import * as express from 'express'
import { Server } from 'http'
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
initialize () {
return new Promise(res => {
const app = express()
app.get('/blocklist', (req: express.Request, res: express.Response) => {
return res.json(this.body)
})
this.server = app.listen(42100, () => res())
2020-05-07 09:32:54 -05:00
})
}
replace (body: BlocklistResponse) {
this.body = body
}
terminate () {
if (this.server) this.server.close()
}
2020-05-07 09:32:54 -05:00
}