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 --- shared/extra-utils/index.ts | 2 -- shared/extra-utils/mock-servers/index.ts | 1 + .../mock-servers/mock-plugin-blocklist.ts | 37 ++++++++++++++++++++++ shared/extra-utils/plugins/mock-blocklist.ts | 37 ---------------------- 4 files changed, 38 insertions(+), 39 deletions(-) create mode 100644 shared/extra-utils/mock-servers/mock-plugin-blocklist.ts delete mode 100644 shared/extra-utils/plugins/mock-blocklist.ts (limited to 'shared') diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index bde269052..7ca079c78 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -7,8 +7,6 @@ export * from './miscs' export * from './mock-servers' export * from './moderation' -export * from './plugins/mock-blocklist' - export * from './requests/check-api-params' export * from './requests/requests' diff --git a/shared/extra-utils/mock-servers/index.ts b/shared/extra-utils/mock-servers/index.ts index 485757843..0ec07f685 100644 --- a/shared/extra-utils/mock-servers/index.ts +++ b/shared/extra-utils/mock-servers/index.ts @@ -1,3 +1,4 @@ export * from './mock-email' export * from './mock-instances-index' export * from './mock-joinpeertube-versions' +export * from './mock-plugin-blocklist' 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() + } +} diff --git a/shared/extra-utils/plugins/mock-blocklist.ts b/shared/extra-utils/plugins/mock-blocklist.ts deleted file mode 100644 index d18f8224f..000000000 --- a/shared/extra-utils/plugins/mock-blocklist.ts +++ /dev/null @@ -1,37 +0,0 @@ -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