]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/abuses.ts
Add playback metric endpoint sent to OTEL
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / abuses.ts
index 4cd10a6fd323a14d6ef7e66b23a8b307e8ce1434..7d8347412b077bef8cbb4c184742a630a7f270a3 100644 (file)
@@ -1,29 +1,24 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
-import { HttpStatusCode } from '@shared/core-utils'
+import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
+import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models'
 import {
   AbusesCommand,
-  checkBadCountPagination,
-  checkBadSortPagination,
-  checkBadStartPagination,
   cleanupTests,
+  createSingleServer,
   doubleFollow,
-  flushAndRunServer,
-  getVideoIdFromUUID,
   makeGetRequest,
   makePostBodyRequest,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
-  uploadVideo,
   waitJobs
-} from '@shared/extra-utils'
-import { AbuseCreate, AbuseState } from '@shared/models'
+} from '@shared/server-commands'
 
 describe('Test abuses API validators', function () {
   const basePath = '/api/v1/abuses/'
 
-  let server: ServerInfo
+  let server: PeerTubeServer
 
   let userToken = ''
   let userToken2 = ''
@@ -37,21 +32,16 @@ describe('Test abuses API validators', function () {
   before(async function () {
     this.timeout(30000)
 
-    server = await flushAndRunServer(1)
+    server = await createSingleServer(1)
 
     await setAccessTokensToServers([ server ])
 
-    const username = 'user1'
-    const password = 'my super password'
-    await server.usersCommand.create({ username: username, password: password })
-    userToken = await server.loginCommand.getAccessToken({ username, password })
+    userToken = await server.users.generateUserAndToken('user_1')
+    userToken2 = await server.users.generateUserAndToken('user_2')
 
-    userToken2 = await server.usersCommand.generateUserAndToken('user_2')
+    server.store.videoCreated = await server.videos.upload()
 
-    const res = await uploadVideo(server.url, server.accessToken, {})
-    server.video = res.body.video
-
-    command = server.abusesCommand
+    command = server.abuses
   })
 
   describe('When listing abuses for admins', function () {
@@ -73,7 +63,7 @@ describe('Test abuses API validators', function () {
       await makeGetRequest({
         url: server.url,
         path,
-        statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
+        expectedStatus: HttpStatusCode.UNAUTHORIZED_401
       })
     })
 
@@ -82,7 +72,7 @@ describe('Test abuses API validators', function () {
         url: server.url,
         path,
         token: userToken,
-        statusCodeExpected: HttpStatusCode.FORBIDDEN_403
+        expectedStatus: HttpStatusCode.FORBIDDEN_403
       })
     })
 
@@ -117,7 +107,7 @@ describe('Test abuses API validators', function () {
         videoIs: 'deleted'
       }
 
-      await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: HttpStatusCode.OK_200 })
+      await makeGetRequest({ url: server.url, path, token: server.accessToken, query, expectedStatus: HttpStatusCode.OK_200 })
     })
   })
 
@@ -140,7 +130,7 @@ describe('Test abuses API validators', function () {
       await makeGetRequest({
         url: server.url,
         path,
-        statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
+        expectedStatus: HttpStatusCode.UNAUTHORIZED_401
       })
     })
 
@@ -159,7 +149,7 @@ describe('Test abuses API validators', function () {
         state: 2
       }
 
-      await makeGetRequest({ url: server.url, path, token: userToken, query, statusCodeExpected: HttpStatusCode.OK_200 })
+      await makeGetRequest({ url: server.url, path, token: userToken, query, expectedStatus: HttpStatusCode.OK_200 })
     })
   })
 
