]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live-constraints.ts
Reorganize plugin models
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-constraints.ts
index 23c8e3b0a999d198f374446a76272e83d237f7b5..cc635de339d2102858ffbcfc08cf225187e98d97 100644 (file)
@@ -2,15 +2,15 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { User, VideoDetails, VideoPrivacy } from '@shared/models'
+import { VideoDetails, VideoPrivacy } from '@shared/models'
 import {
   checkLiveCleanup,
   cleanupTests,
   createLive,
-  createUser,
   doubleFollow,
   flushAndRunMultipleServers,
-  getMyUserInformation,
+  generateUser,
+  getCustomConfigResolutions,
   getVideo,
   runAndTestFfmpegStreamError,
   ServerInfo,
@@ -18,9 +18,9 @@ import {
   setDefaultVideoChannel,
   updateCustomSubConfig,
   updateUser,
-  userLogin,
   wait,
-  waitJobs
+  waitJobs,
+  waitUntilLivePublished
 } from '../../../../shared/extra-utils'
 
 const expect = chai.expect
@@ -55,6 +55,22 @@ describe('Test live constraints', function () {
     await checkLiveCleanup(servers[0], videoId, resolutions)
   }
 
+  async function waitUntilLivePublishedOnAllServers (videoId: string) {
+    for (const server of servers) {
+      await waitUntilLivePublished(server.url, server.accessToken, videoId)
+    }
+  }
+
+  function updateQuota (options: { total: number, daily: number }) {
+    return updateUser({
+      url: servers[0].url,
+      accessToken: servers[0].accessToken,
+      userId,
+      videoQuota: options.total,
+      videoQuotaDaily: options.daily
+    })
+  }
+
   before(async function () {
     this.timeout(120000)
 
@@ -75,27 +91,12 @@ describe('Test live constraints', function () {
     })
 
     {
-      const user = { username: 'user1', password: 'superpassword' }
-      const res = await createUser({
-        url: servers[0].url,
-        accessToken: servers[0].accessToken,
-        username: user.username,
-        password: user.password
-      })
-      userId = res.body.user.id
-
-      userAccessToken = await userLogin(servers[0], user)
-
-      const resMe = await getMyUserInformation(servers[0].url, userAccessToken)
-      userChannelId = (resMe.body as User).videoChannels[0].id
-
-      await updateUser({
-        url: servers[0].url,
-        userId,
-        accessToken: servers[0].accessToken,
-        videoQuota: 1,
-        videoQuotaDaily: -1
-      })
+      const res = await generateUser(servers[0], 'user1')
+      userId = res.userId
+      userChannelId = res.userChannelId
+      userAccessToken = res.token
+
+      await updateQuota({ total: 1, daily: -1 })
     }
 
     // Server 1 and server 2 follow each other
@@ -118,6 +119,7 @@ describe('Test live constraints', function () {
     const userVideoLiveoId = await createLiveWrapper(true)
     await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
 
+    await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
     await waitJobs(servers)
 
     await checkSaveReplay(userVideoLiveoId)
@@ -129,17 +131,12 @@ describe('Test live constraints', function () {
     // Wait for user quota memoize cache invalidation
     await wait(5000)
 
-    await updateUser({
-      url: servers[0].url,
-      userId,
-      accessToken: servers[0].accessToken,
-      videoQuota: -1,
-      videoQuotaDaily: 1
-    })
+    await updateQuota({ total: -1, daily: 1 })
 
     const userVideoLiveoId = await createLiveWrapper(true)
     await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
 
+    await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
     await waitJobs(servers)
 
     await checkSaveReplay(userVideoLiveoId)
@@ -151,20 +148,14 @@ describe('Test live constraints', function () {
     // Wait for user quota memoize cache invalidation
     await wait(5000)
 
-    await updateUser({
-      url: servers[0].url,
-      userId,
-      accessToken: servers[0].accessToken,
-      videoQuota: 10 * 1000 * 1000,
-      videoQuotaDaily: -1
-    })
+    await updateQuota({ total: 10 * 1000 * 1000, daily: -1 })
 
     const userVideoLiveoId = await createLiveWrapper(true)
     await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false)
   })
 
   it('Should have max duration limit', async function () {
-    this.timeout(30000)
+    this.timeout(60000)
 
     await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
       live: {
@@ -173,14 +164,7 @@ describe('Test live constraints', function () {
         maxDuration: 1,
         transcoding: {
           enabled: true,
-          resolutions: {
-            '240p': true,
-            '360p': true,
-            '480p': true,
-            '720p': true,
-            '1080p': true,
-            '2160p': true
-          }
+          resolutions: getCustomConfigResolutions(true)
         }
       }
     })
@@ -188,6 +172,7 @@ describe('Test live constraints', function () {
     const userVideoLiveoId = await createLiveWrapper(true)
     await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true)
 
+    await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
     await waitJobs(servers)
 
     await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240 ])