aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-channels.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/video-channels.ts')
-rw-r--r--server/tests/api/videos/video-channels.ts79
1 files changed, 59 insertions, 20 deletions
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 4f600cae8..876a6ab66 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -1,19 +1,21 @@
1/* tslint:disable:no-unused-expression */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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, ViewsPerDate, VideoDetails } from '../../../../shared/index'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createUser, 8 createUser,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, getVideo, 10 flushAndRunMultipleServers,
11 getVideo,
11 getVideoChannelVideos, 12 getVideoChannelVideos,
12 testImage, 13 testImage,
13 updateVideo, 14 updateVideo,
14 updateVideoChannelAvatar, 15 updateVideoChannelAvatar,
15 uploadVideo, 16 uploadVideo,
16 userLogin 17 userLogin,
18 wait
17} from '../../../../shared/extra-utils' 19} from '../../../../shared/extra-utils'
18import { 20import {
19 addVideoChannel, 21 addVideoChannel,
@@ -24,7 +26,8 @@ import {
24 getVideoChannelsList, 26 getVideoChannelsList,
25 ServerInfo, 27 ServerInfo,
26 setAccessTokensToServers, 28 setAccessTokensToServers,
27 updateVideoChannel 29 updateVideoChannel,
30 viewVideo
28} from '../../../../shared/extra-utils/index' 31} from '../../../../shared/extra-utils/index'
29import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 32import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
30 33
@@ -73,14 +76,14 @@ describe('Test video channels', function () {
73 description: 'super video channel description', 76 description: 'super video channel description',
74 support: 'super video channel support text' 77 support: 'super video channel support text'
75 } 78 }
76 const res = await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel) 79 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
77 secondVideoChannelId = res.body.videoChannel.id 80 secondVideoChannelId = res.body.videoChannel.id
78 } 81 }
79 82
80 // The channel is 1 is propagated to servers 2 83 // The channel is 1 is propagated to servers 2
81 { 84 {
82 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } 85 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
83 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributesArg) 86 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
84 videoUUID = res.body.video.uuid 87 videoUUID = res.body.video.uuid
85 } 88 }
86 89
@@ -106,7 +109,7 @@ describe('Test video channels', function () {
106 109
107 it('Should have two video channels when getting account channels on server 1', async function () { 110 it('Should have two video channels when getting account channels on server 1', async function () {
108 const res = await getAccountVideoChannelsList({ 111 const res = await getAccountVideoChannelsList({
109 url: servers[ 0 ].url, 112 url: servers[0].url,
110 accountName: userInfo.account.name + '@' + userInfo.account.host 113 accountName: userInfo.account.name + '@' + userInfo.account.host
111 }) 114 })
112 115
@@ -127,7 +130,7 @@ describe('Test video channels', function () {
127 it('Should paginate and sort account channels', async function () { 130 it('Should paginate and sort account channels', async function () {
128 { 131 {
129 const res = await getAccountVideoChannelsList({ 132 const res = await getAccountVideoChannelsList({
130 url: servers[ 0 ].url, 133 url: servers[0].url,
131 accountName: userInfo.account.name + '@' + userInfo.account.host, 134 accountName: userInfo.account.name + '@' + userInfo.account.host,
132 start: 0, 135 start: 0,
133 count: 1, 136 count: 1,
@@ -137,13 +140,13 @@ describe('Test video channels', function () {
137 expect(res.body.total).to.equal(2) 140 expect(res.body.total).to.equal(2)
138 expect(res.body.data).to.have.lengthOf(1) 141 expect(res.body.data).to.have.lengthOf(1)
139 142
140 const videoChannel: VideoChannel = res.body.data[ 0 ] 143 const videoChannel: VideoChannel = res.body.data[0]
141 expect(videoChannel.name).to.equal('root_channel') 144 expect(videoChannel.name).to.equal('root_channel')
142 } 145 }
143 146
144 { 147 {
145 const res = await getAccountVideoChannelsList({ 148 const res = await getAccountVideoChannelsList({
146 url: servers[ 0 ].url, 149 url: servers[0].url,
147 accountName: userInfo.account.name + '@' + userInfo.account.host, 150 accountName: userInfo.account.name + '@' + userInfo.account.host,
148 start: 0, 151 start: 0,
149 count: 1, 152 count: 1,
@@ -153,13 +156,13 @@ describe('Test video channels', function () {
153 expect(res.body.total).to.equal(2) 156 expect(res.body.total).to.equal(2)
154 expect(res.body.data).to.have.lengthOf(1) 157 expect(res.body.data).to.have.lengthOf(1)
155 158
156 const videoChannel: VideoChannel = res.body.data[ 0 ] 159 const videoChannel: VideoChannel = res.body.data[0]
157 expect(videoChannel.name).to.equal('second_video_channel') 160 expect(videoChannel.name).to.equal('second_video_channel')
158 } 161 }
159 162
160 { 163 {
161 const res = await getAccountVideoChannelsList({ 164 const res = await getAccountVideoChannelsList({
162 url: servers[ 0 ].url, 165 url: servers[0].url,
163 accountName: userInfo.account.name + '@' + userInfo.account.host, 166 accountName: userInfo.account.name + '@' + userInfo.account.host,
164 start: 1, 167 start: 1,
165 count: 1, 168 count: 1,
@@ -169,14 +172,14 @@ describe('Test video channels', function () {
169 expect(res.body.total).to.equal(2) 172 expect(res.body.total).to.equal(2)
170 expect(res.body.data).to.have.lengthOf(1) 173 expect(res.body.data).to.have.lengthOf(1)
171 174
172 const videoChannel: VideoChannel = res.body.data[ 0 ] 175 const videoChannel: VideoChannel = res.body.data[0]
173 expect(videoChannel.name).to.equal('root_channel') 176 expect(videoChannel.name).to.equal('root_channel')
174 } 177 }
175 }) 178 })
176 179
177 it('Should have one video channel when getting account channels on server 2', async function () { 180 it('Should have one video channel when getting account channels on server 2', async function () {
178 const res = await getAccountVideoChannelsList({ 181 const res = await getAccountVideoChannelsList({
179 url: servers[ 1 ].url, 182 url: servers[1].url,
180 accountName: userInfo.account.name + '@' + userInfo.account.host 183 accountName: userInfo.account.name + '@' + userInfo.account.host
181 }) 184 })
182 185
@@ -349,19 +352,55 @@ describe('Test video channels', function () {
349 it('Should create the main channel with an uuid if there is a conflict', async function () { 352 it('Should create the main channel with an uuid if there is a conflict', async function () {
350 { 353 {
351 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } 354 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
352 await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel) 355 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
353 } 356 }
354 357
355 { 358 {
356 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' }) 359 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
357 const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' }) 360 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' })
358 361
359 const res = await getMyUserInformation(servers[ 0 ].url, accessToken) 362 const res = await getMyUserInformation(servers[0].url, accessToken)
360 const videoChannel = res.body.videoChannels[ 0 ] 363 const videoChannel = res.body.videoChannels[0]
361 expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) 364 expect(videoChannel.name).to.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/)
362 } 365 }
363 }) 366 })
364 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: ViewsPerDate) => {
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
365 after(async function () { 404 after(async function () {
366 await cleanupTests(servers) 405 await cleanupTests(servers)
367 }) 406 })