]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/blocklist.ts
Better welcome modal
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / blocklist.ts
index c745ac975f04d4d1bc2bf2aded538d4e55ad10e6..0661676ce6091bb7d36250767f79e02184d31023 100644 (file)
@@ -3,18 +3,22 @@
 import 'mocha'
 
 import {
+  cleanupTests,
   createUser,
   doubleFollow,
   flushAndRunMultipleServers,
-  flushTests,
-  killallServers,
   makeDeleteRequest,
   makeGetRequest,
   makePostBodyRequest,
   ServerInfo,
-  setAccessTokensToServers, userLogin
-} from '../../utils'
-import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
+  setAccessTokensToServers,
+  userLogin
+} from '../../../../shared/extra-utils'
+import {
+  checkBadCountPagination,
+  checkBadSortPagination,
+  checkBadStartPagination
+} from '../../../../shared/extra-utils/requests/check-api-params'
 
 describe('Test blocklist API validators', function () {
   let servers: ServerInfo[]
@@ -24,15 +28,13 @@ describe('Test blocklist API validators', function () {
   before(async function () {
     this.timeout(60000)
 
-    await flushTests()
-
     servers = await flushAndRunMultipleServers(2)
     await setAccessTokensToServers(servers)
 
     server = servers[0]
 
     const user = { username: 'user1', password: 'password' }
-    await createUser(server.url, server.accessToken, user.username, user.password)
+    await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
 
     userAccessToken = await userLogin(server, user)
 
@@ -188,7 +190,7 @@ describe('Test blocklist API validators', function () {
             url: server.url,
             token: server.accessToken,
             path,
-            fields: { host: 'localhost:9001' },
+            fields: { host: 'localhost:' + server.port },
             statusCodeExpected: 409
           })
         })
@@ -198,7 +200,7 @@ describe('Test blocklist API validators', function () {
             url: server.url,
             token: server.accessToken,
             path,
-            fields: { host: 'localhost:9002' },
+            fields: { host: 'localhost:' + servers[1].port },
             statusCodeExpected: 204
           })
         })
@@ -208,7 +210,7 @@ describe('Test blocklist API validators', function () {
         it('Should fail with an unauthenticated user', async function () {
           await makeDeleteRequest({
             url: server.url,
-            path: path + '/localhost:9002',
+            path: path + '/localhost:' + servers[1].port,
             statusCodeExpected: 401
           })
         })
@@ -225,7 +227,7 @@ describe('Test blocklist API validators', function () {
         it('Should succeed with the correct params', async function () {
           await makeDeleteRequest({
             url: server.url,
-            path: path + '/localhost:9002',
+            path: path + '/localhost:' + servers[1].port,
             token: server.accessToken,
             statusCodeExpected: 204
           })
@@ -398,7 +400,7 @@ describe('Test blocklist API validators', function () {
           await makePostBodyRequest({
             url: server.url,
             path,
-            fields: { host: 'localhost:9002' },
+            fields: { host: 'localhost:' + servers[1].port },
             statusCodeExpected: 401
           })
         })
@@ -408,7 +410,7 @@ describe('Test blocklist API validators', function () {
             url: server.url,
             token: userAccessToken,
             path,
-            fields: { host: 'localhost:9002' },
+            fields: { host: 'localhost:' + servers[1].port },
             statusCodeExpected: 403
           })
         })
@@ -428,7 +430,7 @@ describe('Test blocklist API validators', function () {
             url: server.url,
             token: server.accessToken,
             path,
-            fields: { host: 'localhost:9001' },
+            fields: { host: 'localhost:' + server.port },
             statusCodeExpected: 409
           })
         })
@@ -438,7 +440,7 @@ describe('Test blocklist API validators', function () {
             url: server.url,
             token: server.accessToken,
             path,
-            fields: { host: 'localhost:9002' },
+            fields: { host: 'localhost:' + servers[1].port },
             statusCodeExpected: 204
           })
         })
@@ -448,7 +450,7 @@ describe('Test blocklist API validators', function () {
         it('Should fail with an unauthenticated user', async function () {
           await makeDeleteRequest({
             url: server.url,
-            path: path + '/localhost:9002',
+            path: path + '/localhost:' + servers[1].port,
             statusCodeExpected: 401
           })
         })
@@ -456,7 +458,7 @@ describe('Test blocklist API validators', function () {
         it('Should fail with a user without the appropriate rights', async function () {
           await makeDeleteRequest({
             url: server.url,
-            path: path + '/localhost:9002',
+            path: path + '/localhost:' + servers[1].port,
             token: userAccessToken,
             statusCodeExpected: 403
           })
@@ -474,7 +476,7 @@ describe('Test blocklist API validators', function () {
         it('Should succeed with the correct params', async function () {
           await makeDeleteRequest({
             url: server.url,
-            path: path + '/localhost:9002',
+            path: path + '/localhost:' + servers[1].port,
             token: server.accessToken,
             statusCodeExpected: 204
           })
@@ -484,11 +486,6 @@ describe('Test blocklist API validators', function () {
   })
 
   after(async function () {
-    killallServers(servers)
-
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
-    }
+    await cleanupTests(servers)
   })
 })