]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-channels.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-channels.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5f04dd2f 2
5f04dd2f 3import * as chai from 'chai'
2422c46b 4import 'mocha'
7d14d4d2 5import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
4bbfc6c6 6import {
7c3b7976 7 cleanupTests,
8a19bee1 8 createUser,
4bbfc6c6 9 doubleFollow,
a1587156
C
10 flushAndRunMultipleServers,
11 getVideo,
d175a6f7
C
12 getVideoChannelVideos,
13 testImage,
4bbfc6c6
C
14 updateVideo,
15 updateVideoChannelAvatar,
d175a6f7
C
16 uploadVideo,
17 userLogin
94565d52 18} from '../../../../shared/extra-utils'
5f04dd2f 19import {
2422c46b
C
20 addVideoChannel,
21 deleteVideoChannel,
2422c46b 22 getAccountVideoChannelsList,
5f04dd2f 23 getMyUserInformation,
2422c46b 24 getVideoChannel,
5f04dd2f 25 getVideoChannelsList,
2422c46b
C
26 ServerInfo,
27 setAccessTokensToServers,
28 updateVideoChannel
94565d52
C
29} from '../../../../shared/extra-utils/index'
30import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
5f04dd2f 31
2422c46b
C
32const expect = chai.expect
33
34describe('Test video channels', function () {
35 let servers: ServerInfo[]
5f04dd2f 36 let userInfo: User
0f320037 37 let firstVideoChannelId: number
0f320037 38 let secondVideoChannelId: number
0f320037 39 let videoUUID: string
5f04dd2f
C
40
41 before(async function () {
48f07b4a 42 this.timeout(60000)
5f04dd2f 43
2422c46b
C
44 servers = await flushAndRunMultipleServers(2)
45
46 await setAccessTokensToServers(servers)
47 await doubleFollow(servers[0], servers[1])
5f04dd2f 48
48dce1c9 49 {
6b738c7a
C
50 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
51 const user: User = res.body
0f320037
C
52
53 firstVideoChannelId = user.videoChannels[0].id
48dce1c9
C
54 }
55
3cd0734f 56 await waitJobs(servers)
5f04dd2f
C
57 })
58
59 it('Should have one video channel (created with root)', async () => {
2422c46b 60 const res = await getVideoChannelsList(servers[0].url, 0, 2)
5f04dd2f
C
61
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)
65 })
66
2422c46b
C
67 it('Should create another video channel', async function () {
68 this.timeout(10000)
69
0f320037
C
70 {
71 const videoChannel = {
8a19bee1 72 name: 'second_video_channel',
0f320037
C
73 displayName: 'second video channel',
74 description: 'super video channel description',
75 support: 'super video channel support text'
76 }
a1587156 77 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
0f320037 78 secondVideoChannelId = res.body.videoChannel.id
5f04dd2f 79 }
2422c46b
C
80
81 // The channel is 1 is propagated to servers 2
0f320037 82 {
7d14d4d2 83 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
a1587156 84 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
0f320037
C
85 videoUUID = res.body.video.uuid
86 }
2422c46b 87
3cd0734f 88 await waitJobs(servers)
5f04dd2f
C
89 })
90
91 it('Should have two video channels when getting my information', async () => {
2422c46b 92 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
5f04dd2f
C
93 userInfo = res.body
94
95 expect(userInfo.videoChannels).to.be.an('array')
96 expect(userInfo.videoChannels).to.have.lengthOf(2)
97
98 const videoChannels = userInfo.videoChannels
8a19bee1
C
99 expect(videoChannels[0].name).to.equal('root_channel')
100 expect(videoChannels[0].displayName).to.equal('Main root channel')
101
102 expect(videoChannels[1].name).to.equal('second_video_channel')
7bc29171 103 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 104 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b 105 expect(videoChannels[1].support).to.equal('super video channel support text')
5f04dd2f
C
106 })
107
2422c46b 108 it('Should have two video channels when getting account channels on server 1', async function () {
91b66319 109 const res = await getAccountVideoChannelsList({
a1587156 110 url: servers[0].url,
91b66319
C
111 accountName: userInfo.account.name + '@' + userInfo.account.host
112 })
113
5f04dd2f
C
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)
117
118 const videoChannels = res.body.data
8a19bee1
C
119 expect(videoChannels[0].name).to.equal('root_channel')
120 expect(videoChannels[0].displayName).to.equal('Main root channel')
121
122 expect(videoChannels[1].name).to.equal('second_video_channel')
7bc29171 123 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 124 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b
C
125 expect(videoChannels[1].support).to.equal('super video channel support text')
126 })
127
91b66319
C
128 it('Should paginate and sort account channels', async function () {
129 {
130 const res = await getAccountVideoChannelsList({
a1587156 131 url: servers[0].url,
91b66319
C
132 accountName: userInfo.account.name + '@' + userInfo.account.host,
133 start: 0,
134 count: 1,
135 sort: 'createdAt'
136 })
137
138 expect(res.body.total).to.equal(2)
139 expect(res.body.data).to.have.lengthOf(1)
140
a1587156 141 const videoChannel: VideoChannel = res.body.data[0]
91b66319
C
142 expect(videoChannel.name).to.equal('root_channel')
143 }
144
145 {
146 const res = await getAccountVideoChannelsList({
a1587156 147 url: servers[0].url,
91b66319
C
148 accountName: userInfo.account.name + '@' + userInfo.account.host,
149 start: 0,
150 count: 1,
151 sort: '-createdAt'
152 })
153
154 expect(res.body.total).to.equal(2)
155 expect(res.body.data).to.have.lengthOf(1)
156
a1587156 157 const videoChannel: VideoChannel = res.body.data[0]
91b66319
C
158 expect(videoChannel.name).to.equal('second_video_channel')
159 }
160
161 {
162 const res = await getAccountVideoChannelsList({
a1587156 163 url: servers[0].url,
91b66319
C
164 accountName: userInfo.account.name + '@' + userInfo.account.host,
165 start: 1,
166 count: 1,
167 sort: '-createdAt'
168 })
169
170 expect(res.body.total).to.equal(2)
171 expect(res.body.data).to.have.lengthOf(1)
172
a1587156 173 const videoChannel: VideoChannel = res.body.data[0]
91b66319
C
174 expect(videoChannel.name).to.equal('root_channel')
175 }
176 })
177
2422c46b 178 it('Should have one video channel when getting account channels on server 2', async function () {
91b66319 179 const res = await getAccountVideoChannelsList({
a1587156 180 url: servers[1].url,
91b66319
C
181 accountName: userInfo.account.name + '@' + userInfo.account.host
182 })
183
2422c46b
C
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)
5f04dd2f 187
2422c46b 188 const videoChannels = res.body.data
8a19bee1 189 expect(videoChannels[0].name).to.equal('second_video_channel')
2422c46b
C
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')
5f04dd2f
C
193 })
194
2422c46b
C
195 it('Should list video channels', async function () {
196 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
5f04dd2f
C
197
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)
8a19bee1
C
201 expect(res.body.data[0].name).to.equal('root_channel')
202 expect(res.body.data[0].displayName).to.equal('Main root channel')
5f04dd2f
C
203 })
204
2422c46b 205 it('Should update video channel', async function () {
7d14d4d2 206 this.timeout(15000)
2422c46b 207
5f04dd2f 208 const videoChannelAttributes = {
08c1efbe 209 displayName: 'video channel updated',
2422c46b 210 description: 'video channel description updated',
7d14d4d2 211 support: 'support updated'
5f04dd2f
C
212 }
213
8a19bee1 214 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
2422c46b 215
3cd0734f 216 await waitJobs(servers)
5f04dd2f
C
217 })
218
2422c46b
C
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')
5f04dd2f 222
2422c46b
C
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)
8a19bee1 226 expect(res.body.data[0].name).to.equal('second_video_channel')
2422c46b
C
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')
7d14d4d2
C
229 expect(res.body.data[0].support).to.equal('support updated')
230 }
231 })
232
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
237
238 expect(video.support).to.equal('video support field')
239 }
240 })
241
242 it('Should update the channel support field and update videos too', async function () {
243 this.timeout(35000)
244
245 const videoChannelAttributes = {
246 support: 'video channel support text updated',
247 bulkVideosSupportUpdate: true
248 }
249
250 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
251
252 await waitJobs(servers)
253
254 for (const server of servers) {
255 const res = await getVideo(server.url, videoUUID)
256 const video: VideoDetails = res.body
257
258 expect(video.support).to.equal(videoChannelAttributes.support)
2422c46b 259 }
5f04dd2f
C
260 })
261
4bbfc6c6
C
262 it('Should update video channel avatar', async function () {
263 this.timeout(5000)
264
265 const fixture = 'avatar.png'
266
267 await updateVideoChannelAvatar({
268 url: servers[0].url,
269 accessToken: servers[0].accessToken,
8a19bee1 270 videoChannelName: 'second_video_channel',
4bbfc6c6
C
271 fixture
272 })
273
274 await waitJobs(servers)
275 })
276
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')
280
281 const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId)
282
283 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
284 }
285 })
286
2422c46b 287 it('Should get video channel', async function () {
8a19bee1 288 const res = await getVideoChannel(servers[0].url, 'second_video_channel')
5f04dd2f
C
289
290 const videoChannel = res.body
8a19bee1 291 expect(videoChannel.name).to.equal('second_video_channel')
7bc29171 292 expect(videoChannel.displayName).to.equal('video channel updated')
5f04dd2f 293 expect(videoChannel.description).to.equal('video channel description updated')
2422c46b 294 expect(videoChannel.support).to.equal('video channel support text updated')
5f04dd2f
C
295 })
296
0f320037 297 it('Should list the second video channel videos', async function () {
6b738c7a
C
298 this.timeout(10000)
299
300 for (const server of servers) {
48f07b4a 301 const channelURI = 'second_video_channel@localhost:' + servers[0].port
8a19bee1 302 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
0f320037
C
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')
307 }
308 })
309
310 it('Should change the video channel of a video', async function () {
311 this.timeout(10000)
312
313 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
314
3cd0734f 315 await waitJobs(servers)
0f320037
C
316 })
317
318 it('Should list the first video channel videos', async function () {
319 this.timeout(10000)
320
321 for (const server of servers) {
48f07b4a 322 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
8a19bee1 323 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
0f320037
C
324 expect(res1.body.total).to.equal(0)
325
48f07b4a 326 const channelURI = 'root_channel@localhost:' + servers[0].port
8a19bee1 327 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
0f320037
C
328 expect(res2.body.total).to.equal(1)
329
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')
6b738c7a
C
334 }
335 })
336
2422c46b 337 it('Should delete video channel', async function () {
8a19bee1 338 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
5f04dd2f
C
339 })
340
2422c46b
C
341 it('Should have video channel deleted', async function () {
342 const res = await getVideoChannelsList(servers[0].url, 0, 10)
5f04dd2f
C
343
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)
8a19bee1
C
347 expect(res.body.data[0].displayName).to.equal('Main root channel')
348 })
349
350 it('Should create the main channel with an uuid if there is a conflict', async function () {
351 {
352 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
a1587156 353 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
8a19bee1
C
354 }
355
356 {
a1587156
C
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' })
8a19bee1 359
a1587156
C
360 const res = await getMyUserInformation(servers[0].url, accessToken)
361 const videoChannel = res.body.videoChannels[0]
8a19bee1
C
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}/)
363 }
5f04dd2f
C
364 })
365
7c3b7976
C
366 after(async function () {
367 await cleanupTests(servers)
5f04dd2f
C
368 })
369})