]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/views/video-views-overall-stats.ts
Added "total views" in the my channels list (#5007)
[github/Chocobozzz/PeerTube.git] / server / tests / api / views / video-views-overall-stats.ts
index 53b8f0d4b97e91e570ae6819e6ac6a1ac0e9e5c6..25e488b915c4b305c4010ac2dd150a2003b98bdd 100644 (file)
@@ -36,6 +36,7 @@ describe('Test views overall stats', function () {
         expect(video.views).to.equal(0)
         expect(stats.averageWatchTime).to.equal(0)
         expect(stats.totalWatchTime).to.equal(0)
+        expect(stats.totalViewers).to.equal(0)
       }
     })
 
@@ -55,6 +56,7 @@ describe('Test views overall stats', function () {
         expect(video.views).to.equal(0)
         expect(stats.averageWatchTime).to.equal(1)
         expect(stats.totalWatchTime).to.equal(1)
+        expect(stats.totalViewers).to.equal(1)
       }
     })
 
@@ -74,6 +76,7 @@ describe('Test views overall stats', function () {
           expect(video.views).to.equal(1)
           expect(stats.averageWatchTime).to.equal(2)
           expect(stats.totalWatchTime).to.equal(4)
+          expect(stats.totalViewers).to.equal(2)
         }
 
         {
@@ -83,6 +86,7 @@ describe('Test views overall stats', function () {
           expect(video.views).to.equal(1)
           expect(stats.averageWatchTime).to.equal(21)
           expect(stats.totalWatchTime).to.equal(41)
+          expect(stats.totalViewers).to.equal(2)
         }
       }
     })
@@ -103,6 +107,7 @@ describe('Test views overall stats', function () {
         expect(video.views).to.equal(1)
         expect(stats.averageWatchTime).to.equal(2)
         expect(stats.totalWatchTime).to.equal(6)
+        expect(stats.totalViewers).to.equal(3)
       }
 
       {
@@ -112,6 +117,7 @@ describe('Test views overall stats', function () {
         expect(video.views).to.equal(1)
         expect(stats.averageWatchTime).to.equal(14)
         expect(stats.totalWatchTime).to.equal(43)
+        expect(stats.totalViewers).to.equal(3)
       }
     })
 
@@ -129,6 +135,7 @@ describe('Test views overall stats', function () {
         expect(video.views).to.equal(2)
         expect(stats.averageWatchTime).to.equal(3)
         expect(stats.totalWatchTime).to.equal(11)
+        expect(stats.totalViewers).to.equal(4)
       }
 
       {
@@ -138,6 +145,7 @@ describe('Test views overall stats', function () {
         expect(video.views).to.equal(2)
         expect(stats.averageWatchTime).to.equal(22)
         expect(stats.totalWatchTime).to.equal(88)
+        expect(stats.totalViewers).to.equal(4)
       }
     })
 
@@ -153,12 +161,14 @@ describe('Test views overall stats', function () {
         const stats = await servers[0].videoStats.getOverallStats({ videoId: vodVideoId, startDate: beforeView.toISOString() })
         expect(stats.averageWatchTime).to.equal(3)
         expect(stats.totalWatchTime).to.equal(3)
+        expect(stats.totalViewers).to.equal(1)
       }
 
       {
         const stats = await servers[0].videoStats.getOverallStats({ videoId: liveVideoId, endDate: beforeView.toISOString() })
         expect(stats.averageWatchTime).to.equal(22)
         expect(stats.totalWatchTime).to.equal(88)
+        expect(stats.totalViewers).to.equal(4)
       }
     })
 
@@ -169,6 +179,7 @@ describe('Test views overall stats', function () {
 
   describe('Test watchers peak stats of local videos on VOD', function () {
     let videoUUID: string
+    let before2Watchers: Date
 
     before(async function () {
       this.timeout(120000);
@@ -201,7 +212,7 @@ describe('Test views overall stats', function () {
     it('Should have watcher peak with 2 watchers', async function () {
       this.timeout(60000)
 
-      const before = new Date()
+      before2Watchers = new Date()
       await servers[0].views.view({ id: videoUUID, currentTime: 0 })
       await servers[1].views.view({ id: videoUUID, currentTime: 0 })
       await servers[0].views.view({ id: videoUUID, currentTime: 2 })
@@ -213,11 +224,26 @@ describe('Test views overall stats', function () {
       const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID })
 
       expect(stats.viewersPeak).to.equal(2)
-      expect(new Date(stats.viewersPeakDate)).to.be.above(before).and.below(after)
+      expect(new Date(stats.viewersPeakDate)).to.be.above(before2Watchers).and.below(after)
+    })
+
+    it('Should filter peak viewers stats by date', async function () {
+      {
+        const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID, startDate: new Date().toISOString() })
+        expect(stats.viewersPeak).to.equal(0)
+        expect(stats.viewersPeakDate).to.not.exist
+      }
+
+      {
+        const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID, endDate: before2Watchers.toISOString() })
+        expect(stats.viewersPeak).to.equal(1)
+        expect(new Date(stats.viewersPeakDate)).to.be.below(before2Watchers)
+      }
     })
   })
 
   describe('Test countries', function () {
+    let videoUUID: string
 
     it('Should not report countries if geoip is disabled', async function () {
       this.timeout(120000)
@@ -237,6 +263,7 @@ describe('Test views overall stats', function () {
       this.timeout(240000)
 
       const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
+      videoUUID = uuid
       await waitJobs(servers)
 
       await Promise.all([
@@ -265,6 +292,11 @@ describe('Test views overall stats', function () {
       expect(stats.countries[1].isoCode).to.equal('FR')
       expect(stats.countries[1].viewers).to.equal(1)
     })
+
+    it('Should filter countries stats by date', async function () {
+      const stats = await servers[0].videoStats.getOverallStats({ videoId: videoUUID, startDate: new Date().toISOString() })
+      expect(stats.countries).to.have.lengthOf(0)
+    })
   })
 
   after(async function () {