diff options
Diffstat (limited to 'shared/extra-utils/mock-servers')
-rw-r--r-- | shared/extra-utils/mock-servers/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/mock-servers/mock-plugin-blocklist.ts | 37 |
2 files changed, 38 insertions, 0 deletions
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 @@ | |||
1 | export * from './mock-email' | 1 | export * from './mock-email' |
2 | export * from './mock-instances-index' | 2 | export * from './mock-instances-index' |
3 | export * from './mock-joinpeertube-versions' | 3 | export * from './mock-joinpeertube-versions' |
4 | 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 @@ | |||
1 | import * as express from 'express' | ||
2 | import { Server } from 'http' | ||
3 | import { randomInt } from '@shared/core-utils' | ||
4 | |||
5 | type BlocklistResponse = { | ||
6 | data: { | ||
7 | value: string | ||
8 | action?: 'add' | 'remove' | ||
9 | updatedAt?: string | ||
10 | }[] | ||
11 | } | ||
12 | |||
13 | export class MockBlocklist { | ||
14 | private body: BlocklistResponse | ||
15 | private server: Server | ||
16 | |||
17 | initialize () { | ||
18 | return new Promise<number>(res => { | ||
19 | const app = express() | ||
20 | |||
21 | app.get('/blocklist', (req: express.Request, res: express.Response) => { | ||
22 | return res.json(this.body) | ||
23 | }) | ||
24 | |||
25 | const port = 42201 + randomInt(1, 100) | ||
26 | this.server = app.listen(port, () => res(port)) | ||
27 | }) | ||
28 | } | ||
29 | |||
30 | replace (body: BlocklistResponse) { | ||
31 | this.body = body | ||
32 | } | ||
33 | |||
34 | terminate () { | ||
35 | if (this.server) this.server.close() | ||
36 | } | ||
37 | } | ||