aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/views/video-views-retention-stats.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/views/video-views-retention-stats.ts')
-rw-r--r--server/tests/api/views/video-views-retention-stats.ts56
1 files changed, 56 insertions, 0 deletions
diff --git a/server/tests/api/views/video-views-retention-stats.ts b/server/tests/api/views/video-views-retention-stats.ts
new file mode 100644
index 000000000..98be7bfdb
--- /dev/null
+++ b/server/tests/api/views/video-views-retention-stats.ts
@@ -0,0 +1,56 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import { prepareViewsServers, prepareViewsVideos, processViewersStats } from '@server/tests/shared'
6import { cleanupTests, PeerTubeServer } from '@shared/server-commands'
7
8const expect = chai.expect
9
10describe('Test views retention stats', function () {
11 let servers: PeerTubeServer[]
12
13 before(async function () {
14 this.timeout(120000)
15
16 servers = await prepareViewsServers()
17 })
18
19 describe('Test retention stats on VOD', function () {
20 let vodVideoId: string
21
22 before(async function () {
23 this.timeout(60000);
24
25 ({ vodVideoId } = await prepareViewsVideos({ servers, live: false, vod: true }))
26 })
27
28 it('Should display empty retention', async function () {
29 const { data } = await servers[0].videoStats.getRetentionStats({ videoId: vodVideoId })
30 expect(data).to.have.lengthOf(6)
31
32 for (let i = 0; i < 6; i++) {
33 expect(data[i].second).to.equal(i)
34 expect(data[i].retentionPercent).to.equal(0)
35 }
36 })
37
38 it('Should display appropriate retention metrics', async function () {
39 await servers[0].views.simulateViewer({ xForwardedFor: '127.0.0.2,127.0.0.1', id: vodVideoId, currentTimes: [ 0, 1 ] })
40 await servers[0].views.simulateViewer({ xForwardedFor: '127.0.0.3,127.0.0.1', id: vodVideoId, currentTimes: [ 1, 3 ] })
41 await servers[1].views.simulateViewer({ xForwardedFor: '127.0.0.2,127.0.0.1', id: vodVideoId, currentTimes: [ 4 ] })
42 await servers[1].views.simulateViewer({ xForwardedFor: '127.0.0.3,127.0.0.1', id: vodVideoId, currentTimes: [ 0, 1 ] })
43
44 await processViewersStats(servers)
45
46 const { data } = await servers[0].videoStats.getRetentionStats({ videoId: vodVideoId })
47 expect(data).to.have.lengthOf(6)
48
49 expect(data.map(d => d.retentionPercent)).to.deep.equal([ 50, 75, 25, 25, 25, 0 ])
50 })
51 })
52
53 after(async function () {
54 await cleanupTests(servers)
55 })
56})