X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fvideos%2Fvideo-channels.ts;h=876a6ab66381e92afc615a28684e0efeb8936d86;hb=610d0be13b3d01f653ef269271dd667a57c85ef2;hp=f3a23bf17127aa967ced09cbd9c10c58a53a22c6;hpb=a15871560f80e07386c1dabb8370cd2664ecfd1f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index f3a23bf17..876a6ab66 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -2,7 +2,7 @@ import * as chai from 'chai' import 'mocha' -import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' +import { User, Video, VideoChannel, ViewsPerDate, VideoDetails } from '../../../../shared/index' import { cleanupTests, createUser, @@ -14,7 +14,8 @@ import { updateVideo, updateVideoChannelAvatar, uploadVideo, - userLogin + userLogin, + wait } from '../../../../shared/extra-utils' import { addVideoChannel, @@ -25,7 +26,8 @@ import { getVideoChannelsList, ServerInfo, setAccessTokensToServers, - updateVideoChannel + updateVideoChannel, + viewVideo } from '../../../../shared/extra-utils/index' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' @@ -363,6 +365,42 @@ describe('Test video channels', function () { } }) + it('Should report correct channel statistics', async function () { + + { + const res = await getAccountVideoChannelsList({ + url: servers[0].url, + accountName: userInfo.account.name + '@' + userInfo.account.host, + withStats: true + }) + res.body.data.forEach((channel: VideoChannel) => { + expect(channel).to.haveOwnProperty('viewsPerDay') + expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today + channel.viewsPerDay.forEach((v: ViewsPerDate) => { + expect(v.date).to.be.an('string') + expect(v.views).to.equal(0) + }) + }) + } + + { + // video has been posted on channel firstVideoChannelId since last update + await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') + await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') + + // Wait the repeatable job + await wait(8000) + + const res = await getAccountVideoChannelsList({ + url: servers[0].url, + accountName: userInfo.account.name + '@' + userInfo.account.host, + withStats: true + }) + const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId) + expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) + } + }) + after(async function () { await cleanupTests(servers) })