]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/live/live-constraints.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-constraints.ts
index b819733953c237ab0996d4bd72880b586712b4cc..cf43c262ad0b3fb135efc6a0035696bc0d1ffdcb 100644 (file)
@@ -12,7 +12,9 @@ import {
   PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
+  stopFfmpeg,
   waitJobs,
+  waitUntilLiveReplacedByReplayOnAllServers,
   waitUntilLiveWaitingOnAllServers
 } from '@shared/server-commands'
 import { checkLiveCleanup } from '../../shared'
@@ -53,12 +55,6 @@ describe('Test live constraints', function () {
     await checkLiveCleanup(servers[0], videoId, resolutions)
   }
 
-  async function waitUntilLivePublishedOnAllServers (videoId: string) {
-    for (const server of servers) {
-      await server.live.waitUntilPublished({ videoId })
-    }
-  }
-
   function updateQuota (options: { total: number, daily: number }) {
     return servers[0].users.update({
       userId,
@@ -117,7 +113,7 @@ describe('Test live constraints', function () {
     const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
     await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
 
-    await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
+    await waitUntilLiveReplacedByReplayOnAllServers(servers, userVideoLiveoId)
     await waitJobs(servers)
 
     await checkSaveReplay(userVideoLiveoId)
@@ -153,7 +149,7 @@ describe('Test live constraints', function () {
     const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
     await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
 
-    await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
+    await waitUntilLiveReplacedByReplayOnAllServers(servers, userVideoLiveoId)
     await waitJobs(servers)
 
     await checkSaveReplay(userVideoLiveoId)
@@ -174,6 +170,30 @@ describe('Test live constraints', function () {
     await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: false })
   })
 
+  it('Should have the same quota in admin and as a user', async function () {
+    this.timeout(120000)
+
+    const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
+    const ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ token: userAccessToken, videoId: userVideoLiveoId })
+
+    await servers[0].live.waitUntilPublished({ videoId: userVideoLiveoId })
+
+    await wait(3000)
+
+    const quotaUser = await servers[0].users.getMyQuotaUsed({ token: userAccessToken })
+
+    const { data } = await servers[0].users.list()
+    const quotaAdmin = data.find(u => u.username === 'user1')
+
+    expect(quotaUser.videoQuotaUsed).to.equal(quotaAdmin.videoQuotaUsed)
+    expect(quotaUser.videoQuotaUsedDaily).to.equal(quotaAdmin.videoQuotaUsedDaily)
+
+    expect(quotaUser.videoQuotaUsed).to.be.above(10)
+    expect(quotaUser.videoQuotaUsedDaily).to.be.above(10)
+
+    await stopFfmpeg(ffmpegCommand)
+  })
+
   it('Should have max duration limit', async function () {
     this.timeout(60000)
 
@@ -194,7 +214,7 @@ describe('Test live constraints', function () {
     const userVideoLiveoId = await createLiveWrapper({ replay: true, permanent: false })
     await servers[0].live.runAndTestStreamError({ token: userAccessToken, videoId: userVideoLiveoId, shouldHaveError: true })
 
-    await waitUntilLivePublishedOnAllServers(userVideoLiveoId)
+    await waitUntilLiveReplacedByReplayOnAllServers(servers, userVideoLiveoId)
     await waitJobs(servers)
 
     await checkSaveReplay(userVideoLiveoId, [ 720, 480, 360, 240, 144 ])