aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /shared/extra-utils/mock-servers/mock-plugin-blocklist.ts
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'shared/extra-utils/mock-servers/mock-plugin-blocklist.ts')
-rw-r--r--shared/extra-utils/mock-servers/mock-plugin-blocklist.ts37
1 files changed, 37 insertions, 0 deletions
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 @@
1import * as express from 'express'
2import { Server } from 'http'
3import { randomInt } from '@shared/core-utils'
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 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}