1
0
Fork 0

Move plugin blocklist mock

This commit is contained in:
Chocobozzz 2021-07-06 14:07:54 +02:00
parent 0c1a77e9cc
commit 480d6ea679
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 1 additions and 2 deletions

View file

@ -1,3 +1,4 @@
export * from './mock-email'
export * from './mock-instances-index'
export * from './mock-joinpeertube-versions'
export * from './mock-plugin-blocklist'

View file

@ -0,0 +1,37 @@
import * as express from 'express'
import { Server } from 'http'
import { randomInt } from '@shared/core-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: express.Request, res: express.Response) => {
return res.json(this.body)
})
const port = 42201 + randomInt(1, 100)
this.server = app.listen(port, () => res(port))
})
}
replace (body: BlocklistResponse) {
this.body = body
}
terminate () {
if (this.server) this.server.close()
}
}