1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
9 flushAndRunMultipleServers,
11 getVideoChannelVideos,
14 updateVideoChannelAvatar,
18 } from '../../../../shared/extra-utils'
22 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 describe('Test video channels', function () {
37 let servers: ServerInfo[]
39 let firstVideoChannelId: number
40 let secondVideoChannelId: number
43 before(async function () {
46 servers = await flushAndRunMultipleServers(2)
48 await setAccessTokensToServers(servers)
49 await doubleFollow(servers[0], servers[1])
52 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
53 const user: User = res.body
55 firstVideoChannelId = user.videoChannels[0].id
58 await waitJobs(servers)
61 it('Should have one video channel (created with root)', async () => {
62 const res = await getVideoChannelsList(servers[0].url, 0, 2)
64 expect(res.body.total).to.equal(1)
65 expect(res.body.data).to.be.an('array')
66 expect(res.body.data).to.have.lengthOf(1)
69 it('Should create another video channel', async function () {
73 const videoChannel = {
74 name: 'second_video_channel',
75 displayName: 'second video channel',
76 description: 'super video channel description',
77 support: 'super video channel support text'
79 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
80 secondVideoChannelId = res.body.videoChannel.id
83 // The channel is 1 is propagated to servers 2
85 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
86 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
87 videoUUID = res.body.video.uuid
90 await waitJobs(servers)
93 it('Should have two video channels when getting my information', async () => {
94 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
97 expect(userInfo.videoChannels).to.be.an('array')
98 expect(userInfo.videoChannels).to.have.lengthOf(2)
100 const videoChannels = userInfo.videoChannels
101 expect(videoChannels[0].name).to.equal('root_channel')
102 expect(videoChannels[0].displayName).to.equal('Main root channel')
104 expect(videoChannels[1].name).to.equal('second_video_channel')
105 expect(videoChannels[1].displayName).to.equal('second video channel')
106 expect(videoChannels[1].description).to.equal('super video channel description')
107 expect(videoChannels[1].support).to.equal('super video channel support text')
110 it('Should have two video channels when getting account channels on server 1', async function () {
111 const res = await getAccountVideoChannelsList({
113 accountName: userInfo.account.name + '@' + userInfo.account.host
116 expect(res.body.total).to.equal(2)
117 expect(res.body.data).to.be.an('array')
118 expect(res.body.data).to.have.lengthOf(2)
120 const videoChannels = res.body.data
121 expect(videoChannels[0].name).to.equal('root_channel')
122 expect(videoChannels[0].displayName).to.equal('Main root channel')
124 expect(videoChannels[1].name).to.equal('second_video_channel')
125 expect(videoChannels[1].displayName).to.equal('second video channel')
126 expect(videoChannels[1].description).to.equal('super video channel description')
127 expect(videoChannels[1].support).to.equal('super video channel support text')
130 it('Should paginate and sort account channels', async function () {
132 const res = await getAccountVideoChannelsList({
134 accountName: userInfo.account.name + '@' + userInfo.account.host,
140 expect(res.body.total).to.equal(2)
141 expect(res.body.data).to.have.lengthOf(1)
143 const videoChannel: VideoChannel = res.body.data[0]
144 expect(videoChannel.name).to.equal('root_channel')
148 const res = await getAccountVideoChannelsList({
150 accountName: userInfo.account.name + '@' + userInfo.account.host,
156 expect(res.body.total).to.equal(2)
157 expect(res.body.data).to.have.lengthOf(1)
159 const videoChannel: VideoChannel = res.body.data[0]
160 expect(videoChannel.name).to.equal('second_video_channel')
164 const res = await getAccountVideoChannelsList({
166 accountName: userInfo.account.name + '@' + userInfo.account.host,
172 expect(res.body.total).to.equal(2)
173 expect(res.body.data).to.have.lengthOf(1)
175 const videoChannel: VideoChannel = res.body.data[0]
176 expect(videoChannel.name).to.equal('root_channel')
180 it('Should have one video channel when getting account channels on server 2', async function () {
181 const res = await getAccountVideoChannelsList({
183 accountName: userInfo.account.name + '@' + userInfo.account.host
186 expect(res.body.total).to.equal(1)
187 expect(res.body.data).to.be.an('array')
188 expect(res.body.data).to.have.lengthOf(1)
190 const videoChannels = res.body.data
191 expect(videoChannels[0].name).to.equal('second_video_channel')
192 expect(videoChannels[0].displayName).to.equal('second video channel')
193 expect(videoChannels[0].description).to.equal('super video channel description')
194 expect(videoChannels[0].support).to.equal('super video channel support text')
197 it('Should list video channels', async function () {
198 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
200 expect(res.body.total).to.equal(2)
201 expect(res.body.data).to.be.an('array')
202 expect(res.body.data).to.have.lengthOf(1)
203 expect(res.body.data[0].name).to.equal('root_channel')
204 expect(res.body.data[0].displayName).to.equal('Main root channel')
207 it('Should update video channel', async function () {
210 const videoChannelAttributes = {
211 displayName: 'video channel updated',
212 description: 'video channel description updated',
213 support: 'support updated'
216 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
218 await waitJobs(servers)
221 it('Should have video channel updated', async function () {
222 for (const server of servers) {
223 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
225 expect(res.body.total).to.equal(2)
226 expect(res.body.data).to.be.an('array')
227 expect(res.body.data).to.have.lengthOf(1)
228 expect(res.body.data[0].name).to.equal('second_video_channel')
229 expect(res.body.data[0].displayName).to.equal('video channel updated')
230 expect(res.body.data[0].description).to.equal('video channel description updated')
231 expect(res.body.data[0].support).to.equal('support updated')
235 it('Should not have updated the video support field', async function () {
236 for (const server of servers) {
237 const res = await getVideo(server.url, videoUUID)
238 const video: VideoDetails = res.body
240 expect(video.support).to.equal('video support field')
244 it('Should update the channel support field and update videos too', async function () {
247 const videoChannelAttributes = {
248 support: 'video channel support text updated',
249 bulkVideosSupportUpdate: true
252 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
254 await waitJobs(servers)
256 for (const server of servers) {
257 const res = await getVideo(server.url, videoUUID)
258 const video: VideoDetails = res.body
260 expect(video.support).to.equal(videoChannelAttributes.support)
264 it('Should update video channel avatar', async function () {
267 const fixture = 'avatar.png'
269 await updateVideoChannelAvatar({
271 accessToken: servers[0].accessToken,
272 videoChannelName: 'second_video_channel',
276 await waitJobs(servers)
279 it('Should have video channel avatar updated', async function () {
280 for (const server of servers) {
281 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
283 const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId)
285 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
289 it('Should get video channel', async function () {
290 const res = await getVideoChannel(servers[0].url, 'second_video_channel')
292 const videoChannel = res.body
293 expect(videoChannel.name).to.equal('second_video_channel')
294 expect(videoChannel.displayName).to.equal('video channel updated')
295 expect(videoChannel.description).to.equal('video channel description updated')
296 expect(videoChannel.support).to.equal('video channel support text updated')
299 it('Should list the second video channel videos', async function () {
302 for (const server of servers) {
303 const channelURI = 'second_video_channel@localhost:' + servers[0].port
304 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
305 expect(res1.body.total).to.equal(1)
306 expect(res1.body.data).to.be.an('array')
307 expect(res1.body.data).to.have.lengthOf(1)
308 expect(res1.body.data[0].name).to.equal('my video name')
312 it('Should change the video channel of a video', async function () {
315 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
317 await waitJobs(servers)
320 it('Should list the first video channel videos', async function () {
323 for (const server of servers) {
324 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
325 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
326 expect(res1.body.total).to.equal(0)
328 const channelURI = 'root_channel@localhost:' + servers[0].port
329 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
330 expect(res2.body.total).to.equal(1)
332 const videos: Video[] = res2.body.data
333 expect(videos).to.be.an('array')
334 expect(videos).to.have.lengthOf(1)
335 expect(videos[0].name).to.equal('my video name')
339 it('Should delete video channel', async function () {
340 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
343 it('Should have video channel deleted', async function () {
344 const res = await getVideoChannelsList(servers[0].url, 0, 10)
346 expect(res.body.total).to.equal(1)
347 expect(res.body.data).to.be.an('array')
348 expect(res.body.data).to.have.lengthOf(1)
349 expect(res.body.data[0].displayName).to.equal('Main root channel')
352 it('Should create the main channel with an uuid if there is a conflict', async function () {
354 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
355 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
359 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
360 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' })
362 const res = await getMyUserInformation(servers[0].url, accessToken)
363 const videoChannel = res.body.videoChannels[0]
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}/)
368 it('Should report correct channel views per days', async function () {
372 const res = await getAccountVideoChannelsList({
374 accountName: userInfo.account.name + '@' + userInfo.account.host,
378 const channels: VideoChannel[] = res.body.data
380 for (const channel of channels) {
381 expect(channel).to.haveOwnProperty('viewsPerDay')
382 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
384 for (const v of channel.viewsPerDay) {
385 expect(v.date).to.be.an('string')
386 expect(v.views).to.equal(0)
392 // video has been posted on channel firstVideoChannelId since last update
393 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1')
394 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1')
396 // Wait the repeatable job
399 const res = await getAccountVideoChannelsList({
401 accountName: userInfo.account.name + '@' + userInfo.account.host,
404 const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId)
405 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2)
409 it('Should report correct videos count', async function () {
410 const res = await getAccountVideoChannelsList({
412 accountName: userInfo.account.name + '@' + userInfo.account.host,
415 const channels: VideoChannel[] = res.body.data
417 const totoChannel = channels.find(c => c.name === 'toto_channel')
418 const rootChannel = channels.find(c => c.name === 'root_channel')
420 expect(rootChannel.videosCount).to.equal(1)
421 expect(totoChannel.videosCount).to.equal(0)
424 it('Should search among account video channels', async function () {
426 const res = await getAccountVideoChannelsList({
428 accountName: userInfo.account.name + '@' + userInfo.account.host,
431 expect(res.body.total).to.equal(1)
433 const channels = res.body.data
434 expect(channels).to.have.lengthOf(1)
438 const res = await getAccountVideoChannelsList({
440 accountName: userInfo.account.name + '@' + userInfo.account.host,
441 search: 'does not exist'
443 expect(res.body.total).to.equal(0)
445 const channels = res.body.data
446 expect(channels).to.have.lengthOf(0)
450 after(async function () {
451 await cleanupTests(servers)