aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared/mock-servers/mock-plugin-blocklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/shared/mock-servers/mock-plugin-blocklist.ts')
-rw-r--r--server/tests/shared/mock-servers/mock-plugin-blocklist.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/server/tests/shared/mock-servers/mock-plugin-blocklist.ts b/server/tests/shared/mock-servers/mock-plugin-blocklist.ts
new file mode 100644
index 000000000..5d6e01816
--- /dev/null
+++ b/server/tests/shared/mock-servers/mock-plugin-blocklist.ts
@@ -0,0 +1,36 @@
1import express, { Request, Response } from 'express'
2import { Server } from 'http'
3import { getPort, randomListen, terminateServer } from './shared'
4
5type BlocklistResponse = {
6 data: {
7 value: string
8 action?: 'add' | 'remove'
9 updatedAt?: string
10 }[]
11}
12
13export class MockBlocklist {
14 private body: BlocklistResponse
15 private server: Server
16
17 async initialize () {
18 const app = express()
19
20 app.get('/blocklist', (req: Request, res: Response) => {
21 return res.json(this.body)
22 })
23
24 this.server = await randomListen(app)
25
26 return getPort(this.server)
27 }
28
29 replace (body: BlocklistResponse) {
30 this.body = body
31 }
32
33 terminate () {
34 return terminateServer(this.server)
35 }
36}