1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 deleteVideoChannelImage,
10 flushAndRunMultipleServers,
12 getVideoChannelVideos,
15 updateVideoChannelImage,
19 } from '../../../../shared/extra-utils'
23 getAccountVideoChannelsList,
27 setAccessTokensToServers,
30 } from '../../../../shared/extra-utils/index'
31 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
32 import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
34 const expect = chai.expect
36 async function findChannel (server: ServerInfo, channelId: number) {
37 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
38 const videoChannel = res.body.data.find(c => c.id === channelId)
40 return videoChannel as VideoChannel
43 describe('Test video channels', function () {
44 let servers: ServerInfo[]
46 let firstVideoChannelId: number
47 let secondVideoChannelId: number
50 before(async function () {
53 servers = await flushAndRunMultipleServers(2)
55 await setAccessTokensToServers(servers)
56 await doubleFollow(servers[0], servers[1])
59 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
60 const user: User = res.body
62 firstVideoChannelId = user.videoChannels[0].id
65 await waitJobs(servers)
68 it('Should have one video channel (created with root)', async () => {
69 const res = await getVideoChannelsList(servers[0].url, 0, 2)
71 expect(res.body.total).to.equal(1)
72 expect(res.body.data).to.be.an('array')
73 expect(res.body.data).to.have.lengthOf(1)
76 it('Should create another video channel', async function () {
80 const videoChannel = {
81 name: 'second_video_channel',
82 displayName: 'second video channel',
83 description: 'super video channel description',
84 support: 'super video channel support text'
86 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
87 secondVideoChannelId = res.body.videoChannel.id
90 // The channel is 1 is propagated to servers 2
92 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
93 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
94 videoUUID = res.body.video.uuid
97 await waitJobs(servers)
100 it('Should have two video channels when getting my information', async () => {
101 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
104 expect(userInfo.videoChannels).to.be.an('array')
105 expect(userInfo.videoChannels).to.have.lengthOf(2)
107 const videoChannels = userInfo.videoChannels
108 expect(videoChannels[0].name).to.equal('root_channel')
109 expect(videoChannels[0].displayName).to.equal('Main root channel')
111 expect(videoChannels[1].name).to.equal('second_video_channel')
112 expect(videoChannels[1].displayName).to.equal('second video channel')
113 expect(videoChannels[1].description).to.equal('super video channel description')
114 expect(videoChannels[1].support).to.equal('super video channel support text')
117 it('Should have two video channels when getting account channels on server 1', async function () {
118 const res = await getAccountVideoChannelsList({
120 accountName: userInfo.account.name + '@' + userInfo.account.host
123 expect(res.body.total).to.equal(2)
124 expect(res.body.data).to.be.an('array')
125 expect(res.body.data).to.have.lengthOf(2)
127 const videoChannels = res.body.data
128 expect(videoChannels[0].name).to.equal('root_channel')
129 expect(videoChannels[0].displayName).to.equal('Main root channel')
131 expect(videoChannels[1].name).to.equal('second_video_channel')
132 expect(videoChannels[1].displayName).to.equal('second video channel')
133 expect(videoChannels[1].description).to.equal('super video channel description')
134 expect(videoChannels[1].support).to.equal('super video channel support text')
137 it('Should paginate and sort account channels', async function () {
139 const res = await getAccountVideoChannelsList({
141 accountName: userInfo.account.name + '@' + userInfo.account.host,
147 expect(res.body.total).to.equal(2)
148 expect(res.body.data).to.have.lengthOf(1)
150 const videoChannel: VideoChannel = res.body.data[0]
151 expect(videoChannel.name).to.equal('root_channel')
155 const res = await getAccountVideoChannelsList({
157 accountName: userInfo.account.name + '@' + userInfo.account.host,
163 expect(res.body.total).to.equal(2)
164 expect(res.body.data).to.have.lengthOf(1)
166 const videoChannel: VideoChannel = res.body.data[0]
167 expect(videoChannel.name).to.equal('second_video_channel')
171 const res = await getAccountVideoChannelsList({
173 accountName: userInfo.account.name + '@' + userInfo.account.host,
179 expect(res.body.total).to.equal(2)
180 expect(res.body.data).to.have.lengthOf(1)
182 const videoChannel: VideoChannel = res.body.data[0]
183 expect(videoChannel.name).to.equal('root_channel')
187 it('Should have one video channel when getting account channels on server 2', async function () {
188 const res = await getAccountVideoChannelsList({
190 accountName: userInfo.account.name + '@' + userInfo.account.host
193 expect(res.body.total).to.equal(1)
194 expect(res.body.data).to.be.an('array')
195 expect(res.body.data).to.have.lengthOf(1)
197 const videoChannels = res.body.data
198 expect(videoChannels[0].name).to.equal('second_video_channel')
199 expect(videoChannels[0].displayName).to.equal('second video channel')
200 expect(videoChannels[0].description).to.equal('super video channel description')
201 expect(videoChannels[0].support).to.equal('super video channel support text')
204 it('Should list video channels', async function () {
205 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
207 expect(res.body.total).to.equal(2)
208 expect(res.body.data).to.be.an('array')
209 expect(res.body.data).to.have.lengthOf(1)
210 expect(res.body.data[0].name).to.equal('root_channel')
211 expect(res.body.data[0].displayName).to.equal('Main root channel')
214 it('Should update video channel', async function () {
217 const videoChannelAttributes = {
218 displayName: 'video channel updated',
219 description: 'video channel description updated',
220 support: 'support updated'
223 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
225 await waitJobs(servers)
228 it('Should have video channel updated', async function () {
229 for (const server of servers) {
230 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
232 expect(res.body.total).to.equal(2)
233 expect(res.body.data).to.be.an('array')
234 expect(res.body.data).to.have.lengthOf(1)
235 expect(res.body.data[0].name).to.equal('second_video_channel')
236 expect(res.body.data[0].displayName).to.equal('video channel updated')
237 expect(res.body.data[0].description).to.equal('video channel description updated')
238 expect(res.body.data[0].support).to.equal('support updated')
242 it('Should not have updated the video support field', async function () {
243 for (const server of servers) {
244 const res = await getVideo(server.url, videoUUID)
245 const video: VideoDetails = res.body
247 expect(video.support).to.equal('video support field')
251 it('Should update the channel support field and update videos too', async function () {
254 const videoChannelAttributes = {
255 support: 'video channel support text updated',
256 bulkVideosSupportUpdate: true
259 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
261 await waitJobs(servers)
263 for (const server of servers) {
264 const res = await getVideo(server.url, videoUUID)
265 const video: VideoDetails = res.body
267 expect(video.support).to.equal(videoChannelAttributes.support)
271 it('Should update video channel avatar', async function () {
274 const fixture = 'avatar.png'
276 await updateVideoChannelImage({
278 accessToken: servers[0].accessToken,
279 videoChannelName: 'second_video_channel',
284 await waitJobs(servers)
286 for (const server of servers) {
287 const videoChannel = await findChannel(server, secondVideoChannelId)
289 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
293 it('Should update video channel banner', async function () {
296 const fixture = 'banner.jpg'
298 await updateVideoChannelImage({
300 accessToken: servers[0].accessToken,
301 videoChannelName: 'second_video_channel',
306 await waitJobs(servers)
308 for (const server of servers) {
309 const videoChannel = await findChannel(server, secondVideoChannelId)
311 await testImage(server.url, 'banner-resized', videoChannel.banner.path)
315 it('Should delete the video channel avatar', async function () {
318 await deleteVideoChannelImage({
320 accessToken: servers[0].accessToken,
321 videoChannelName: 'second_video_channel',
325 await waitJobs(servers)
327 for (const server of servers) {
328 const videoChannel = await findChannel(server, secondVideoChannelId)
330 expect(videoChannel.avatar).to.be.null
334 it('Should delete the video channel banner', async function () {
337 await deleteVideoChannelImage({
339 accessToken: servers[0].accessToken,
340 videoChannelName: 'second_video_channel',
344 await waitJobs(servers)
346 for (const server of servers) {
347 const videoChannel = await findChannel(server, secondVideoChannelId)
349 expect(videoChannel.banner).to.be.null
353 it('Should list the second video channel videos', async function () {
356 for (const server of servers) {
357 const channelURI = 'second_video_channel@localhost:' + servers[0].port
358 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
359 expect(res1.body.total).to.equal(1)
360 expect(res1.body.data).to.be.an('array')
361 expect(res1.body.data).to.have.lengthOf(1)
362 expect(res1.body.data[0].name).to.equal('my video name')
366 it('Should change the video channel of a video', async function () {
369 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
371 await waitJobs(servers)
374 it('Should list the first video channel videos', async function () {
377 for (const server of servers) {
378 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
379 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
380 expect(res1.body.total).to.equal(0)
382 const channelURI = 'root_channel@localhost:' + servers[0].port
383 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
384 expect(res2.body.total).to.equal(1)
386 const videos: Video[] = res2.body.data
387 expect(videos).to.be.an('array')
388 expect(videos).to.have.lengthOf(1)
389 expect(videos[0].name).to.equal('my video name')
393 it('Should delete video channel', async function () {
394 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
397 it('Should have video channel deleted', async function () {
398 const res = await getVideoChannelsList(servers[0].url, 0, 10)
400 expect(res.body.total).to.equal(1)
401 expect(res.body.data).to.be.an('array')
402 expect(res.body.data).to.have.lengthOf(1)
403 expect(res.body.data[0].displayName).to.equal('Main root channel')
406 it('Should create the main channel with an uuid if there is a conflict', async function () {
408 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
409 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
413 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
414 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' })
416 const res = await getMyUserInformation(servers[0].url, accessToken)
417 const videoChannel = res.body.videoChannels[0]
418 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}/)
422 it('Should report correct channel views per days', async function () {
426 const res = await getAccountVideoChannelsList({
428 accountName: userInfo.account.name + '@' + userInfo.account.host,
432 const channels: VideoChannel[] = res.body.data
434 for (const channel of channels) {
435 expect(channel).to.haveOwnProperty('viewsPerDay')
436 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
438 for (const v of channel.viewsPerDay) {
439 expect(v.date).to.be.an('string')
440 expect(v.views).to.equal(0)
446 // video has been posted on channel firstVideoChannelId since last update
447 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1')
448 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1')
450 // Wait the repeatable job
453 const res = await getAccountVideoChannelsList({
455 accountName: userInfo.account.name + '@' + userInfo.account.host,
458 const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId)
459 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2)
463 it('Should report correct videos count', async function () {
464 const res = await getAccountVideoChannelsList({
466 accountName: userInfo.account.name + '@' + userInfo.account.host,
469 const channels: VideoChannel[] = res.body.data
471 const totoChannel = channels.find(c => c.name === 'toto_channel')
472 const rootChannel = channels.find(c => c.name === 'root_channel')
474 expect(rootChannel.videosCount).to.equal(1)
475 expect(totoChannel.videosCount).to.equal(0)
478 it('Should search among account video channels', async function () {
480 const res = await getAccountVideoChannelsList({
482 accountName: userInfo.account.name + '@' + userInfo.account.host,
485 expect(res.body.total).to.equal(1)
487 const channels = res.body.data
488 expect(channels).to.have.lengthOf(1)
492 const res = await getAccountVideoChannelsList({
494 accountName: userInfo.account.name + '@' + userInfo.account.host,
495 search: 'does not exist'
497 expect(res.body.total).to.equal(0)
499 const channels = res.body.data
500 expect(channels).to.have.lengthOf(0)
504 after(async function () {
505 await cleanupTests(servers)