@@ -173,7 +163,7 @@ describe('Test abuses API validators', function () {
 
     it('Should fail with a wrong video', async function () {
       const fields = { video: { id: 'blabla' }, reason: 'my super reason' }
-      await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
+      await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
     })
 
     it('Should fail with an unknown video', async function () {
@@ -183,13 +173,13 @@ describe('Test abuses API validators', function () {
         path,
         token: userToken,
         fields,
-        statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+        expectedStatus: HttpStatusCode.NOT_FOUND_404
       })
     })
 
     it('Should fail with a wrong comment', async function () {
       const fields = { comment: { id: 'blabla' }, reason: 'my super reason' }
-      await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
+      await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
     })
 
     it('Should fail with an unknown comment', async function () {
@@ -199,13 +189,13 @@ describe('Test abuses API validators', function () {
         path,
         token: userToken,
         fields,
-        statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+        expectedStatus: HttpStatusCode.NOT_FOUND_404
       })
     })
 
     it('Should fail with a wrong account', async function () {
       const fields = { account: { id: 'blabla' }, reason: 'my super reason' }
-      await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
+      await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
     })
 
     it('Should fail with an unknown account', async function () {
@@ -215,7 +205,7 @@ describe('Test abuses API validators', function () {
         path,
         token: userToken,
         fields,
-        statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+        expectedStatus: HttpStatusCode.NOT_FOUND_404
       })
     })
 
@@ -226,63 +216,63 @@ describe('Test abuses API validators', function () {
         path,
         token: userToken,
         fields,
-        statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
+        expectedStatus: HttpStatusCode.BAD_REQUEST_400
       })
     })
 
     it('Should fail with a non authenticated user', async function () {
-      const fields = { video: { id: server.video.id }, reason: 'my super reason' }
+      const fields = { video: { id: server.store.videoCreated.id }, reason: 'my super reason' }
 
-      await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
+      await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
     })
 
     it('Should fail with a reason too short', async function () {
-      const fields = { video: { id: server.video.id }, reason: 'h' }
+      const fields = { video: { id: server.store.videoCreated.id }, reason: 'h' }
 
       await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
     })
 
     it('Should fail with a too big reason', async function () {
-      const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) }
+      const fields = { video: { id: server.store.videoCreated.id }, reason: 'super'.repeat(605) }
 
       await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
     })
 
     it('Should succeed with the correct parameters (basic)', async function () {
-      const fields: AbuseCreate = { video: { id: server.video.shortUUID }, reason: 'my super reason' }
+      const fields: AbuseCreate = { video: { id: server.store.videoCreated.shortUUID }, reason: 'my super reason' }
 
       const res = await makePostBodyRequest({
         url: server.url,
         path,
         token: userToken,
         fields,
-        statusCodeExpected: HttpStatusCode.OK_200
+        expectedStatus: HttpStatusCode.OK_200
       })
       abuseId = res.body.abuse.id
     })
 
     it('Should fail with a wrong predefined reason', async function () {
-      const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
+      const fields = { video: server.store.videoCreated, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
 
       await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
     })
 
     it('Should fail with negative timestamps', async function () {
-      const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' }
+      const fields = { video: { id: server.store.videoCreated.id, startAt: -1 }, reason: 'my super reason' }
 
       await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
     })
 
     it('Should fail mith misordered startAt/endAt', async function () {
-      const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' }
+      const fields = { video: { id: server.store.videoCreated.id, startAt: 5, endAt: 1 }, reason: 'my super reason' }
 
       await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
     })
 
-    it('Should succeed with the corret parameters (advanced)', async function () {
+    it('Should succeed with the correct parameters (advanced)', async function () {
       const fields: AbuseCreate = {
         video: {
-          id: server.video.id,
+          id: server.store.videoCreated.id,
           startAt: 1,
           endAt: 5
         },
@@ -290,7 +280,7 @@ describe('Test abuses API validators', function () {
         predefinedReasons: [ 'serverRules' ]
       }
 
-      await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.OK_200 })
+      await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.OK_200 })
     })
   })
 
@@ -343,7 +333,7 @@ describe('Test abuses API validators', function () {
       await command.addMessage({ token: userToken, abuseId, message: 'a'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
     })
 
-    it('Should suceed with the correct params', async function () {
+    it('Should succeed with the correct params', async function () {
       const res = await command.addMessage({ token: userToken, abuseId, message })
       messageId = res.body.abuseMessage.id
     })
@@ -411,18 +401,18 @@ describe('Test abuses API validators', function () {
 
   describe('When trying to manage messages of a remote abuse', function () {
     let remoteAbuseId: number
-    let anotherServer: ServerInfo
+    let anotherServer: PeerTubeServer
 
     before(async function () {
       this.timeout(50000)
 
-      anotherServer = await flushAndRunServer(2)
+      anotherServer = await createSingleServer(2)
       await setAccessTokensToServers([ anotherServer ])
 
       await doubleFollow(anotherServer, server)
 
-      const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid)
-      await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId })
+      const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.videoCreated.uuid })
+      await anotherServer.abuses.report({ reason: 'remote server', videoId: server2VideoId })
 
       await waitJobs([ server, anotherServer ])