2020-05-07 10:32:54 -04:00
|
|
|
import * as express from 'express'
|
2020-06-26 08:50:40 -04:00
|
|
|
import { Server } from 'http'
|
2020-05-07 10:32:54 -04:00
|
|
|
|
|
|
|
type BlocklistResponse = {
|
|
|
|
data: {
|
|
|
|
value: string
|
|
|
|
action?: 'add' | 'remove'
|
2020-05-07 11:08:16 -04:00
|
|
|
updatedAt?: string
|
2020-05-07 10:32:54 -04:00
|
|
|
}[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export class MockBlocklist {
|
|
|
|
private body: BlocklistResponse
|
2020-06-26 08:50:40 -04:00
|
|
|
private server: Server
|
2020-05-07 10:32:54 -04:00
|
|
|
|
|
|
|
initialize () {
|
|
|
|
return new Promise(res => {
|
|
|
|
const app = express()
|
|
|
|
|
|
|
|
app.get('/blocklist', (req: express.Request, res: express.Response) => {
|
|
|
|
return res.json(this.body)
|
|
|
|
})
|
|
|
|
|
2020-06-26 08:50:40 -04:00
|
|
|
this.server = app.listen(42100, () => res())
|
2020-05-07 10:32:54 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
replace (body: BlocklistResponse) {
|
|
|
|
this.body = body
|
|
|
|
}
|
2020-06-26 08:50:40 -04:00
|
|
|
|
|
|
|
terminate () {
|
|
|
|
if (this.server) this.server.close()
|
|
|
|
}
|
2020-05-07 10:32:54 -04:00
|
|
|
}
|