]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/video-comments.ts
Introduce user command
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-comments.ts
index 659a10c413bd614f92a72bd058e6c019cc03bf5f..b7656a17661be4b05f772b4db600f7806a090a65 100644 (file)
@@ -1,26 +1,22 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
+import * as chai from 'chai'
+import { HttpStatusCode } from '@shared/core-utils'
 import {
+  checkBadCountPagination,
+  checkBadSortPagination,
+  checkBadStartPagination,
   cleanupTests,
-  createUser,
   flushAndRunServer,
   makeDeleteRequest,
   makeGetRequest,
   makePostBodyRequest,
   ServerInfo,
   setAccessTokensToServers,
-  uploadVideo,
-  userLogin
-} from '../../../../shared/extra-utils'
-import {
-  checkBadCountPagination,
-  checkBadSortPagination,
-  checkBadStartPagination
-} from '../../../../shared/extra-utils/requests/check-api-params'
-import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+  uploadVideo
+} from '@shared/extra-utils'
+import { VideoCreateResult } from '@shared/models'
 
 const expect = chai.expect
 
@@ -28,7 +24,7 @@ describe('Test video comments API validator', function () {
   let pathThread: string
   let pathComment: string
   let server: ServerInfo
-  let videoUUID: string
+  let video: VideoCreateResult
   let userAccessToken: string
   let userAccessToken2: string
   let commentId: number
@@ -44,26 +40,26 @@ describe('Test video comments API validator', function () {
 
     {
       const res = await uploadVideo(server.url, server.accessToken, {})
-      videoUUID = res.body.video.uuid
-      pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
+      video = res.body.video
+      pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
     }
 
     {
-      const res = await addVideoCommentThread(server.url, server.accessToken, videoUUID, 'coucou')
-      commentId = res.body.comment.id
-      pathComment = '/api/v1/videos/' + videoUUID + '/comments/' + commentId
+      const created = await server.commentsCommand.createThread({ videoId: video.uuid, text: 'coucou' })
+      commentId = created.id
+      pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId
     }
 
     {
       const user = { username: 'user1', password: 'my super password' }
-      await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
-      userAccessToken = await userLogin(server, user)
+      await server.usersCommand.create({ username: user.username, password: user.password })
+      userAccessToken = await server.loginCommand.getAccessToken(user)
     }
 
     {
       const user = { username: 'user2', password: 'my super password' }
-      await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
-      userAccessToken2 = await userLogin(server, user)
+      await server.usersCommand.create({ username: user.username, password: user.password })
+      userAccessToken2 = await server.loginCommand.getAccessToken(user)
     }
   })
 
@@ -101,7 +97,7 @@ describe('Test video comments API validator', function () {
     it('Should fail with an incorrect thread id', async function () {
       await makeGetRequest({
         url: server.url,
-        path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
+        path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/156',
         statusCodeExpected: HttpStatusCode.NOT_FOUND_404
       })
     })
@@ -109,7 +105,7 @@ describe('Test video comments API validator', function () {
     it('Should success with the correct params', async function () {
       await makeGetRequest({
         url: server.url,
-        path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
+        path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/' + commentId,
         statusCodeExpected: HttpStatusCode.OK_200
       })
     })
@@ -225,7 +221,7 @@ describe('Test video comments API validator', function () {
     })
 
     it('Should fail with an incorrect comment', async function () {
-      const path = '/api/v1/videos/' + videoUUID + '/comments/124'
+      const path = '/api/v1/videos/' + video.uuid + '/comments/124'
       const fields = {
         text: 'super comment'
       }
@@ -272,7 +268,7 @@ describe('Test video comments API validator', function () {
     })
 
     it('Should fail with an incorrect comment', async function () {
-      const path = '/api/v1/videos/' + videoUUID + '/comments/124'
+      const path = '/api/v1/videos/' + video.uuid + '/comments/124'
       await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
     })
 
@@ -280,11 +276,11 @@ describe('Test video comments API validator', function () {
       let commentToDelete: number
 
       {
-        const res = await addVideoCommentThread(server.url, userAccessToken, videoUUID, 'hello')
-        commentToDelete = res.body.comment.id
+        const created = await server.commentsCommand.createThread({ videoId: video.uuid, token: userAccessToken, text: 'hello' })
+        commentToDelete = created.id
       }
 
-      const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete
+      const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete
 
       await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
       await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
@@ -300,8 +296,8 @@ describe('Test video comments API validator', function () {
       }
 
       {
-        const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello')
-        commentToDelete = res.body.comment.id
+        const created = await server.commentsCommand.createThread({ videoId: anotherVideoUUID, text: 'hello' })
+        commentToDelete = created.id
       }
 
       const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
@@ -323,8 +319,8 @@ describe('Test video comments API validator', function () {
   describe('When a video has comments disabled', function () {
     before(async function () {
       const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false })
-      videoUUID = res.body.video.uuid
-      pathThread = '/api/v1/videos/' + videoUUID + '/comment-threads'
+      video = res.body.video
+      pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
     })
 
     it('Should return an empty thread list', async function () {