Move plugin blocklist mock
This commit is contained in:
parent
0c1a77e9cc
commit
480d6ea679
3 changed files with 1 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
export * from './mock-email'
|
||||
export * from './mock-instances-index'
|
||||
export * from './mock-joinpeertube-versions'
|
||||
export * from './mock-plugin-blocklist'
|
||||
|
|
37
shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
Normal file
37
shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
Normal 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()
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue