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