1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
10 flushAndRunMultipleServers,
12 getVideoChannelVideos,
15 updateVideoChannelAvatar,
18 } from '../../../../shared/extra-utils'
22 getAccountVideoChannelsList,
27 setAccessTokensToServers,
29 } from '../../../../shared/extra-utils/index'
30 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
32 const expect = chai.expect
34 describe('Test video channels', function () {
35 let servers: ServerInfo[]
37 let firstVideoChannelId: number
38 let secondVideoChannelId: number
41 before(async function () {
44 servers = await flushAndRunMultipleServers(2)
46 await setAccessTokensToServers(servers)
47 await doubleFollow(servers[0], servers[1])
50 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
51 const user: User = res.body
53 firstVideoChannelId = user.videoChannels[0].id
56 await waitJobs(servers)
59 it('Should have one video channel (created with root)', async () => {
60 const res = await getVideoChannelsList(servers[0].url, 0, 2)
62 expect(res.body.total).to.equal(1)
63 expect(res.body.data).to.be.an('array')
64 expect(res.body.data).to.have.lengthOf(1)
67 it('Should create another video channel', async function () {
71 const videoChannel = {
72 name: 'second_video_channel',
73 displayName: 'second video channel',
74 description: 'super video channel description',
75 support: 'super video channel support text'
77 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
78 secondVideoChannelId = res.body.videoChannel.id
81 // The channel is 1 is propagated to servers 2
83 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
84 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
85 videoUUID = res.body.video.uuid
88 await waitJobs(servers)
91 it('Should have two video channels when getting my information', async () => {
92 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
95 expect(userInfo.videoChannels).to.be.an('array')
96 expect(userInfo.videoChannels).to.have.lengthOf(2)
98 const videoChannels = userInfo.videoChannels
99 expect(videoChannels[0].name).to.equal('root_channel')
100 expect(videoChannels[0].displayName).to.equal('Main root channel')
102 expect(videoChannels[1].name).to.equal('second_video_channel')
103 expect(videoChannels[1].displayName).to.equal('second video channel')
104 expect(videoChannels[1].description).to.equal('super video channel description')
105 expect(videoChannels[1].support).to.equal('super video channel support text')
108 it('Should have two video channels when getting account channels on server 1', async function () {
109 const res = await getAccountVideoChannelsList({
111 accountName: userInfo.account.name + '@' + userInfo.account.host
114 expect(res.body.total).to.equal(2)
115 expect(res.body.data).to.be.an('array')
116 expect(res.body.data).to.have.lengthOf(2)
118 const videoChannels = res.body.data
119 expect(videoChannels[0].name).to.equal('root_channel')
120 expect(videoChannels[0].displayName).to.equal('Main root channel')
122 expect(videoChannels[1].name).to.equal('second_video_channel')
123 expect(videoChannels[1].displayName).to.equal('second video channel')
124 expect(videoChannels[1].description).to.equal('super video channel description')
125 expect(videoChannels[1].support).to.equal('super video channel support text')
128 it('Should paginate and sort account channels', async function () {
130 const res = await getAccountVideoChannelsList({
132 accountName: userInfo.account.name + '@' + userInfo.account.host,
138 expect(res.body.total).to.equal(2)
139 expect(res.body.data).to.have.lengthOf(1)
141 const videoChannel: VideoChannel = res.body.data[0]
142 expect(videoChannel.name).to.equal('root_channel')
146 const res = await getAccountVideoChannelsList({
148 accountName: userInfo.account.name + '@' + userInfo.account.host,
154 expect(res.body.total).to.equal(2)
155 expect(res.body.data).to.have.lengthOf(1)
157 const videoChannel: VideoChannel = res.body.data[0]
158 expect(videoChannel.name).to.equal('second_video_channel')
162 const res = await getAccountVideoChannelsList({
164 accountName: userInfo.account.name + '@' + userInfo.account.host,
170 expect(res.body.total).to.equal(2)
171 expect(res.body.data).to.have.lengthOf(1)
173 const videoChannel: VideoChannel = res.body.data[0]
174 expect(videoChannel.name).to.equal('root_channel')
178 it('Should have one video channel when getting account channels on server 2', async function () {
179 const res = await getAccountVideoChannelsList({
181 accountName: userInfo.account.name + '@' + userInfo.account.host
184 expect(res.body.total).to.equal(1)
185 expect(res.body.data).to.be.an('array')
186 expect(res.body.data).to.have.lengthOf(1)
188 const videoChannels = res.body.data
189 expect(videoChannels[0].name).to.equal('second_video_channel')
190 expect(videoChannels[0].displayName).to.equal('second video channel')
191 expect(videoChannels[0].description).to.equal('super video channel description')
192 expect(videoChannels[0].support).to.equal('super video channel support text')
195 it('Should list video channels', async function () {
196 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
198 expect(res.body.total).to.equal(2)
199 expect(res.body.data).to.be.an('array')
200 expect(res.body.data).to.have.lengthOf(1)
201 expect(res.body.data[0].name).to.equal('root_channel')
202 expect(res.body.data[0].displayName).to.equal('Main root channel')
205 it('Should update video channel', async function () {
208 const videoChannelAttributes = {
209 displayName: 'video channel updated',
210 description: 'video channel description updated',
211 support: 'support updated'
214 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
216 await waitJobs(servers)
219 it('Should have video channel updated', async function () {
220 for (const server of servers) {
221 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
223 expect(res.body.total).to.equal(2)
224 expect(res.body.data).to.be.an('array')
225 expect(res.body.data).to.have.lengthOf(1)
226 expect(res.body.data[0].name).to.equal('second_video_channel')
227 expect(res.body.data[0].displayName).to.equal('video channel updated')
228 expect(res.body.data[0].description).to.equal('video channel description updated')
229 expect(res.body.data[0].support).to.equal('support updated')
233 it('Should not have updated the video support field', async function () {
234 for (const server of servers) {
235 const res = await getVideo(server.url, videoUUID)
236 const video: VideoDetails = res.body
238 expect(video.support).to.equal('video support field')
242 it('Should update the channel support field and update videos too', async function () {
245 const videoChannelAttributes = {
246 support: 'video channel support text updated',
247 bulkVideosSupportUpdate: true
250 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
252 await waitJobs(servers)
254 for (const server of servers) {
255 const res = await getVideo(server.url, videoUUID)
256 const video: VideoDetails = res.body
258 expect(video.support).to.equal(videoChannelAttributes.support)
262 it('Should update video channel avatar', async function () {
265 const fixture = 'avatar.png'
267 await updateVideoChannelAvatar({
269 accessToken: servers[0].accessToken,
270 videoChannelName: 'second_video_channel',
274 await waitJobs(servers)
277 it('Should have video channel avatar updated', async function () {
278 for (const server of servers) {
279 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
281 const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId)
283 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
287 it('Should get video channel', async function () {
288 const res = await getVideoChannel(servers[0].url, 'second_video_channel')
290 const videoChannel = res.body
291 expect(videoChannel.name).to.equal('second_video_channel')
292 expect(videoChannel.displayName).to.equal('video channel updated')
293 expect(videoChannel.description).to.equal('video channel description updated')
294 expect(videoChannel.support).to.equal('video channel support text updated')
297 it('Should list the second video channel videos', async function () {
300 for (const server of servers) {
301 const channelURI = 'second_video_channel@localhost:' + servers[0].port
302 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
303 expect(res1.body.total).to.equal(1)
304 expect(res1.body.data).to.be.an('array')
305 expect(res1.body.data).to.have.lengthOf(1)
306 expect(res1.body.data[0].name).to.equal('my video name')
310 it('Should change the video channel of a video', async function () {
313 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
315 await waitJobs(servers)
318 it('Should list the first video channel videos', async function () {
321 for (const server of servers) {
322 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
323 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
324 expect(res1.body.total).to.equal(0)
326 const channelURI = 'root_channel@localhost:' + servers[0].port
327 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
328 expect(res2.body.total).to.equal(1)
330 const videos: Video[] = res2.body.data
331 expect(videos).to.be.an('array')
332 expect(videos).to.have.lengthOf(1)
333 expect(videos[0].name).to.equal('my video name')
337 it('Should delete video channel', async function () {
338 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
341 it('Should have video channel deleted', async function () {
342 const res = await getVideoChannelsList(servers[0].url, 0, 10)
344 expect(res.body.total).to.equal(1)
345 expect(res.body.data).to.be.an('array')
346 expect(res.body.data).to.have.lengthOf(1)
347 expect(res.body.data[0].displayName).to.equal('Main root channel')
350 it('Should create the main channel with an uuid if there is a conflict', async function () {
352 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
353 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
357 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
358 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' })
360 const res = await getMyUserInformation(servers[0].url, accessToken)
361 const videoChannel = res.body.videoChannels[0]
362 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}/)
366 after(async function () {
367 await cleanupTests(servers)