]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-channels.ts
Add size info in db for actor images
[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
2422c46b 3import 'mocha'
8eb07b01 4import * as chai from 'chai'
84531547 5import { basename } from 'path'
4bbfc6c6 6import {
7c3b7976 7 cleanupTests,
8a19bee1 8 createUser,
213e30ef 9 deleteVideoChannelImage,
4bbfc6c6 10 doubleFollow,
a1587156 11 flushAndRunMultipleServers,
84531547 12 getActorImage,
a1587156 13 getVideo,
cdeddff1 14 getVideoChannel,
d175a6f7
C
15 getVideoChannelVideos,
16 testImage,
4bbfc6c6 17 updateVideo,
213e30ef 18 updateVideoChannelImage,
d175a6f7 19 uploadVideo,
714bfcc5
RK
20 userLogin,
21 wait
94565d52 22} from '../../../../shared/extra-utils'
5f04dd2f 23import {
2422c46b
C
24 addVideoChannel,
25 deleteVideoChannel,
2422c46b 26 getAccountVideoChannelsList,
5f04dd2f
C
27 getMyUserInformation,
28 getVideoChannelsList,
2422c46b
C
29 ServerInfo,
30 setAccessTokensToServers,
714bfcc5
RK
31 updateVideoChannel,
32 viewVideo
94565d52
C
33} from '../../../../shared/extra-utils/index'
34import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
8eb07b01 35import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index'
84531547 36import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
5f04dd2f 37
2422c46b
C
38const expect = chai.expect
39
213e30ef
C
40async function findChannel (server: ServerInfo, channelId: number) {
41 const res = await getVideoChannelsList(server.url, 0, 5, '-name')
42 const videoChannel = res.body.data.find(c => c.id === channelId)
43
44 return videoChannel as VideoChannel
45}
46
2422c46b
C
47describe('Test video channels', function () {
48 let servers: ServerInfo[]
5f04dd2f 49 let userInfo: User
0f320037 50 let firstVideoChannelId: number
0f320037 51 let secondVideoChannelId: number
0f320037 52 let videoUUID: string
5f04dd2f
C
53
54 before(async function () {
48f07b4a 55 this.timeout(60000)
5f04dd2f 56
2422c46b
C
57 servers = await flushAndRunMultipleServers(2)
58
59 await setAccessTokensToServers(servers)
60 await doubleFollow(servers[0], servers[1])
5f04dd2f 61
48dce1c9 62 {
6b738c7a
C
63 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
64 const user: User = res.body
0f320037
C
65
66 firstVideoChannelId = user.videoChannels[0].id
48dce1c9
C
67 }
68
3cd0734f 69 await waitJobs(servers)
5f04dd2f
C
70 })
71
72 it('Should have one video channel (created with root)', async () => {
2422c46b 73 const res = await getVideoChannelsList(servers[0].url, 0, 2)
5f04dd2f
C
74
75 expect(res.body.total).to.equal(1)
76 expect(res.body.data).to.be.an('array')
77 expect(res.body.data).to.have.lengthOf(1)
78 })
79
2422c46b
C
80 it('Should create another video channel', async function () {
81 this.timeout(10000)
82
0f320037
C
83 {
84 const videoChannel = {
8a19bee1 85 name: 'second_video_channel',
0f320037
C
86 displayName: 'second video channel',
87 description: 'super video channel description',
88 support: 'super video channel support text'
89 }
a1587156 90 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
0f320037 91 secondVideoChannelId = res.body.videoChannel.id
5f04dd2f 92 }
2422c46b
C
93
94 // The channel is 1 is propagated to servers 2
0f320037 95 {
7d14d4d2 96 const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' }
a1587156 97 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg)
0f320037
C
98 videoUUID = res.body.video.uuid
99 }
2422c46b 100
3cd0734f 101 await waitJobs(servers)
5f04dd2f
C
102 })
103
104 it('Should have two video channels when getting my information', async () => {
2422c46b 105 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
5f04dd2f
C
106 userInfo = res.body
107
108 expect(userInfo.videoChannels).to.be.an('array')
109 expect(userInfo.videoChannels).to.have.lengthOf(2)
110
111 const videoChannels = userInfo.videoChannels
8a19bee1
C
112 expect(videoChannels[0].name).to.equal('root_channel')
113 expect(videoChannels[0].displayName).to.equal('Main root channel')
114
115 expect(videoChannels[1].name).to.equal('second_video_channel')
7bc29171 116 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 117 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b 118 expect(videoChannels[1].support).to.equal('super video channel support text')
5f04dd2f
C
119 })
120
2422c46b 121 it('Should have two video channels when getting account channels on server 1', async function () {
91b66319 122 const res = await getAccountVideoChannelsList({
a1587156 123 url: servers[0].url,
91b66319
C
124 accountName: userInfo.account.name + '@' + userInfo.account.host
125 })
126
5f04dd2f
C
127 expect(res.body.total).to.equal(2)
128 expect(res.body.data).to.be.an('array')
129 expect(res.body.data).to.have.lengthOf(2)
130
131 const videoChannels = res.body.data
8a19bee1
C
132 expect(videoChannels[0].name).to.equal('root_channel')
133 expect(videoChannels[0].displayName).to.equal('Main root channel')
134
135 expect(videoChannels[1].name).to.equal('second_video_channel')
7bc29171 136 expect(videoChannels[1].displayName).to.equal('second video channel')
5f04dd2f 137 expect(videoChannels[1].description).to.equal('super video channel description')
2422c46b
C
138 expect(videoChannels[1].support).to.equal('super video channel support text')
139 })
140
91b66319
C
141 it('Should paginate and sort account channels', async function () {
142 {
143 const res = await getAccountVideoChannelsList({
a1587156 144 url: servers[0].url,
91b66319
C
145 accountName: userInfo.account.name + '@' + userInfo.account.host,
146 start: 0,
147 count: 1,
148 sort: 'createdAt'
149 })
150
151 expect(res.body.total).to.equal(2)
152 expect(res.body.data).to.have.lengthOf(1)
153
a1587156 154 const videoChannel: VideoChannel = res.body.data[0]
91b66319
C
155 expect(videoChannel.name).to.equal('root_channel')
156 }
157
158 {
159 const res = await getAccountVideoChannelsList({
a1587156 160 url: servers[0].url,
91b66319
C
161 accountName: userInfo.account.name + '@' + userInfo.account.host,
162 start: 0,
163 count: 1,
164 sort: '-createdAt'
165 })
166
167 expect(res.body.total).to.equal(2)
168 expect(res.body.data).to.have.lengthOf(1)
169
a1587156 170 const videoChannel: VideoChannel = res.body.data[0]
91b66319
C
171 expect(videoChannel.name).to.equal('second_video_channel')
172 }
173
174 {
175 const res = await getAccountVideoChannelsList({
a1587156 176 url: servers[0].url,
91b66319
C
177 accountName: userInfo.account.name + '@' + userInfo.account.host,
178 start: 1,
179 count: 1,
180 sort: '-createdAt'
181 })
182
183 expect(res.body.total).to.equal(2)
184 expect(res.body.data).to.have.lengthOf(1)
185
a1587156 186 const videoChannel: VideoChannel = res.body.data[0]
91b66319
C
187 expect(videoChannel.name).to.equal('root_channel')
188 }
189 })
190
2422c46b 191 it('Should have one video channel when getting account channels on server 2', async function () {
91b66319 192 const res = await getAccountVideoChannelsList({
a1587156 193 url: servers[1].url,
91b66319
C
194 accountName: userInfo.account.name + '@' + userInfo.account.host
195 })
196
2422c46b
C
197 expect(res.body.total).to.equal(1)
198 expect(res.body.data).to.be.an('array')
199 expect(res.body.data).to.have.lengthOf(1)
5f04dd2f 200
2422c46b 201 const videoChannels = res.body.data
8a19bee1 202 expect(videoChannels[0].name).to.equal('second_video_channel')
2422c46b
C
203 expect(videoChannels[0].displayName).to.equal('second video channel')
204 expect(videoChannels[0].description).to.equal('super video channel description')
205 expect(videoChannels[0].support).to.equal('super video channel support text')
5f04dd2f
C
206 })
207
2422c46b
C
208 it('Should list video channels', async function () {
209 const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name')
5f04dd2f
C
210
211 expect(res.body.total).to.equal(2)
212 expect(res.body.data).to.be.an('array')
213 expect(res.body.data).to.have.lengthOf(1)
8a19bee1
C
214 expect(res.body.data[0].name).to.equal('root_channel')
215 expect(res.body.data[0].displayName).to.equal('Main root channel')
5f04dd2f
C
216 })
217
2422c46b 218 it('Should update video channel', async function () {
7d14d4d2 219 this.timeout(15000)
2422c46b 220
5f04dd2f 221 const videoChannelAttributes = {
08c1efbe 222 displayName: 'video channel updated',
2422c46b 223 description: 'video channel description updated',
7d14d4d2 224 support: 'support updated'
5f04dd2f
C
225 }
226
8a19bee1 227 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
2422c46b 228
3cd0734f 229 await waitJobs(servers)
5f04dd2f
C
230 })
231
2422c46b
C
232 it('Should have video channel updated', async function () {
233 for (const server of servers) {
234 const res = await getVideoChannelsList(server.url, 0, 1, '-name')
5f04dd2f 235
2422c46b
C
236 expect(res.body.total).to.equal(2)
237 expect(res.body.data).to.be.an('array')
238 expect(res.body.data).to.have.lengthOf(1)
8a19bee1 239 expect(res.body.data[0].name).to.equal('second_video_channel')
2422c46b
C
240 expect(res.body.data[0].displayName).to.equal('video channel updated')
241 expect(res.body.data[0].description).to.equal('video channel description updated')
7d14d4d2
C
242 expect(res.body.data[0].support).to.equal('support updated')
243 }
244 })
245
246 it('Should not have updated the video support field', async function () {
247 for (const server of servers) {
248 const res = await getVideo(server.url, videoUUID)
249 const video: VideoDetails = res.body
250
251 expect(video.support).to.equal('video support field')
252 }
253 })
254
255 it('Should update the channel support field and update videos too', async function () {
256 this.timeout(35000)
257
258 const videoChannelAttributes = {
259 support: 'video channel support text updated',
260 bulkVideosSupportUpdate: true
261 }
262
263 await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes)
264
265 await waitJobs(servers)
266
267 for (const server of servers) {
268 const res = await getVideo(server.url, videoUUID)
269 const video: VideoDetails = res.body
270
271 expect(video.support).to.equal(videoChannelAttributes.support)
2422c46b 272 }
5f04dd2f
C
273 })
274
4bbfc6c6 275 it('Should update video channel avatar', async function () {
213e30ef 276 this.timeout(15000)
4bbfc6c6
C
277
278 const fixture = 'avatar.png'
279
213e30ef 280 await updateVideoChannelImage({
4bbfc6c6
C
281 url: servers[0].url,
282 accessToken: servers[0].accessToken,
8a19bee1 283 videoChannelName: 'second_video_channel',
213e30ef
C
284 fixture,
285 type: 'avatar'
4bbfc6c6
C
286 })
287
288 await waitJobs(servers)
213e30ef
C
289
290 for (const server of servers) {
291 const videoChannel = await findChannel(server, secondVideoChannelId)
292
293 await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png')
84531547
C
294
295 const row = await getActorImage(server.internalServerNumber, basename(videoChannel.avatar.path))
296 expect(row.height).to.equal(ACTOR_IMAGES_SIZE.AVATARS.height)
297 expect(row.width).to.equal(ACTOR_IMAGES_SIZE.AVATARS.width)
213e30ef 298 }
4bbfc6c6
C
299 })
300
213e30ef
C
301 it('Should update video channel banner', async function () {
302 this.timeout(15000)
303
304 const fixture = 'banner.jpg'
305
306 await updateVideoChannelImage({
307 url: servers[0].url,
308 accessToken: servers[0].accessToken,
309 videoChannelName: 'second_video_channel',
310 fixture,
311 type: 'banner'
312 })
313
314 await waitJobs(servers)
315
4bbfc6c6 316 for (const server of servers) {
cdeddff1
C
317 const res = await getVideoChannel(server.url, 'second_video_channel@' + servers[0].host)
318 const videoChannel = res.body
4bbfc6c6 319
213e30ef 320 await testImage(server.url, 'banner-resized', videoChannel.banner.path)
84531547
C
321
322 const row = await getActorImage(server.internalServerNumber, basename(videoChannel.banner.path))
323 expect(row.height).to.equal(ACTOR_IMAGES_SIZE.BANNERS.height)
324 expect(row.width).to.equal(ACTOR_IMAGES_SIZE.BANNERS.width)
213e30ef
C
325 }
326 })
4bbfc6c6 327
213e30ef
C
328 it('Should delete the video channel avatar', async function () {
329 this.timeout(15000)
330
331 await deleteVideoChannelImage({
332 url: servers[0].url,
333 accessToken: servers[0].accessToken,
334 videoChannelName: 'second_video_channel',
335 type: 'avatar'
336 })
337
338 await waitJobs(servers)
339
340 for (const server of servers) {
341 const videoChannel = await findChannel(server, secondVideoChannelId)
342
343 expect(videoChannel.avatar).to.be.null
4bbfc6c6
C
344 }
345 })
346
213e30ef
C
347 it('Should delete the video channel banner', async function () {
348 this.timeout(15000)
349
350 await deleteVideoChannelImage({
351 url: servers[0].url,
352 accessToken: servers[0].accessToken,
353 videoChannelName: 'second_video_channel',
354 type: 'banner'
355 })
5f04dd2f 356
213e30ef
C
357 await waitJobs(servers)
358
359 for (const server of servers) {
360 const videoChannel = await findChannel(server, secondVideoChannelId)
361
362 expect(videoChannel.banner).to.be.null
363 }
5f04dd2f
C
364 })
365
0f320037 366 it('Should list the second video channel videos', async function () {
6b738c7a
C
367 this.timeout(10000)
368
369 for (const server of servers) {
48f07b4a 370 const channelURI = 'second_video_channel@localhost:' + servers[0].port
8a19bee1 371 const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
0f320037
C
372 expect(res1.body.total).to.equal(1)
373 expect(res1.body.data).to.be.an('array')
374 expect(res1.body.data).to.have.lengthOf(1)
375 expect(res1.body.data[0].name).to.equal('my video name')
376 }
377 })
378
379 it('Should change the video channel of a video', async function () {
380 this.timeout(10000)
381
382 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId })
383
3cd0734f 384 await waitJobs(servers)
0f320037
C
385 })
386
387 it('Should list the first video channel videos', async function () {
388 this.timeout(10000)
389
390 for (const server of servers) {
48f07b4a 391 const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port
8a19bee1 392 const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5)
0f320037
C
393 expect(res1.body.total).to.equal(0)
394
48f07b4a 395 const channelURI = 'root_channel@localhost:' + servers[0].port
8a19bee1 396 const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5)
0f320037
C
397 expect(res2.body.total).to.equal(1)
398
399 const videos: Video[] = res2.body.data
400 expect(videos).to.be.an('array')
401 expect(videos).to.have.lengthOf(1)
402 expect(videos[0].name).to.equal('my video name')
6b738c7a
C
403 }
404 })
405
2422c46b 406 it('Should delete video channel', async function () {
8a19bee1 407 await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel')
5f04dd2f
C
408 })
409
2422c46b
C
410 it('Should have video channel deleted', async function () {
411 const res = await getVideoChannelsList(servers[0].url, 0, 10)
5f04dd2f
C
412
413 expect(res.body.total).to.equal(1)
414 expect(res.body.data).to.be.an('array')
415 expect(res.body.data).to.have.lengthOf(1)
8a19bee1
C
416 expect(res.body.data[0].displayName).to.equal('Main root channel')
417 })
418
419 it('Should create the main channel with an uuid if there is a conflict', async function () {
420 {
421 const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' }
a1587156 422 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel)
8a19bee1
C
423 }
424
425 {
a1587156
C
426 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' })
427 const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' })
8a19bee1 428
a1587156
C
429 const res = await getMyUserInformation(servers[0].url, accessToken)
430 const videoChannel = res.body.videoChannels[0]
8a19bee1
C
431 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}/)
432 }
5f04dd2f
C
433 })
434
1ba471c5 435 it('Should report correct channel views per days', async function () {
5a61ffbb 436 this.timeout(10000)
714bfcc5
RK
437
438 {
439 const res = await getAccountVideoChannelsList({
440 url: servers[0].url,
441 accountName: userInfo.account.name + '@' + userInfo.account.host,
442 withStats: true
443 })
1ba471c5
C
444
445 const channels: VideoChannel[] = res.body.data
446
447 for (const channel of channels) {
714bfcc5
RK
448 expect(channel).to.haveOwnProperty('viewsPerDay')
449 expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today
1ba471c5
C
450
451 for (const v of channel.viewsPerDay) {
714bfcc5
RK
452 expect(v.date).to.be.an('string')
453 expect(v.views).to.equal(0)
1ba471c5
C
454 }
455 }
714bfcc5
RK
456 }
457
458 {
459 // video has been posted on channel firstVideoChannelId since last update
460 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1')
461 await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1')
462
463 // Wait the repeatable job
464 await wait(8000)
465
466 const res = await getAccountVideoChannelsList({
467 url: servers[0].url,
468 accountName: userInfo.account.name + '@' + userInfo.account.host,
469 withStats: true
470 })
471 const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId)
472 expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2)
473 }
474 })
475
1ba471c5
C
476 it('Should report correct videos count', async function () {
477 const res = await getAccountVideoChannelsList({
478 url: servers[0].url,
479 accountName: userInfo.account.name + '@' + userInfo.account.host,
480 withStats: true
481 })
482 const channels: VideoChannel[] = res.body.data
483
484 const totoChannel = channels.find(c => c.name === 'toto_channel')
485 const rootChannel = channels.find(c => c.name === 'root_channel')
486
487 expect(rootChannel.videosCount).to.equal(1)
488 expect(totoChannel.videosCount).to.equal(0)
489 })
490
7b390964
RK
491 it('Should search among account video channels', async function () {
492 {
493 const res = await getAccountVideoChannelsList({
494 url: servers[0].url,
495 accountName: userInfo.account.name + '@' + userInfo.account.host,
496 search: 'root'
497 })
498 expect(res.body.total).to.equal(1)
499
500 const channels = res.body.data
501 expect(channels).to.have.lengthOf(1)
502 }
503
504 {
505 const res = await getAccountVideoChannelsList({
506 url: servers[0].url,
507 accountName: userInfo.account.name + '@' + userInfo.account.host,
508 search: 'does not exist'
509 })
510 expect(res.body.total).to.equal(0)
511
512 const channels = res.body.data
513 expect(channels).to.have.lengthOf(0)
514 }
515 })
516
7c3b7976
C
517 after(async function () {
518 await cleanupTests(servers)
5f04dd2f
C
519 })
520})