diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2020-03-27 22:26:39 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-03-31 10:29:24 +0200 |
commit | 714bfcc556177dce2b65a1e58babdf2488e9de13 (patch) | |
tree | 35d5d14c03756bc239ce91d52ca9051dd34f80c4 /server/tests/api/videos | |
parent | 747c562837e37f2fa455e8ef62165e9bb4e365f1 (diff) | |
download | PeerTube-714bfcc556177dce2b65a1e58babdf2488e9de13.tar.gz PeerTube-714bfcc556177dce2b65a1e58babdf2488e9de13.tar.zst PeerTube-714bfcc556177dce2b65a1e58babdf2488e9de13.zip |
Tests for viewsPerDay
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r-- | server/tests/api/videos/video-channels.ts | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index f3a23bf17..bde45584d 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' | 5 | import { User, Video, VideoChannel, viewsPerTime, VideoDetails } from '../../../../shared/index' |
6 | import { | 6 | import { |
7 | cleanupTests, | 7 | cleanupTests, |
8 | createUser, | 8 | createUser, |
@@ -14,7 +14,8 @@ import { | |||
14 | updateVideo, | 14 | updateVideo, |
15 | updateVideoChannelAvatar, | 15 | updateVideoChannelAvatar, |
16 | uploadVideo, | 16 | uploadVideo, |
17 | userLogin | 17 | userLogin, |
18 | wait | ||
18 | } from '../../../../shared/extra-utils' | 19 | } from '../../../../shared/extra-utils' |
19 | import { | 20 | import { |
20 | addVideoChannel, | 21 | addVideoChannel, |
@@ -25,7 +26,8 @@ import { | |||
25 | getVideoChannelsList, | 26 | getVideoChannelsList, |
26 | ServerInfo, | 27 | ServerInfo, |
27 | setAccessTokensToServers, | 28 | setAccessTokensToServers, |
28 | updateVideoChannel | 29 | updateVideoChannel, |
30 | viewVideo | ||
29 | } from '../../../../shared/extra-utils/index' | 31 | } from '../../../../shared/extra-utils/index' |
30 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 32 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
31 | 33 | ||
@@ -363,6 +365,42 @@ describe('Test video channels', function () { | |||
363 | } | 365 | } |
364 | }) | 366 | }) |
365 | 367 | ||
368 | it('Should report correct channel statistics', async function () { | ||
369 | |||
370 | { | ||
371 | const res = await getAccountVideoChannelsList({ | ||
372 | url: servers[0].url, | ||
373 | accountName: userInfo.account.name + '@' + userInfo.account.host, | ||
374 | withStats: true | ||
375 | }) | ||
376 | res.body.data.forEach((channel: VideoChannel) => { | ||
377 | expect(channel).to.haveOwnProperty('viewsPerDay') | ||
378 | expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today | ||
379 | channel.viewsPerDay.forEach((v: viewsPerTime) => { | ||
380 | expect(v.date).to.be.an('string') | ||
381 | expect(v.views).to.equal(0) | ||
382 | }) | ||
383 | }) | ||
384 | } | ||
385 | |||
386 | { | ||
387 | // video has been posted on channel firstVideoChannelId since last update | ||
388 | await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') | ||
389 | await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') | ||
390 | |||
391 | // Wait the repeatable job | ||
392 | await wait(8000) | ||
393 | |||
394 | const res = await getAccountVideoChannelsList({ | ||
395 | url: servers[0].url, | ||
396 | accountName: userInfo.account.name + '@' + userInfo.account.host, | ||
397 | withStats: true | ||
398 | }) | ||
399 | const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId) | ||
400 | expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) | ||
401 | } | ||
402 | }) | ||
403 | |||
366 | after(async function () { | 404 | after(async function () { |
367 | await cleanupTests(servers) | 405 | await cleanupTests(servers) |
368 | }) | 406 | }) |