]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/video-comments.ts
Fix CI using 127.0.0.1 for tests
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-comments.ts
index f9bd2364627d1779dc2dc911dc5776fa23954ee1..dc47f8a4a41c83b9b3eef8835d8873b5b6aa6f38 100644 (file)
@@ -1,24 +1,19 @@
 /* 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,
-  createUser,
-  dateIsValid,
-  flushAndRunServer,
-  ServerInfo,
+  createSingleServer,
+  PeerTubeServer,
   setAccessTokensToServers,
-  testImage,
-  updateMyAvatar,
-  uploadVideo
-} from '@shared/extra-utils'
-
-const expect = chai.expect
+  setDefaultAccountAvatar,
+  setDefaultChannelAvatar
+} from '@shared/server-commands'
 
 describe('Test video comments', function () {
-  let server: ServerInfo
+  let server: PeerTubeServer
   let videoId: number
   let videoUUID: string
   let threadId: number
@@ -31,29 +26,20 @@ describe('Test video comments', function () {
   before(async function () {
     this.timeout(30000)
 
-    server = await flushAndRunServer(1)
+    server = await createSingleServer(1)
 
     await setAccessTokensToServers([ server ])
 
-    const res = await uploadVideo(server.url, server.accessToken, {})
-    videoUUID = res.body.video.uuid
-    videoId = res.body.video.id
+    const { id, uuid } = await server.videos.upload()
+    videoUUID = uuid
+    videoId = id
 
-    await updateMyAvatar({
-      url: server.url,
-      accessToken: server.accessToken,
-      fixture: 'avatar.png'
-    })
+    await setDefaultChannelAvatar(server)
+    await setDefaultAccountAvatar(server)
 
-    await createUser({
-      url: server.url,
-      accessToken: server.accessToken,
-      username: 'user1',
-      password: 'password'
-    })
-    userAccessTokenServer1 = await server.loginCommand.getAccessToken('user1', 'password')
+    userAccessTokenServer1 = await server.users.generateUserAndToken('user1')
 
-    command = server.commentsCommand
+    command = server.comments
   })
 
   describe('User comments', function () {
@@ -77,8 +63,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
@@ -99,9 +85,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)
@@ -263,6 +251,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' })