]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/redundancy.ts
Fix CI using 127.0.0.1 for tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / redundancy.ts
index b2370a094f826a4f60a41cc0605427da7e107820..908407b9a5a898a1e5ce823072373f467037eb29 100644 (file)
@@ -1,34 +1,32 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-
+import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
+import { HttpStatusCode, VideoCreateResult } from '@shared/models'
 import {
-  checkBadCountPagination,
-  checkBadSortPagination,
-  checkBadStartPagination,
   cleanupTests,
-  createUser,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers, makeDeleteRequest,
-  makeGetRequest, makePostBodyRequest,
+  makeDeleteRequest,
+  makeGetRequest,
+  makePostBodyRequest,
   makePutBodyRequest,
-  ServerInfo,
-  setAccessTokensToServers, uploadVideoAndGetId,
-  userLogin, waitJobs
-} from '../../../../shared/extra-utils'
+  PeerTubeServer,
+  setAccessTokensToServers,
+  waitJobs
+} from '@shared/server-commands'
 
 describe('Test server redundancy API validators', function () {
-  let servers: ServerInfo[]
+  let servers: PeerTubeServer[]
   let userAccessToken = null
   let videoIdLocal: number
-  let videoIdRemote: number
+  let videoRemote: VideoCreateResult
 
   // ---------------------------------------------------------------
 
   before(async function () {
-    this.timeout(30000)
+    this.timeout(80000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
 
     await setAccessTokensToServers(servers)
     await doubleFollow(servers[0], servers[1])
@@ -38,13 +36,16 @@ describe('Test server redundancy API validators', function () {
       password: 'password'
     }
 
-    await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password })
-    userAccessToken = await userLogin(servers[0], user)
+    await servers[0].users.create({ username: user.username, password: user.password })
+    userAccessToken = await servers[0].login.getAccessToken(user)
+
+    videoIdLocal = (await servers[0].videos.quickUpload({ name: 'video' })).id
 
-    videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id
-    videoIdRemote = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).id
+    const remoteUUID = (await servers[1].videos.quickUpload({ name: 'video' })).uuid
 
     await waitJobs(servers)
+
+    videoRemote = await servers[0].videos.get({ id: remoteUUID })
   })
 
   describe('When listing redundancies', function () {
@@ -59,11 +60,11 @@ describe('Test server redundancy API validators', function () {
     })
 
     it('Should fail with an invalid token', async function () {
-      await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 })
+      await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
     })
 
     it('Should fail if the user is not an administrator', async function () {
-      await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 })
+      await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
     })
 
     it('Should fail with a bad start pagination', async function () {
@@ -87,7 +88,7 @@ describe('Test server redundancy API validators', function () {
     })
 
     it('Should succeed with the correct params', async function () {
-      await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: 200 })
+      await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 })
     })
   })
 
@@ -103,11 +104,11 @@ describe('Test server redundancy API validators', function () {
     })
 
     it('Should fail with an invalid token', async function () {
-      await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 })
+      await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
     })
 
     it('Should fail if the user is not an administrator', async function () {
-      await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 })
+      await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
     })
 
     it('Should fail without a video id', async function () {
@@ -119,7 +120,7 @@ describe('Test server redundancy API validators', function () {
     })
 
     it('Should fail with a not found video id', async function () {
-      await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: 404 })
+      await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
     })
 
     it('Should fail with a local a video id', async function () {
@@ -127,7 +128,13 @@ describe('Test server redundancy API validators', function () {
     })
 
     it('Should succeed with the correct params', async function () {
-      await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 204 })
+      await makePostBodyRequest({
+        url,
+        path,
+        token,
+        fields: { videoId: videoRemote.shortUUID },
+        expectedStatus: HttpStatusCode.NO_CONTENT_204
+      })
     })
 
     it('Should fail if the video is already duplicated', async function () {
@@ -135,7 +142,13 @@ describe('Test server redundancy API validators', function () {
 
       await waitJobs(servers)
 
-      await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 409 })
+      await makePostBodyRequest({
+        url,
+        path,
+        token,
+        fields: { videoId: videoRemote.uuid },
+        expectedStatus: HttpStatusCode.CONFLICT_409
+      })
     })
   })
 
@@ -151,11 +164,11 @@ describe('Test server redundancy API validators', function () {
     })
 
     it('Should fail with an invalid token', async function () {
-      await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: 401 })
+      await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
     })
 
     it('Should fail if the user is not an administrator', async function () {
-      await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: 403 })
+      await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
     })
 
     it('Should fail with an incorrect video id', async function () {
@@ -163,7 +176,7 @@ describe('Test server redundancy API validators', function () {
     })
 
     it('Should fail with a not found video redundancy', async function () {
-      await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: 404 })
+      await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
     })
   })
 
@@ -173,20 +186,20 @@ describe('Test server redundancy API validators', function () {
     it('Should fail with an invalid token', async function () {
       await makePutBodyRequest({
         url: servers[0].url,
-        path: path + '/localhost:' + servers[1].port,
+        path: path + '/' + servers[1].host,
         fields: { redundancyAllowed: true },
         token: 'fake_token',
-        statusCodeExpected: 401
+        expectedStatus: HttpStatusCode.UNAUTHORIZED_401
       })
     })
 
     it('Should fail if the user is not an administrator', async function () {
       await makePutBodyRequest({
         url: servers[0].url,
-        path: path + '/localhost:' + servers[1].port,
+        path: path + '/' + servers[1].host,
         fields: { redundancyAllowed: true },
         token: userAccessToken,
-        statusCodeExpected: 403
+        expectedStatus: HttpStatusCode.FORBIDDEN_403
       })
     })
 
@@ -196,27 +209,27 @@ describe('Test server redundancy API validators', function () {
         path: path + '/example.com',
         fields: { redundancyAllowed: true },
         token: servers[0].accessToken,
-        statusCodeExpected: 404
+        expectedStatus: HttpStatusCode.NOT_FOUND_404
       })
     })
 
     it('Should fail without de redundancyAllowed param', async function () {
       await makePutBodyRequest({
         url: servers[0].url,
-        path: path + '/localhost:' + servers[1].port,
+        path: path + '/' + servers[1].host,
         fields: { blabla: true },
         token: servers[0].accessToken,
-        statusCodeExpected: 400
+        expectedStatus: HttpStatusCode.BAD_REQUEST_400
       })
     })
 
     it('Should succeed with the correct parameters', async function () {
       await makePutBodyRequest({
         url: servers[0].url,
-        path: path + '/localhost:' + servers[1].port,
+        path: path + '/' + servers[1].host,
         fields: { redundancyAllowed: true },
         token: servers[0].accessToken,
-        statusCodeExpected: 204
+        expectedStatus: HttpStatusCode.NO_CONTENT_204
       })
     })
   })