]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-comments.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-comments.ts
index bb4f92a9bd74ef977f6ab4be42f482a430d156fc..b7d5624a6b3c8f794928844af4451219084af380 100644 (file)
@@ -1,19 +1,17 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
+import { dateIsValid, testImage } from '@server/tests/shared'
 import {
   cleanupTests,
   CommentsCommand,
   createSingleServer,
-  dateIsValid,
   PeerTubeServer,
   setAccessTokensToServers,
-  testImage
+  setDefaultAccountAvatar,
+  setDefaultChannelAvatar
 } from '@shared/server-commands'
 
-const expect = chai.expect
-
 describe('Test video comments', function () {
   let server: PeerTubeServer
   let videoId: number
@@ -26,7 +24,7 @@ describe('Test video comments', function () {
   let command: CommentsCommand
 
   before(async function () {
-    this.timeout(30000)
+    this.timeout(120000)
 
     server = await createSingleServer(1)
 
@@ -36,9 +34,12 @@ describe('Test video comments', function () {
     videoUUID = uuid
     videoId = id
 
-    await server.users.updateMyAvatar({ fixture: 'avatar.png' })
+    await setDefaultChannelAvatar(server)
+    await setDefaultAccountAvatar(server)
 
     userAccessTokenServer1 = await server.users.generateUserAndToken('user1')
+    await setDefaultChannelAvatar(server, 'user1_channel')
+    await setDefaultAccountAvatar(server, userAccessTokenServer1)
 
     command = server.comments
   })
@@ -64,8 +65,8 @@ describe('Test video comments', function () {
       expect(comment.videoId).to.equal(videoId)
       expect(comment.id).to.equal(comment.threadId)
       expect(comment.account.name).to.equal('root')
-      expect(comment.account.host).to.equal('localhost:' + server.port)
-      expect(comment.account.url).to.equal('http://localhost:' + server.port + '/accounts/root')
+      expect(comment.account.host).to.equal(server.host)
+      expect(comment.account.url).to.equal(server.url + '/accounts/root')
       expect(comment.totalReplies).to.equal(0)
       expect(comment.totalRepliesFromVideoAuthor).to.equal(0)
       expect(dateIsValid(comment.createdAt as string)).to.be.true
@@ -86,9 +87,11 @@ describe('Test video comments', function () {
       expect(comment.videoId).to.equal(videoId)
       expect(comment.id).to.equal(comment.threadId)
       expect(comment.account.name).to.equal('root')
-      expect(comment.account.host).to.equal('localhost:' + server.port)
+      expect(comment.account.host).to.equal(server.host)
 
-      await testImage(server.url, 'avatar-resized', comment.account.avatar.path, '.png')
+      for (const avatar of comment.account.avatars) {
+        await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatar.path, '.png')
+      }
 
       expect(comment.totalReplies).to.equal(0)
       expect(comment.totalRepliesFromVideoAuthor).to.equal(0)
@@ -166,6 +169,13 @@ describe('Test video comments', function () {
       expect(body.data[2].totalReplies).to.equal(0)
     })
 
+    it('Should list the and sort them by total replies', async function () {
+      const body = await command.listThreads({ videoId: videoUUID, sort: 'totalReplies' })
+
+      expect(body.data[2].text).to.equal('my super first comment')
+      expect(body.data[2].totalReplies).to.equal(3)
+    })
+
     it('Should delete a reply', async function () {
       await command.delete({ videoId, commentId: replyToDeleteId })
 
@@ -231,16 +241,34 @@ describe('Test video comments', function () {
       await command.addReply({ videoId, toCommentId: threadId2, text: text3 })
 
       const tree = await command.getThread({ videoId: videoUUID, threadId: threadId2 })
-      expect(tree.comment.totalReplies).to.equal(tree.comment.totalRepliesFromVideoAuthor + 1)
+      expect(tree.comment.totalRepliesFromVideoAuthor).to.equal(1)
+      expect(tree.comment.totalReplies).to.equal(2)
     })
   })
 
   describe('All instance comments', function () {
 
     it('Should list instance comments as admin', async function () {
-      const { data } = await command.listForAdmin({ start: 0, count: 1 })
+      {
+        const { data, total } = await command.listForAdmin({ start: 0, count: 1 })
+
+        expect(total).to.equal(7)
+        expect(data).to.have.lengthOf(1)
+        expect(data[0].text).to.equal('my second answer to thread 4')
+        expect(data[0].account.name).to.equal('root')
+        expect(data[0].account.displayName).to.equal('root')
+        expect(data[0].account.avatars).to.have.lengthOf(2)
+      }
+
+      {
+        const { data, total } = await command.listForAdmin({ start: 1, count: 2 })
+
+        expect(total).to.equal(7)
+        expect(data).to.have.lengthOf(2)
 
-      expect(data[0].text).to.equal('my second answer to thread 4')
+        expect(data[0].account.avatars).to.have.lengthOf(2)
+        expect(data[1].account.avatars).to.have.lengthOf(2)
+      }
     })
 
     it('Should filter instance comments by isLocal', async function () {
@@ -250,6 +278,22 @@ describe('Test video comments', function () {
       expect(total).to.equal(0)
     })
 
+    it('Should filter instance comments by onLocalVideo', async function () {
+      {
+        const { total, data } = await command.listForAdmin({ onLocalVideo: false })
+
+        expect(data).to.have.lengthOf(0)
+        expect(total).to.equal(0)
+      }
+
+      {
+        const { total, data } = await command.listForAdmin({ onLocalVideo: true })
+
+        expect(data).to.not.have.lengthOf(0)
+        expect(total).to.not.equal(0)
+      }
+    })
+
     it('Should search instance comments by account', async function () {
       const { total, data } = await command.listForAdmin({ searchAccount: 'user' })