From 480d6ea6791fe4100f1905af1e1e3a08173594ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 14:07:54 +0200 Subject: Move plugin blocklist mock --- .../mock-servers/mock-plugin-blocklist.ts | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 shared/extra-utils/mock-servers/mock-plugin-blocklist.ts (limited to 'shared/extra-utils/mock-servers/mock-plugin-blocklist.ts') diff --git a/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts b/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts new file mode 100644 index 000000000..d18f8224f --- /dev/null +++ b/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts @@ -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(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() + } +} -- cgit v1.2.3