diff options
author | Chocobozzz <me@florianbigard.com> | 2022-03-24 13:36:47 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2022-04-15 09:49:35 +0200 |
commit | b211106695bb82f6c32e53306081b5262c3d109d (patch) | |
tree | fa187de1c33b0956665f5362e29af6b0f6d8bb57 /server/tests/api/views/video-views-retention-stats.ts | |
parent | 69d48ee30c9d47cddf0c3c047dc99a99dcb6e894 (diff) | |
download | PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.gz PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.tar.zst PeerTube-b211106695bb82f6c32e53306081b5262c3d109d.zip |
Support video views/viewers stats in server
* Add "currentTime" and "event" body params to view endpoint
* Merge watching and view endpoints
* Introduce WatchAction AP activity
* Add tables to store viewer information of local videos
* Add endpoints to fetch video views/viewers stats of local videos
* Refactor views/viewers handlers
* Support "views" and "viewers" counters for both VOD and live videos
Diffstat (limited to 'server/tests/api/views/video-views-retention-stats.ts')
-rw-r--r-- | server/tests/api/views/video-views-retention-stats.ts | 56 |
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 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { prepareViewsServers, prepareViewsVideos, processViewersStats } from '@server/tests/shared' | ||
6 | import { cleanupTests, PeerTubeServer } from '@shared/server-commands' | ||
7 | |||
8 | const expect = chai.expect | ||
9 | |||
10 | describe('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 | }) | ||