]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/moderation/video-blacklist.ts
Force live stream termination
[github/Chocobozzz/PeerTube.git] / server / tests / api / moderation / video-blacklist.ts
index d23d23bcbf6103b90eba8930569758bd44de529b..ef087a93b812fa8276b98bc4a9808b9ef49a0185 100644 (file)
@@ -1,30 +1,27 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
-import { orderBy } from 'lodash'
+import { expect } from 'chai'
+import { FIXTURE_URLS } from '@server/tests/shared'
+import { sortObjectComparator } from '@shared/core-utils'
+import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
 import {
   BlacklistCommand,
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
-  ImportsCommand,
   killallServers,
-  reRunServer,
-  ServerInfo,
+  PeerTubeServer,
   setAccessTokensToServers,
+  setDefaultChannelAvatar,
   waitJobs
-} from '@shared/extra-utils'
-import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
-
-const expect = chai.expect
+} from '@shared/server-commands'
 
 describe('Test video blacklist', function () {
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   let videoId: number
   let command: BlacklistCommand
 
-  async function blacklistVideosOnServer (server: ServerInfo) {
+  async function blacklistVideosOnServer (server: PeerTubeServer) {
     const { data } = await server.videos.list()
 
     for (const video of data) {
@@ -33,16 +30,17 @@ describe('Test video blacklist', function () {
   }
 
   before(async function () {
-    this.timeout(50000)
+    this.timeout(120000)
 
     // Run servers
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
 
     // Get the access tokens
     await setAccessTokensToServers(servers)
 
     // Server 1 and server 2 follow each other
     await doubleFollow(servers[0], servers[1])
+    await setDefaultChannelAvatar(servers[0])
 
     // Upload 2 videos on server 2
     await servers[1].videos.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } })
@@ -137,7 +135,7 @@ describe('Test video blacklist', function () {
       expect(blacklistedVideos).to.be.an('array')
       expect(blacklistedVideos.length).to.equal(2)
 
-      const result = orderBy(body.data, [ 'id' ], [ 'desc' ])
+      const result = [ ...body.data ].sort(sortObjectComparator('id', 'desc'))
       expect(blacklistedVideos).to.deep.equal(result)
     })
 
@@ -149,7 +147,7 @@ describe('Test video blacklist', function () {
       expect(blacklistedVideos).to.be.an('array')
       expect(blacklistedVideos.length).to.equal(2)
 
-      const result = orderBy(body.data, [ 'name' ], [ 'desc' ])
+      const result = [ ...body.data ].sort(sortObjectComparator('name', 'desc'))
       expect(blacklistedVideos).to.deep.equal(result)
     })
 
@@ -161,7 +159,7 @@ describe('Test video blacklist', function () {
       expect(blacklistedVideos).to.be.an('array')
       expect(blacklistedVideos.length).to.equal(2)
 
-      const result = orderBy(body.data, [ 'createdAt' ])
+      const result = [ ...body.data ].sort(sortObjectComparator('createdAt', 'asc'))
       expect(blacklistedVideos).to.deep.equal(result)
     })
   })
@@ -241,8 +239,6 @@ describe('Test video blacklist', function () {
     let video4UUID: string
 
     before(async function () {
-      this.timeout(10000)
-
       {
         const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 3' } })
         video3UUID = uuid
@@ -256,8 +252,6 @@ describe('Test video blacklist', function () {
     })
 
     it('Should blacklist video 3 and keep it federated', async function () {
-      this.timeout(10000)
-
       await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false })
 
       await waitJobs(servers)
@@ -274,8 +268,6 @@ describe('Test video blacklist', function () {
     })
 
     it('Should unfederate the video', async function () {
-      this.timeout(10000)
-
       await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true })
 
       await waitJobs(servers)
@@ -287,8 +279,6 @@ describe('Test video blacklist', function () {
     })
 
     it('Should have the video unfederated even after an Update AP message', async function () {
-      this.timeout(10000)
-
       await servers[0].videos.update({ id: video4UUID, attributes: { description: 'super description' } })
 
       await waitJobs(servers)
@@ -311,8 +301,6 @@ describe('Test video blacklist', function () {
     })
 
     it('Should remove the video from blacklist and refederate the video', async function () {
-      this.timeout(10000)
-
       await command.remove({ videoId: video4UUID })
 
       await waitJobs(servers)
@@ -344,7 +332,7 @@ describe('Test video blacklist', function () {
           }
         }
       }
-      await reRunServer(servers[0], config)
+      await servers[0].run(config)
 
       {
         const user = { username: 'user_without_flag', password: 'password' }
@@ -388,7 +376,7 @@ describe('Test video blacklist', function () {
       this.timeout(15000)
 
       const attributes = {
-        targetUrl: ImportsCommand.getGoodVideoUrl(),
+        targetUrl: FIXTURE_URLS.goodVideo,
         name: 'URL import',
         channelId: channelOfUserWithoutFlag
       }
@@ -401,7 +389,7 @@ describe('Test video blacklist', function () {
 
     it('Should auto blacklist a video on torrent import', async function () {
       const attributes = {
-        magnetUri: ImportsCommand.getMagnetURI(),
+        magnetUri: FIXTURE_URLS.magnet,
         name: 'Torrent import',
         channelId: channelOfUserWithoutFlag
       }