]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/redundancy/redundancy-constraints.ts
Introduce captions command
[github/Chocobozzz/PeerTube.git] / server / tests / api / redundancy / redundancy-constraints.ts
index 4fd8f065c0fb2a68228cfe091f9f54835c7d60e2..a666976b3865e2284262144e5e77e055225aad74 100644 (file)
@@ -1,20 +1,19 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import * as chai from 'chai'
 import 'mocha'
 import {
   cleanupTests,
   flushAndRunServer,
-  follow,
   killallServers,
   reRunServer,
   ServerInfo,
   setAccessTokensToServers,
+  updateVideo,
   uploadVideo,
+  waitJobs,
   waitUntilLog
-} from '../../../../shared/extra-utils'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { listVideoRedundancies, updateRedundancy } from '@shared/extra-utils/server/redundancy'
+} from '@shared/extra-utils'
+import { VideoPrivacy } from '@shared/models'
 
 const expect = chai.expect
 
@@ -23,46 +22,48 @@ describe('Test redundancy constraints', function () {
   let localServer: ServerInfo
   let servers: ServerInfo[]
 
+  const remoteServerConfig = {
+    redundancy: {
+      videos: {
+        check_interval: '1 second',
+        strategies: [
+          {
+            strategy: 'recently-added',
+            min_lifetime: '1 hour',
+            size: '100MB',
+            min_views: 0
+          }
+        ]
+      }
+    }
+  }
+
+  async function uploadWrapper (videoName: string) {
+    // Wait for transcoding
+    const res = await uploadVideo(localServer.url, localServer.accessToken, { name: 'to transcode', privacy: VideoPrivacy.PRIVATE })
+    await waitJobs([ localServer ])
+
+    // Update video to schedule a federation
+    await updateVideo(localServer.url, localServer.accessToken, res.body.video.id, { name: videoName, privacy: VideoPrivacy.PUBLIC })
+  }
+
   async function getTotalRedundanciesLocalServer () {
-    const res = await listVideoRedundancies({
-      url: localServer.url,
-      accessToken: localServer.accessToken,
-      target: 'my-videos'
-    })
+    const body = await localServer.redundancyCommand.listVideos({ target: 'my-videos' })
 
-    return res.body.total
+    return body.total
   }
 
   async function getTotalRedundanciesRemoteServer () {
-    const res = await listVideoRedundancies({
-      url: remoteServer.url,
-      accessToken: remoteServer.accessToken,
-      target: 'remote-videos'
-    })
+    const body = await remoteServer.redundancyCommand.listVideos({ target: 'remote-videos' })
 
-    return res.body.total
+    return body.total
   }
 
   before(async function () {
     this.timeout(120000)
 
     {
-      const config = {
-        redundancy: {
-          videos: {
-            check_interval: '1 second',
-            strategies: [
-              {
-                strategy: 'recently-added',
-                min_lifetime: '1 hour',
-                size: '100MB',
-                min_views: 0
-              }
-            ]
-          }
-        }
-      }
-      remoteServer = await flushAndRunServer(1, config)
+      remoteServer = await flushAndRunServer(1, remoteServerConfig)
     }
 
     {
@@ -86,9 +87,9 @@ describe('Test redundancy constraints', function () {
     await waitJobs(servers)
 
     // Server 1 and server 2 follow each other
-    await follow(remoteServer.url, [ localServer.url ], remoteServer.accessToken)
+    await remoteServer.followsCommand.follow({ targets: [ localServer.url ] })
     await waitJobs(servers)
-    await updateRedundancy(remoteServer.url, remoteServer.accessToken, localServer.host, true)
+    await remoteServer.redundancyCommand.updateRedundancy({ host: localServer.host, redundancyAllowed: true })
 
     await waitJobs(servers)
   })
@@ -124,9 +125,8 @@ describe('Test redundancy constraints', function () {
     await killallServers([ localServer ])
     await reRunServer(localServer, config)
 
-    await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 2 server 2' })
+    await uploadWrapper('video 2 server 2')
 
-    await waitJobs(servers)
     await waitUntilLog(remoteServer, 'Duplicated ', 10)
     await waitJobs(servers)
 
@@ -151,12 +151,11 @@ describe('Test redundancy constraints', function () {
         }
       }
     }
-    await killallServers([ localServer ])
+    killallServers([ localServer ])
     await reRunServer(localServer, config)
 
-    await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 3 server 2' })
+    await uploadWrapper('video 3 server 2')
 
-    await waitJobs(servers)
     await waitUntilLog(remoteServer, 'Duplicated ', 15)
     await waitJobs(servers)
 
@@ -174,12 +173,10 @@ describe('Test redundancy constraints', function () {
   it('Should have redundancy on server 1 and on server 2 with followings filter now server 2 follows server 1', async function () {
     this.timeout(120000)
 
-    await follow(localServer.url, [ remoteServer.url ], localServer.accessToken)
+    await localServer.followsCommand.follow({ targets: [ remoteServer.url ] })
     await waitJobs(servers)
 
-    await uploadVideo(localServer.url, localServer.accessToken, { name: 'video 4 server 2' })
-
-    await waitJobs(servers)
+    await uploadWrapper('video 4 server 2')
     await waitUntilLog(remoteServer, 'Duplicated ', 20)
     await waitJobs(servers)