1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 deleteVideoChannelImage,
10 flushAndRunMultipleServers,
13 getVideoChannelVideos,
16 updateVideoChannelImage,
20 } from '../../../../shared/extra-utils'
24 getAccountVideoChannelsList,
28 setAccessTokensToServers,
31 } from '../../../../shared/extra-utils/index'
32 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
33 import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
35 const expect = chai.expect
37 async function findChannel (server: ServerInfo, channelId: number) {
38 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
39 const videoChannel = res.body.data.find(c => c.id === channelId)
41 return videoChannel as VideoChannel
44 describe('Test video channels', function () {
45 let servers: ServerInfo[]
47 let firstVideoChannelId: number
48 let secondVideoChannelId: number
51 before(async function () {
54 servers = await flushAndRunMultipleServers(2)
56 await setAccessTokensToServers(servers)
57 await doubleFollow(servers[0], servers[1])
60 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
61 const user: User = res.body
63 firstVideoChannelId = user.videoChannels[0].id
66 await waitJobs(servers)
69 it('Should have one video channel (created with root)', async () => {
70 const res = await getVideoChannelsList(servers[0].url, 0, 2)
72 expect(res.body.total).to.equal(1)
73 expect(res.body.data).to.be.an('array')
74 expect(res.body.data).to.have.lengthOf(1)
77 it('Should create another video channel', async function () {
81 const videoChannel = {
82 name: 'second_video_channel',
83 displayName: 'second video channel',
84 description: 'super video channel description',
85 support: 'super video channel support text'
87 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
88 secondVideoChannelId = res.body.videoChannel.id
91 // The channel is 1 is propagated to servers 2
93 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
94 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
95 videoUUID = res.body.video.uuid
98 await waitJobs(servers)
101 it('Should have two video channels when getting my information', async () => {
102 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
105 expect(userInfo.videoChannels).to.be.an('array')
106 expect(userInfo.videoChannels).to.have.lengthOf(2)
108 const videoChannels = userInfo.videoChannels
109 expect(videoChannels[0].name).to.equal('root_channel')
110 expect(videoChannels[0].displayName).to.equal('Main root channel')
112 expect(videoChannels[1].name).to.equal('second_video_channel')
113 expect(videoChannels[1].displayName).to.equal('second video channel')
114 expect(videoChannels[1].description).to.equal('super video channel description')
115 expect(videoChannels[1].support).to.equal('super video channel support text')
118 it('Should have two video channels when getting account channels on server 1', async function () {
119 const res = await getAccountVideoChannelsList({
121 accountName: userInfo.account.name + '@' + userInfo.account.host
124 expect(res.body.total).to.equal(2)
125 expect(res.body.data).to.be.an('array')
126 expect(res.body.data).to.have.lengthOf(2)
128 const videoChannels = res.body.data
129 expect(videoChannels[0].name).to.equal('root_channel')
130 expect(videoChannels[0].displayName).to.equal('Main root channel')
132 expect(videoChannels[1].name).to.equal('second_video_channel')
133 expect(videoChannels[1].displayName).to.equal('second video channel')
134 expect(videoChannels[1].description).to.equal('super video channel description')
135 expect(videoChannels[1].support).to.equal('super video channel support text')
138 it('Should paginate and sort account channels', async function () {
140 const res = await getAccountVideoChannelsList({
142 accountName: userInfo.account.name + '@' + userInfo.account.host,
148 expect(res.body.total).to.equal(2)
149 expect(res.body.data).to.have.lengthOf(1)
151 const videoChannel: VideoChannel = res.body.data[0]
152 expect(videoChannel.name).to.equal('root_channel')
156 const res = await getAccountVideoChannelsList({
158 accountName: userInfo.account.name + '@' + userInfo.account.host,
164 expect(res.body.total).to.equal(2)
165 expect(res.body.data).to.have.lengthOf(1)
167 const videoChannel: VideoChannel = res.body.data[0]
168 expect(videoChannel.name).to.equal('second_video_channel')
172 const res = await getAccountVideoChannelsList({
174 accountName: userInfo.account.name + '@' + userInfo.account.host,
180 expect(res.body.total).to.equal(2)
181 expect(res.body.data).to.have.lengthOf(1)
183 const videoChannel: VideoChannel = res.body.data[0]
184 expect(videoChannel.name).to.equal('root_channel')
188 it('Should have one video channel when getting account channels on server 2', async function () {
189 const res = await getAccountVideoChannelsList({
191 accountName: userInfo.account.name + '@' + userInfo.account.host
194 expect(res.body.total).to.equal(1)
195 expect(res.body.data).to.be.an('array')
196 expect(res.body.data).to.have.lengthOf(1)
198 const videoChannels = res.body.data
199 expect(videoChannels[0].name).to.equal('second_video_channel')
200 expect(videoChannels[0].displayName).to.equal('second video channel')
201 expect(videoChannels[0].description).to.equal('super video channel description')
202 expect(videoChannels[0].support).to.equal('super video channel support text')
205 it('Should list video channels', async function () {
206 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
208 expect(res.body.total).to.equal(2)
209 expect(res.body.data).to.be.an('array')
210 expect(res.body.data).to.have.lengthOf(1)
211 expect(res.body.data[0].name).to.equal('root_channel')
212 expect(res.body.data[0].displayName).to.equal('Main root channel')
215 it('Should update video channel', async function () {
218 const videoChannelAttributes = {
219 displayName: 'video channel updated',
220 description: 'video channel description updated',
221 support: 'support updated'
224 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
226 await waitJobs(servers)
229 it('Should have video channel updated', async function () {
230 for (const server of servers) {
231 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
233 expect(res.body.total).to.equal(2)
234 expect(res.body.data).to.be.an('array')
235 expect(res.body.data).to.have.lengthOf(1)
236 expect(res.body.data[0].name).to.equal('second_video_channel')
237 expect(res.body.data[0].displayName).to.equal('video channel updated')
238 expect(res.body.data[0].description).to.equal('video channel description updated')
239 expect(res.body.data[0].support).to.equal('support updated')
243 it('Should not have updated the video support field', async function () {
244 for (const server of servers) {
245 const res = await getVideo(server.url, videoUUID)
246 const video: VideoDetails = res.body
248 expect(video.support).to.equal('video support field')
252 it('Should update the channel support field and update videos too', async function () {
255 const videoChannelAttributes = {
256 support: 'video channel support text updated',
257 bulkVideosSupportUpdate: true
260 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
262 await waitJobs(servers)
264 for (const server of servers) {
265 const res = await getVideo(server.url, videoUUID)
266 const video: VideoDetails = res.body
268 expect(video.support).to.equal(videoChannelAttributes.support)
272 it('Should update video channel avatar', async function () {
275 const fixture = 'avatar.png'
277 await updateVideoChannelImage({
279 accessToken: servers[0].accessToken,
280 videoChannelName: 'second_video_channel',
285 await waitJobs(servers)
287 for (const server of servers) {
288 const videoChannel = await findChannel(server, secondVideoChannelId)
290 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
294 it('Should update video channel banner', async function () {
297 const fixture = 'banner.jpg'
299 await updateVideoChannelImage({
301 accessToken: servers[0].accessToken,
302 videoChannelName: 'second_video_channel',
307 await waitJobs(servers)
309 for (const server of servers) {
310 const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host)
311 const videoChannel = res.body
313 await testImage(server.url, 'banner-resized', videoChannel.banner.path)
317 it('Should delete the video channel avatar', async function () {
320 await deleteVideoChannelImage({
322 accessToken: servers[0].accessToken,
323 videoChannelName: 'second_video_channel',
327 await waitJobs(servers)
329 for (const server of servers) {
330 const videoChannel = await findChannel(server, secondVideoChannelId)
332 expect(videoChannel.avatar).to.be.null
336 it('Should delete the video channel banner', async function () {
339 await deleteVideoChannelImage({
341 accessToken: servers[0].accessToken,
342 videoChannelName: 'second_video_channel',
346 await waitJobs(servers)
348 for (const server of servers) {
349 const videoChannel = await findChannel(server, secondVideoChannelId)
351 expect(videoChannel.banner).to.be.null
355 it('Should list the second video channel videos', async function () {
358 for (const server of servers) {
359 const channelURI = 'second_video_channel@localhost:' + servers[0].port
360 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
361 expect(res1.body.total).to.equal(1)
362 expect(res1.body.data).to.be.an('array')
363 expect(res1.body.data).to.have.lengthOf(1)
364 expect(res1.body.data[0].name).to.equal('my video name')
368 it('Should change the video channel of a video', async function () {
371 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
373 await waitJobs(servers)
376 it('Should list the first video channel videos', async function () {
379 for (const server of servers) {
380 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
381 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
382 expect(res1.body.total).to.equal(0)
384 const channelURI = 'root_channel@localhost:' + servers[0].port
385 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
386 expect(res2.body.total).to.equal(1)
388 const videos: Video[] = res2.body.data
389 expect(videos).to.be.an('array')
390 expect(videos).to.have.lengthOf(1)
391 expect(videos[0].name).to.equal('my video name')
395 it('Should delete video channel', async function () {
396 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
399 it('Should have video channel deleted', async function () {
400 const res = await getVideoChannelsList(servers[0].url, 0, 10)
402 expect(res.body.total).to.equal(1)
403 expect(res.body.data).to.be.an('array')
404 expect(res.body.data).to.have.lengthOf(1)
405 expect(res.body.data[0].displayName).to.equal('Main root channel')
408 it('Should create the main channel with an uuid if there is a conflict', async function () {
410 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
411 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
415 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
416 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' })
418 const res = await getMyUserInformation(servers[0].url, accessToken)
419 const videoChannel = res.body.videoChannels[0]
420 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}/)
424 it('Should report correct channel views per days', async function () {
428 const res = await getAccountVideoChannelsList({
430 accountName: userInfo.account.name + '@' + userInfo.account.host,
434 const channels: VideoChannel[] = res.body.data
436 for (const channel of channels) {
437 expect(channel).to.haveOwnProperty('viewsPerDay')
438 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
440 for (const v of channel.viewsPerDay) {
441 expect(v.date).to.be.an('string')
442 expect(v.views).to.equal(0)
448 // video has been posted on channel firstVideoChannelId since last update
449 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1')
450 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1')
452 // Wait the repeatable job
455 const res = await getAccountVideoChannelsList({
457 accountName: userInfo.account.name + '@' + userInfo.account.host,
460 const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId)
461 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2)
465 it('Should report correct videos count', async function () {
466 const res = await getAccountVideoChannelsList({
468 accountName: userInfo.account.name + '@' + userInfo.account.host,
471 const channels: VideoChannel[] = res.body.data
473 const totoChannel = channels.find(c => c.name === 'toto_channel')
474 const rootChannel = channels.find(c => c.name === 'root_channel')
476 expect(rootChannel.videosCount).to.equal(1)
477 expect(totoChannel.videosCount).to.equal(0)
480 it('Should search among account video channels', async function () {
482 const res = await getAccountVideoChannelsList({
484 accountName: userInfo.account.name + '@' + userInfo.account.host,
487 expect(res.body.total).to.equal(1)
489 const channels = res.body.data
490 expect(channels).to.have.lengthOf(1)
494 const res = await getAccountVideoChannelsList({
496 accountName: userInfo.account.name + '@' + userInfo.account.host,
497 search: 'does not exist'
499 expect(res.body.total).to.equal(0)
501 const channels = res.body.data
502 expect(channels).to.have.lengthOf(0)
506 after(async function () {
507 await cleanupTests(servers)