1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { basename } from 'path'
9 deleteVideoChannelImage,
11 flushAndRunMultipleServers,
15 getVideoChannelVideos,
18 updateVideoChannelImage,
22 } from '../../../../shared/extra-utils'
26 getAccountVideoChannelsList,
30 setAccessTokensToServers,
33 } from '../../../../shared/extra-utils/index'
34 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
35 import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
36 import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
38 const expect = chai.expect
40 async function findChannel (server: ServerInfo, channelId: number) {
41 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
42 const videoChannel = res.body.data.find(c => c.id === channelId)
44 return videoChannel as VideoChannel
47 describe('Test video channels', function () {
48 let servers: ServerInfo[]
50 let firstVideoChannelId: number
51 let secondVideoChannelId: number
54 before(async function () {
57 servers = await flushAndRunMultipleServers(2)
59 await setAccessTokensToServers(servers)
60 await doubleFollow(servers[0], servers[1])
63 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
64 const user: User = res.body
66 firstVideoChannelId = user.videoChannels[0].id
69 await waitJobs(servers)
72 it('Should have one video channel (created with root)', async () => {
73 const res = await getVideoChannelsList(servers[0].url, 0, 2)
75 expect(res.body.total).to.equal(1)
76 expect(res.body.data).to.be.an('array')
77 expect(res.body.data).to.have.lengthOf(1)
80 it('Should create another video channel', async function () {
84 const videoChannel = {
85 name: 'second_video_channel',
86 displayName: 'second video channel',
87 description: 'super video channel description',
88 support: 'super video channel support text'
90 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
91 secondVideoChannelId = res.body.videoChannel.id
94 // The channel is 1 is propagated to servers 2
96 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
97 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
98 videoUUID = res.body.video.uuid
101 await waitJobs(servers)
104 it('Should have two video channels when getting my information', async () => {
105 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
108 expect(userInfo.videoChannels).to.be.an('array')
109 expect(userInfo.videoChannels).to.have.lengthOf(2)
111 const videoChannels = userInfo.videoChannels
112 expect(videoChannels[0].name).to.equal('root_channel')
113 expect(videoChannels[0].displayName).to.equal('Main root channel')
115 expect(videoChannels[1].name).to.equal('second_video_channel')
116 expect(videoChannels[1].displayName).to.equal('second video channel')
117 expect(videoChannels[1].description).to.equal('super video channel description')
118 expect(videoChannels[1].support).to.equal('super video channel support text')
121 it('Should have two video channels when getting account channels on server 1', async function () {
122 const res = await getAccountVideoChannelsList({
124 accountName: userInfo.account.name + '@' + userInfo.account.host
127 expect(res.body.total).to.equal(2)
128 expect(res.body.data).to.be.an('array')
129 expect(res.body.data).to.have.lengthOf(2)
131 const videoChannels = res.body.data
132 expect(videoChannels[0].name).to.equal('root_channel')
133 expect(videoChannels[0].displayName).to.equal('Main root channel')
135 expect(videoChannels[1].name).to.equal('second_video_channel')
136 expect(videoChannels[1].displayName).to.equal('second video channel')
137 expect(videoChannels[1].description).to.equal('super video channel description')
138 expect(videoChannels[1].support).to.equal('super video channel support text')
141 it('Should paginate and sort account channels', async function () {
143 const res = await getAccountVideoChannelsList({
145 accountName: userInfo.account.name + '@' + userInfo.account.host,
151 expect(res.body.total).to.equal(2)
152 expect(res.body.data).to.have.lengthOf(1)
154 const videoChannel: VideoChannel = res.body.data[0]
155 expect(videoChannel.name).to.equal('root_channel')
159 const res = await getAccountVideoChannelsList({
161 accountName: userInfo.account.name + '@' + userInfo.account.host,
167 expect(res.body.total).to.equal(2)
168 expect(res.body.data).to.have.lengthOf(1)
170 const videoChannel: VideoChannel = res.body.data[0]
171 expect(videoChannel.name).to.equal('second_video_channel')
175 const res = await getAccountVideoChannelsList({
177 accountName: userInfo.account.name + '@' + userInfo.account.host,
183 expect(res.body.total).to.equal(2)
184 expect(res.body.data).to.have.lengthOf(1)
186 const videoChannel: VideoChannel = res.body.data[0]
187 expect(videoChannel.name).to.equal('root_channel')
191 it('Should have one video channel when getting account channels on server 2', async function () {
192 const res = await getAccountVideoChannelsList({
194 accountName: userInfo.account.name + '@' + userInfo.account.host
197 expect(res.body.total).to.equal(1)
198 expect(res.body.data).to.be.an('array')
199 expect(res.body.data).to.have.lengthOf(1)
201 const videoChannels = res.body.data
202 expect(videoChannels[0].name).to.equal('second_video_channel')
203 expect(videoChannels[0].displayName).to.equal('second video channel')
204 expect(videoChannels[0].description).to.equal('super video channel description')
205 expect(videoChannels[0].support).to.equal('super video channel support text')
208 it('Should list video channels', async function () {
209 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
211 expect(res.body.total).to.equal(2)
212 expect(res.body.data).to.be.an('array')
213 expect(res.body.data).to.have.lengthOf(1)
214 expect(res.body.data[0].name).to.equal('root_channel')
215 expect(res.body.data[0].displayName).to.equal('Main root channel')
218 it('Should update video channel', async function () {
221 const videoChannelAttributes = {
222 displayName: 'video channel updated',
223 description: 'video channel description updated',
224 support: 'support updated'
227 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
229 await waitJobs(servers)
232 it('Should have video channel updated', async function () {
233 for (const server of servers) {
234 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
236 expect(res.body.total).to.equal(2)
237 expect(res.body.data).to.be.an('array')
238 expect(res.body.data).to.have.lengthOf(1)
239 expect(res.body.data[0].name).to.equal('second_video_channel')
240 expect(res.body.data[0].displayName).to.equal('video channel updated')
241 expect(res.body.data[0].description).to.equal('video channel description updated')
242 expect(res.body.data[0].support).to.equal('support updated')
246 it('Should not have updated the video support field', async function () {
247 for (const server of servers) {
248 const res = await getVideo(server.url, videoUUID)
249 const video: VideoDetails = res.body
251 expect(video.support).to.equal('video support field')
255 it('Should update the channel support field and update videos too', async function () {
258 const videoChannelAttributes = {
259 support: 'video channel support text updated',
260 bulkVideosSupportUpdate: true
263 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
265 await waitJobs(servers)
267 for (const server of servers) {
268 const res = await getVideo(server.url, videoUUID)
269 const video: VideoDetails = res.body
271 expect(video.support).to.equal(videoChannelAttributes.support)
275 it('Should update video channel avatar', async function () {
278 const fixture = 'avatar.png'
280 await updateVideoChannelImage({
282 accessToken: servers[0].accessToken,
283 videoChannelName: 'second_video_channel',
288 await waitJobs(servers)
290 for (const server of servers) {
291 const videoChannel = await findChannel(server, secondVideoChannelId)
293 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
295 const row = await getActorImage(server.internalServerNumber, basename(videoChannel.avatar.path))
296 expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height)
297 expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width)
301 it('Should update video channel banner', async function () {
304 const fixture = 'banner.jpg'
306 await updateVideoChannelImage({
308 accessToken: servers[0].accessToken,
309 videoChannelName: 'second_video_channel',
314 await waitJobs(servers)
316 for (const server of servers) {
317 const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host)
318 const videoChannel = res.body
320 await testImage(server.url, 'banner-resized', videoChannel.banner.path)
322 const row = await getActorImage(server.internalServerNumber, basename(videoChannel.banner.path))
323 expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height)
324 expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width)
328 it('Should delete the video channel avatar', async function () {
331 await deleteVideoChannelImage({
333 accessToken: servers[0].accessToken,
334 videoChannelName: 'second_video_channel',
338 await waitJobs(servers)
340 for (const server of servers) {
341 const videoChannel = await findChannel(server, secondVideoChannelId)
343 expect(videoChannel.avatar).to.be.null
347 it('Should delete the video channel banner', async function () {
350 await deleteVideoChannelImage({
352 accessToken: servers[0].accessToken,
353 videoChannelName: 'second_video_channel',
357 await waitJobs(servers)
359 for (const server of servers) {
360 const videoChannel = await findChannel(server, secondVideoChannelId)
362 expect(videoChannel.banner).to.be.null
366 it('Should list the second video channel videos', async function () {
369 for (const server of servers) {
370 const channelURI = 'second_video_channel@localhost:' + servers[0].port
371 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
372 expect(res1.body.total).to.equal(1)
373 expect(res1.body.data).to.be.an('array')
374 expect(res1.body.data).to.have.lengthOf(1)
375 expect(res1.body.data[0].name).to.equal('my video name')
379 it('Should change the video channel of a video', async function () {
382 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
384 await waitJobs(servers)
387 it('Should list the first video channel videos', async function () {
390 for (const server of servers) {
391 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
392 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
393 expect(res1.body.total).to.equal(0)
395 const channelURI = 'root_channel@localhost:' + servers[0].port
396 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
397 expect(res2.body.total).to.equal(1)
399 const videos: Video[] = res2.body.data
400 expect(videos).to.be.an('array')
401 expect(videos).to.have.lengthOf(1)
402 expect(videos[0].name).to.equal('my video name')
406 it('Should delete video channel', async function () {
407 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
410 it('Should have video channel deleted', async function () {
411 const res = await getVideoChannelsList(servers[0].url, 0, 10)
413 expect(res.body.total).to.equal(1)
414 expect(res.body.data).to.be.an('array')
415 expect(res.body.data).to.have.lengthOf(1)
416 expect(res.body.data[0].displayName).to.equal('Main root channel')
419 it('Should create the main channel with an uuid if there is a conflict', async function () {
421 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
422 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
426 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
427 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' })
429 const res = await getMyUserInformation(servers[0].url, accessToken)
430 const videoChannel = res.body.videoChannels[0]
431 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}/)
435 it('Should report correct channel views per days', async function () {
439 const res = await getAccountVideoChannelsList({
441 accountName: userInfo.account.name + '@' + userInfo.account.host,
445 const channels: VideoChannel[] = res.body.data
447 for (const channel of channels) {
448 expect(channel).to.haveOwnProperty('viewsPerDay')
449 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
451 for (const v of channel.viewsPerDay) {
452 expect(v.date).to.be.an('string')
453 expect(v.views).to.equal(0)
459 // video has been posted on channel firstVideoChannelId since last update
460 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1')
461 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1')
463 // Wait the repeatable job
466 const res = await getAccountVideoChannelsList({
468 accountName: userInfo.account.name + '@' + userInfo.account.host,
471 const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId)
472 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2)
476 it('Should report correct videos count', async function () {
477 const res = await getAccountVideoChannelsList({
479 accountName: userInfo.account.name + '@' + userInfo.account.host,
482 const channels: VideoChannel[] = res.body.data
484 const totoChannel = channels.find(c => c.name === 'toto_channel')
485 const rootChannel = channels.find(c => c.name === 'root_channel')
487 expect(rootChannel.videosCount).to.equal(1)
488 expect(totoChannel.videosCount).to.equal(0)
491 it('Should search among account video channels', async function () {
493 const res = await getAccountVideoChannelsList({
495 accountName: userInfo.account.name + '@' + userInfo.account.host,
498 expect(res.body.total).to.equal(1)
500 const channels = res.body.data
501 expect(channels).to.have.lengthOf(1)
505 const res = await getAccountVideoChannelsList({
507 accountName: userInfo.account.name + '@' + userInfo.account.host,
508 search: 'does not exist'
510 expect(res.body.total).to.equal(0)
512 const channels = res.body.data
513 expect(channels).to.have.lengthOf(0)
517 after(async function () {
518 await cleanupTests(servers)