]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/plugins/mock-blocklist.ts
Hide schedule privacy if private does not exist
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / plugins / mock-blocklist.ts
index 6fe3dee9f7341e1fedcb74d767c5a68f0bc59e40..d18f8224ff6382a9ce113e350ebf59b141a53eff 100644 (file)
@@ -1,4 +1,6 @@
 import * as express from 'express'
+import { Server } from 'http'
+import { randomInt } from '@shared/core-utils'
 
 type BlocklistResponse = {
   data: {
@@ -10,20 +12,26 @@ type BlocklistResponse = {
 
 export class MockBlocklist {
   private body: BlocklistResponse
+  private server: Server
 
   initialize () {
-    return new Promise(res => {
+    return new Promise<number>(res => {
       const app = express()
 
       app.get('/blocklist', (req: express.Request, res: express.Response) => {
         return res.json(this.body)
       })
 
-      app.listen(42100, () => res())
+      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()
+  }
 }