aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-03-27 22:26:39 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-03-31 10:29:24 +0200
commit714bfcc556177dce2b65a1e58babdf2488e9de13 (patch)
tree35d5d14c03756bc239ce91d52ca9051dd34f80c4 /server
parent747c562837e37f2fa455e8ef62165e9bb4e365f1 (diff)
downloadPeerTube-714bfcc556177dce2b65a1e58babdf2488e9de13.tar.gz
PeerTube-714bfcc556177dce2b65a1e58babdf2488e9de13.tar.zst
PeerTube-714bfcc556177dce2b65a1e58babdf2488e9de13.zip
Tests for viewsPerDay
Diffstat (limited to 'server')
-rw-r--r--server/models/video/video-channel.ts2
-rw-r--r--server/tests/api/videos/video-channels.ts44
2 files changed, 42 insertions, 4 deletions
diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts
index 5e6541837..78fc3d7e4 100644
--- a/server/models/video/video-channel.ts
+++ b/server/models/video/video-channel.ts
@@ -191,7 +191,7 @@ export type SummaryOptions = {
191 'SELECT days.day AS day, ' + 191 'SELECT days.day AS day, ' +
192 'COALESCE(SUM(views.views), 0) AS views ' + 192 'COALESCE(SUM(views.views), 0) AS views ' +
193 'FROM days ' + 193 'FROM days ' +
194 `LEFT JOIN views ON date_trunc('day', "views"."createdAt") = days.day ` + 194 `LEFT JOIN views ON date_trunc('day', "views"."startDate") = date_trunc('day', days.day) ` +
195 'GROUP BY 1 ' + 195 'GROUP BY 1 ' +
196 'ORDER BY day ' + 196 'ORDER BY day ' +
197 ') t' + 197 ') t' +
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
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' 5import { User, Video, VideoChannel, viewsPerTime, VideoDetails } from '../../../../shared/index'
6import { 6import {
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'
19import { 20import {
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'
30import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 32import { 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 })