1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { User, Video, VideoChannel } from '../../../../shared/index'
10 flushAndRunMultipleServers,
11 getVideoChannelVideos,
14 updateVideoChannelAvatar,
17 } from '../../../../shared/extra-utils'
22 getAccountVideoChannelsList,
28 setAccessTokensToServers,
30 } from '../../../../shared/extra-utils/index'
31 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
33 const expect = chai.expect
35 describe('Test video channels', function () {
36 let servers: ServerInfo[]
38 let accountUUID: string
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
54 accountUUID = user.account.uuid
56 firstVideoChannelId = user.videoChannels[0].id
59 await waitJobs(servers)
62 it('Should have one video channel (created with root)', async () => {
63 const res = await getVideoChannelsList(servers[0].url, 0, 2)
65 expect(res.body.total).to.equal(1)
66 expect(res.body.data).to.be.an('array')
67 expect(res.body.data).to.have.lengthOf(1)
70 it('Should create another video channel', async function () {
74 const videoChannel = {
75 name: 'second_video_channel',
76 displayName: 'second video channel',
77 description: 'super video channel description',
78 support: 'super video channel support text'
80 const res = await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel)
81 secondVideoChannelId = res.body.videoChannel.id
84 // The channel is 1 is propagated to servers 2
86 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'my video name', channelId: secondVideoChannelId })
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({
112 url: servers[ 0 ].url,
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({
133 url: servers[ 0 ].url,
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({
149 url: servers[ 0 ].url,
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({
165 url: servers[ 0 ].url,
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({
182 url: servers[ 1 ].url,
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: 'video channel support text 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('video channel support text updated')
235 it('Should update video channel avatar', async function () {
238 const fixture = 'avatar.png'
240 await updateVideoChannelAvatar({
242 accessToken: servers[0].accessToken,
243 videoChannelName: 'second_video_channel',
247 await waitJobs(servers)
250 it('Should have video channel avatar updated', async function () {
251 for (const server of servers) {
252 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
254 const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId)
256 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
260 it('Should get video channel', async function () {
261 const res = await getVideoChannel(servers[0].url, 'second_video_channel')
263 const videoChannel = res.body
264 expect(videoChannel.name).to.equal('second_video_channel')
265 expect(videoChannel.displayName).to.equal('video channel updated')
266 expect(videoChannel.description).to.equal('video channel description updated')
267 expect(videoChannel.support).to.equal('video channel support text updated')
270 it('Should list the second video channel videos', async function () {
273 for (const server of servers) {
274 const channelURI = 'second_video_channel@localhost:' + servers[0].port
275 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
276 expect(res1.body.total).to.equal(1)
277 expect(res1.body.data).to.be.an('array')
278 expect(res1.body.data).to.have.lengthOf(1)
279 expect(res1.body.data[0].name).to.equal('my video name')
283 it('Should change the video channel of a video', async function () {
286 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
288 await waitJobs(servers)
291 it('Should list the first video channel videos', async function () {
294 for (const server of servers) {
295 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
296 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
297 expect(res1.body.total).to.equal(0)
299 const channelURI = 'root_channel@localhost:' + servers[0].port
300 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
301 expect(res2.body.total).to.equal(1)
303 const videos: Video[] = res2.body.data
304 expect(videos).to.be.an('array')
305 expect(videos).to.have.lengthOf(1)
306 expect(videos[0].name).to.equal('my video name')
310 it('Should delete video channel', async function () {
311 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
314 it('Should have video channel deleted', async function () {
315 const res = await getVideoChannelsList(servers[0].url, 0, 10)
317 expect(res.body.total).to.equal(1)
318 expect(res.body.data).to.be.an('array')
319 expect(res.body.data).to.have.lengthOf(1)
320 expect(res.body.data[0].displayName).to.equal('Main root channel')
323 it('Should create the main channel with an uuid if there is a conflict', async function () {
325 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
326 await addVideoChannel(servers[ 0 ].url, servers[ 0 ].accessToken, videoChannel)
330 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' })
331 const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' })
333 const res = await getMyUserInformation(servers[ 0 ].url, accessToken)
334 const videoChannel = res.body.videoChannels[ 0 ]
335 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}/)
339 after(async function () {
340 await cleanupTests(servers)