1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
10 flushAndRunMultipleServers, getVideo,
11 getVideoChannelVideos,
14 updateVideoChannelAvatar,
17 } from '../../../../shared/extra-utils'
21 getAccountVideoChannelsList,
26 setAccessTokensToServers,
28 } from '../../../../shared/extra-utils/index'
29 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
31 const expect = chai.expect
33 describe('Test video channels', function () {
34 let servers: ServerInfo[]
36 let firstVideoChannelId: number
37 let secondVideoChannelId: number
40 before(async function () {
43 servers = await flushAndRunMultipleServers(2)
45 await setAccessTokensToServers(servers)
46 await doubleFollow(servers[0], servers[1])
49 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
50 const user: User = res.body
52 firstVideoChannelId = user.videoChannels[0].id
55 await waitJobs(servers)
58 it('Should have one video channel (created with root)', async () => {
59 const res = await getVideoChannelsList(servers[0].url, 0, 2)
61 expect(res.body.total).to.equal(1)
62 expect(res.body.data).to.be.an('array')
63 expect(res.body.data).to.have.lengthOf(1)
66 it('Should create another video channel', async function () {
70 const videoChannel = {
71 name: 'second_video_channel',
72 displayName: 'second video channel',
73 description: 'super video channel description',
74 support: 'super video channel support text'
76 const res = await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel)
77 secondVideoChannelId = res.body.videoChannel.id
80 // The channel is 1 is propagated to servers 2
82 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
83 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributesArg)
84 videoUUID = res.body.video.uuid
87 await waitJobs(servers)
90 it('Should have two video channels when getting my information', async () => {
91 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
94 expect(userInfo.videoChannels).to.be.an('array')
95 expect(userInfo.videoChannels).to.have.lengthOf(2)
97 const videoChannels = userInfo.videoChannels
98 expect(videoChannels[0].name).to.equal('root_channel')
99 expect(videoChannels[0].displayName).to.equal('Main root channel')
101 expect(videoChannels[1].name).to.equal('second_video_channel')
102 expect(videoChannels[1].displayName).to.equal('second video channel')
103 expect(videoChannels[1].description).to.equal('super video channel description')
104 expect(videoChannels[1].support).to.equal('super video channel support text')
107 it('Should have two video channels when getting account channels on server 1', async function () {
108 const res = await getAccountVideoChannelsList({
109 url: servers[ 0 ].url,
110 accountName: userInfo.account.name + '@' + userInfo.account.host
113 expect(res.body.total).to.equal(2)
114 expect(res.body.data).to.be.an('array')
115 expect(res.body.data).to.have.lengthOf(2)
117 const videoChannels = res.body.data
118 expect(videoChannels[0].name).to.equal('root_channel')
119 expect(videoChannels[0].displayName).to.equal('Main root channel')
121 expect(videoChannels[1].name).to.equal('second_video_channel')
122 expect(videoChannels[1].displayName).to.equal('second video channel')
123 expect(videoChannels[1].description).to.equal('super video channel description')
124 expect(videoChannels[1].support).to.equal('super video channel support text')
127 it('Should paginate and sort account channels', async function () {
129 const res = await getAccountVideoChannelsList({
130 url: servers[ 0 ].url,
131 accountName: userInfo.account.name + '@' + userInfo.account.host,
137 expect(res.body.total).to.equal(2)
138 expect(res.body.data).to.have.lengthOf(1)
140 const videoChannel: VideoChannel = res.body.data[ 0 ]
141 expect(videoChannel.name).to.equal('root_channel')
145 const res = await getAccountVideoChannelsList({
146 url: servers[ 0 ].url,
147 accountName: userInfo.account.name + '@' + userInfo.account.host,
153 expect(res.body.total).to.equal(2)
154 expect(res.body.data).to.have.lengthOf(1)
156 const videoChannel: VideoChannel = res.body.data[ 0 ]
157 expect(videoChannel.name).to.equal('second_video_channel')
161 const res = await getAccountVideoChannelsList({
162 url: servers[ 0 ].url,
163 accountName: userInfo.account.name + '@' + userInfo.account.host,
169 expect(res.body.total).to.equal(2)
170 expect(res.body.data).to.have.lengthOf(1)
172 const videoChannel: VideoChannel = res.body.data[ 0 ]
173 expect(videoChannel.name).to.equal('root_channel')
177 it('Should have one video channel when getting account channels on server 2', async function () {
178 const res = await getAccountVideoChannelsList({
179 url: servers[ 1 ].url,
180 accountName: userInfo.account.name + '@' + userInfo.account.host
183 expect(res.body.total).to.equal(1)
184 expect(res.body.data).to.be.an('array')
185 expect(res.body.data).to.have.lengthOf(1)
187 const videoChannels = res.body.data
188 expect(videoChannels[0].name).to.equal('second_video_channel')
189 expect(videoChannels[0].displayName).to.equal('second video channel')
190 expect(videoChannels[0].description).to.equal('super video channel description')
191 expect(videoChannels[0].support).to.equal('super video channel support text')
194 it('Should list video channels', async function () {
195 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
197 expect(res.body.total).to.equal(2)
198 expect(res.body.data).to.be.an('array')
199 expect(res.body.data).to.have.lengthOf(1)
200 expect(res.body.data[0].name).to.equal('root_channel')
201 expect(res.body.data[0].displayName).to.equal('Main root channel')
204 it('Should update video channel', async function () {
207 const videoChannelAttributes = {
208 displayName: 'video channel updated',
209 description: 'video channel description updated',
210 support: 'support updated'
213 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
215 await waitJobs(servers)
218 it('Should have video channel updated', async function () {
219 for (const server of servers) {
220 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
222 expect(res.body.total).to.equal(2)
223 expect(res.body.data).to.be.an('array')
224 expect(res.body.data).to.have.lengthOf(1)
225 expect(res.body.data[0].name).to.equal('second_video_channel')
226 expect(res.body.data[0].displayName).to.equal('video channel updated')
227 expect(res.body.data[0].description).to.equal('video channel description updated')
228 expect(res.body.data[0].support).to.equal('support updated')
232 it('Should not have updated the video support field', async function () {
233 for (const server of servers) {
234 const res = await getVideo(server.url, videoUUID)
235 const video: VideoDetails = res.body
237 expect(video.support).to.equal('video support field')
241 it('Should update the channel support field and update videos too', async function () {
244 const videoChannelAttributes = {
245 support: 'video channel support text updated',
246 bulkVideosSupportUpdate: true
249 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
251 await waitJobs(servers)
253 for (const server of servers) {
254 const res = await getVideo(server.url, videoUUID)
255 const video: VideoDetails = res.body
257 expect(video.support).to.equal(videoChannelAttributes.support)
261 it('Should update video channel avatar', async function () {
264 const fixture = 'avatar.png'
266 await updateVideoChannelAvatar({
268 accessToken: servers[0].accessToken,
269 videoChannelName: 'second_video_channel',
273 await waitJobs(servers)
276 it('Should have video channel avatar updated', async function () {
277 for (const server of servers) {
278 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
280 const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId)
282 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
286 it('Should get video channel', async function () {
287 const res = await getVideoChannel(servers[0].url, 'second_video_channel')
289 const videoChannel = res.body
290 expect(videoChannel.name).to.equal('second_video_channel')
291 expect(videoChannel.displayName).to.equal('video channel updated')
292 expect(videoChannel.description).to.equal('video channel description updated')
293 expect(videoChannel.support).to.equal('video channel support text updated')
296 it('Should list the second video channel videos', async function () {
299 for (const server of servers) {
300 const channelURI = 'second_video_channel@localhost:' + servers[0].port
301 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
302 expect(res1.body.total).to.equal(1)
303 expect(res1.body.data).to.be.an('array')
304 expect(res1.body.data).to.have.lengthOf(1)
305 expect(res1.body.data[0].name).to.equal('my video name')
309 it('Should change the video channel of a video', async function () {
312 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
314 await waitJobs(servers)
317 it('Should list the first video channel videos', async function () {
320 for (const server of servers) {
321 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
322 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
323 expect(res1.body.total).to.equal(0)
325 const channelURI = 'root_channel@localhost:' + servers[0].port
326 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
327 expect(res2.body.total).to.equal(1)
329 const videos: Video[] = res2.body.data
330 expect(videos).to.be.an('array')
331 expect(videos).to.have.lengthOf(1)
332 expect(videos[0].name).to.equal('my video name')
336 it('Should delete video channel', async function () {
337 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
340 it('Should have video channel deleted', async function () {
341 const res = await getVideoChannelsList(servers[0].url, 0, 10)
343 expect(res.body.total).to.equal(1)
344 expect(res.body.data).to.be.an('array')
345 expect(res.body.data).to.have.lengthOf(1)
346 expect(res.body.data[0].displayName).to.equal('Main root channel')
349 it('Should create the main channel with an uuid if there is a conflict', async function () {
351 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
352 await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel)
356 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' })
357 const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' })
359 const res = await getMyUserInformation(servers[ 0 ].url, accessToken)
360 const videoChannel = res.body.videoChannels[ 0 ]
361 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}/)
365 after(async function () {
366 await cleanupTests(servers)