aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/models/video/video-channel.ts2
-rw-r--r--server/tests/api/videos/video-channels.ts44
-rw-r--r--shared/extra-utils/videos/video-channels.ts9
3 files changed, 48 insertions, 7 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 })
diff --git a/shared/extra-utils/videos/video-channels.ts b/shared/extra-utils/videos/video-channels.ts
index 51d433940..55f08b996 100644
--- a/shared/extra-utils/videos/video-channels.ts
+++ b/shared/extra-utils/videos/video-channels.ts
@@ -8,7 +8,7 @@ import { ServerInfo } from '../server/servers'
8import { User } from '../../models/users/user.model' 8import { User } from '../../models/users/user.model'
9import { getMyUserInformation } from '../users/users' 9import { getMyUserInformation } from '../users/users'
10 10
11function getVideoChannelsList (url: string, start: number, count: number, sort?: string) { 11function getVideoChannelsList (url: string, start: number, count: number, sort?: string, withStats?: boolean) {
12 const path = '/api/v1/video-channels' 12 const path = '/api/v1/video-channels'
13 13
14 const req = request(url) 14 const req = request(url)
@@ -17,6 +17,7 @@ function getVideoChannelsList (url: string, start: number, count: number, sort?:
17 .query({ count: count }) 17 .query({ count: count })
18 18
19 if (sort) req.query({ sort }) 19 if (sort) req.query({ sort })
20 if (withStats) req.query({ withStats })
20 21
21 return req.set('Accept', 'application/json') 22 return req.set('Accept', 'application/json')
22 .expect(200) 23 .expect(200)
@@ -30,8 +31,9 @@ function getAccountVideoChannelsList (parameters: {
30 count?: number 31 count?: number
31 sort?: string 32 sort?: string
32 specialStatus?: number 33 specialStatus?: number
34 withStats?: boolean
33}) { 35}) {
34 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200 } = parameters 36 const { url, accountName, start, count, sort = 'createdAt', specialStatus = 200, withStats = false } = parameters
35 37
36 const path = '/api/v1/accounts/' + accountName + '/video-channels' 38 const path = '/api/v1/accounts/' + accountName + '/video-channels'
37 39
@@ -41,7 +43,8 @@ function getAccountVideoChannelsList (parameters: {
41 query: { 43 query: {
42 start, 44 start,
43 count, 45 count,
44 sort 46 sort,
47 withStats
45 }, 48 },
46 statusCodeExpected: specialStatus 49 statusCodeExpected: specialStatus
47 }) 50 })