]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
5f04dd2f | 2 | |
5f04dd2f | 3 | import * as chai from 'chai' |
2422c46b | 4 | import 'mocha' |
3d527ba1 | 5 | import { User, Video, VideoChannel, ViewsPerDate, VideoDetails } from '../../../../shared/index' |
4bbfc6c6 | 6 | import { |
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 | 16 | uploadVideo, |
714bfcc5 RK |
17 | userLogin, |
18 | wait | |
94565d52 | 19 | } from '../../../../shared/extra-utils' |
5f04dd2f | 20 | import { |
2422c46b C |
21 | addVideoChannel, |
22 | deleteVideoChannel, | |
2422c46b | 23 | getAccountVideoChannelsList, |
5f04dd2f | 24 | getMyUserInformation, |
2422c46b | 25 | getVideoChannel, |
5f04dd2f | 26 | getVideoChannelsList, |
2422c46b C |
27 | ServerInfo, |
28 | setAccessTokensToServers, | |
714bfcc5 RK |
29 | updateVideoChannel, |
30 | viewVideo | |
94565d52 C |
31 | } from '../../../../shared/extra-utils/index' |
32 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
5f04dd2f | 33 | |
2422c46b C |
34 | const expect = chai.expect |
35 | ||
36 | describe('Test video channels', function () { | |
37 | let servers: ServerInfo[] | |
5f04dd2f | 38 | let userInfo: User |
0f320037 | 39 | let firstVideoChannelId: number |
0f320037 | 40 | let secondVideoChannelId: number |
0f320037 | 41 | let videoUUID: string |
5f04dd2f C |
42 | |
43 | before(async function () { | |
48f07b4a | 44 | this.timeout(60000) |
5f04dd2f | 45 | |
2422c46b C |
46 | servers = await flushAndRunMultipleServers(2) |
47 | ||
48 | await setAccessTokensToServers(servers) | |
49 | await doubleFollow(servers[0], servers[1]) | |
5f04dd2f | 50 | |
48dce1c9 | 51 | { |
6b738c7a C |
52 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) |
53 | const user: User = res.body | |
0f320037 C |
54 | |
55 | firstVideoChannelId = user.videoChannels[0].id | |
48dce1c9 C |
56 | } |
57 | ||
3cd0734f | 58 | await waitJobs(servers) |
5f04dd2f C |
59 | }) |
60 | ||
61 | it('Should have one video channel (created with root)', async () => { | |
2422c46b | 62 | const res = await getVideoChannelsList(servers[0].url, 0, 2) |
5f04dd2f C |
63 | |
64 | expect(res.body.total).to.equal(1) | |
65 | expect(res.body.data).to.be.an('array') | |
66 | expect(res.body.data).to.have.lengthOf(1) | |
67 | }) | |
68 | ||
2422c46b C |
69 | it('Should create another video channel', async function () { |
70 | this.timeout(10000) | |
71 | ||
0f320037 C |
72 | { |
73 | const videoChannel = { | |
8a19bee1 | 74 | name: 'second_video_channel', |
0f320037 C |
75 | displayName: 'second video channel', |
76 | description: 'super video channel description', | |
77 | support: 'super video channel support text' | |
78 | } | |
a1587156 | 79 | const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) |
0f320037 | 80 | secondVideoChannelId = res.body.videoChannel.id |
5f04dd2f | 81 | } |
2422c46b C |
82 | |
83 | // The channel is 1 is propagated to servers 2 | |
0f320037 | 84 | { |
7d14d4d2 | 85 | const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } |
a1587156 | 86 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg) |
0f320037 C |
87 | videoUUID = res.body.video.uuid |
88 | } | |
2422c46b | 89 | |
3cd0734f | 90 | await waitJobs(servers) |
5f04dd2f C |
91 | }) |
92 | ||
93 | it('Should have two video channels when getting my information', async () => { | |
2422c46b | 94 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) |
5f04dd2f C |
95 | userInfo = res.body |
96 | ||
97 | expect(userInfo.videoChannels).to.be.an('array') | |
98 | expect(userInfo.videoChannels).to.have.lengthOf(2) | |
99 | ||
100 | const videoChannels = userInfo.videoChannels | |
8a19bee1 C |
101 | expect(videoChannels[0].name).to.equal('root_channel') |
102 | expect(videoChannels[0].displayName).to.equal('Main root channel') | |
103 | ||
104 | expect(videoChannels[1].name).to.equal('second_video_channel') | |
7bc29171 | 105 | expect(videoChannels[1].displayName).to.equal('second video channel') |
5f04dd2f | 106 | expect(videoChannels[1].description).to.equal('super video channel description') |
2422c46b | 107 | expect(videoChannels[1].support).to.equal('super video channel support text') |
5f04dd2f C |
108 | }) |
109 | ||
2422c46b | 110 | it('Should have two video channels when getting account channels on server 1', async function () { |
91b66319 | 111 | const res = await getAccountVideoChannelsList({ |
a1587156 | 112 | url: servers[0].url, |
91b66319 C |
113 | accountName: userInfo.account.name + '@' + userInfo.account.host |
114 | }) | |
115 | ||
5f04dd2f C |
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) | |
119 | ||
120 | const videoChannels = res.body.data | |
8a19bee1 C |
121 | expect(videoChannels[0].name).to.equal('root_channel') |
122 | expect(videoChannels[0].displayName).to.equal('Main root channel') | |
123 | ||
124 | expect(videoChannels[1].name).to.equal('second_video_channel') | |
7bc29171 | 125 | expect(videoChannels[1].displayName).to.equal('second video channel') |
5f04dd2f | 126 | expect(videoChannels[1].description).to.equal('super video channel description') |
2422c46b C |
127 | expect(videoChannels[1].support).to.equal('super video channel support text') |
128 | }) | |
129 | ||
91b66319 C |
130 | it('Should paginate and sort account channels', async function () { |
131 | { | |
132 | const res = await getAccountVideoChannelsList({ | |
a1587156 | 133 | url: servers[0].url, |
91b66319 C |
134 | accountName: userInfo.account.name + '@' + userInfo.account.host, |
135 | start: 0, | |
136 | count: 1, | |
137 | sort: 'createdAt' | |
138 | }) | |
139 | ||
140 | expect(res.body.total).to.equal(2) | |
141 | expect(res.body.data).to.have.lengthOf(1) | |
142 | ||
a1587156 | 143 | const videoChannel: VideoChannel = res.body.data[0] |
91b66319 C |
144 | expect(videoChannel.name).to.equal('root_channel') |
145 | } | |
146 | ||
147 | { | |
148 | const res = await getAccountVideoChannelsList({ | |
a1587156 | 149 | url: servers[0].url, |
91b66319 C |
150 | accountName: userInfo.account.name + '@' + userInfo.account.host, |
151 | start: 0, | |
152 | count: 1, | |
153 | sort: '-createdAt' | |
154 | }) | |
155 | ||
156 | expect(res.body.total).to.equal(2) | |
157 | expect(res.body.data).to.have.lengthOf(1) | |
158 | ||
a1587156 | 159 | const videoChannel: VideoChannel = res.body.data[0] |
91b66319 C |
160 | expect(videoChannel.name).to.equal('second_video_channel') |
161 | } | |
162 | ||
163 | { | |
164 | const res = await getAccountVideoChannelsList({ | |
a1587156 | 165 | url: servers[0].url, |
91b66319 C |
166 | accountName: userInfo.account.name + '@' + userInfo.account.host, |
167 | start: 1, | |
168 | count: 1, | |
169 | sort: '-createdAt' | |
170 | }) | |
171 | ||
172 | expect(res.body.total).to.equal(2) | |
173 | expect(res.body.data).to.have.lengthOf(1) | |
174 | ||
a1587156 | 175 | const videoChannel: VideoChannel = res.body.data[0] |
91b66319 C |
176 | expect(videoChannel.name).to.equal('root_channel') |
177 | } | |
178 | }) | |
179 | ||
2422c46b | 180 | it('Should have one video channel when getting account channels on server 2', async function () { |
91b66319 | 181 | const res = await getAccountVideoChannelsList({ |
a1587156 | 182 | url: servers[1].url, |
91b66319 C |
183 | accountName: userInfo.account.name + '@' + userInfo.account.host |
184 | }) | |
185 | ||
2422c46b C |
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) | |
5f04dd2f | 189 | |
2422c46b | 190 | const videoChannels = res.body.data |
8a19bee1 | 191 | expect(videoChannels[0].name).to.equal('second_video_channel') |
2422c46b C |
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') | |
5f04dd2f C |
195 | }) |
196 | ||
2422c46b C |
197 | it('Should list video channels', async function () { |
198 | const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name') | |
5f04dd2f C |
199 | |
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) | |
8a19bee1 C |
203 | expect(res.body.data[0].name).to.equal('root_channel') |
204 | expect(res.body.data[0].displayName).to.equal('Main root channel') | |
5f04dd2f C |
205 | }) |
206 | ||
2422c46b | 207 | it('Should update video channel', async function () { |
7d14d4d2 | 208 | this.timeout(15000) |
2422c46b | 209 | |
5f04dd2f | 210 | const videoChannelAttributes = { |
08c1efbe | 211 | displayName: 'video channel updated', |
2422c46b | 212 | description: 'video channel description updated', |
7d14d4d2 | 213 | support: 'support updated' |
5f04dd2f C |
214 | } |
215 | ||
8a19bee1 | 216 | await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) |
2422c46b | 217 | |
3cd0734f | 218 | await waitJobs(servers) |
5f04dd2f C |
219 | }) |
220 | ||
2422c46b C |
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') | |
5f04dd2f | 224 | |
2422c46b C |
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) | |
8a19bee1 | 228 | expect(res.body.data[0].name).to.equal('second_video_channel') |
2422c46b C |
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') | |
7d14d4d2 C |
231 | expect(res.body.data[0].support).to.equal('support updated') |
232 | } | |
233 | }) | |
234 | ||
235 | it('Should not have updated the video support field', async function () { | |
236 | for (const server of servers) { | |
237 | const res = await getVideo(server.url, videoUUID) | |
238 | const video: VideoDetails = res.body | |
239 | ||
240 | expect(video.support).to.equal('video support field') | |
241 | } | |
242 | }) | |
243 | ||
244 | it('Should update the channel support field and update videos too', async function () { | |
245 | this.timeout(35000) | |
246 | ||
247 | const videoChannelAttributes = { | |
248 | support: 'video channel support text updated', | |
249 | bulkVideosSupportUpdate: true | |
250 | } | |
251 | ||
252 | await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) | |
253 | ||
254 | await waitJobs(servers) | |
255 | ||
256 | for (const server of servers) { | |
257 | const res = await getVideo(server.url, videoUUID) | |
258 | const video: VideoDetails = res.body | |
259 | ||
260 | expect(video.support).to.equal(videoChannelAttributes.support) | |
2422c46b | 261 | } |
5f04dd2f C |
262 | }) |
263 | ||
4bbfc6c6 C |
264 | it('Should update video channel avatar', async function () { |
265 | this.timeout(5000) | |
266 | ||
267 | const fixture = 'avatar.png' | |
268 | ||
269 | await updateVideoChannelAvatar({ | |
270 | url: servers[0].url, | |
271 | accessToken: servers[0].accessToken, | |
8a19bee1 | 272 | videoChannelName: 'second_video_channel', |
4bbfc6c6 C |
273 | fixture |
274 | }) | |
275 | ||
276 | await waitJobs(servers) | |
277 | }) | |
278 | ||
279 | it('Should have video channel avatar updated', async function () { | |
280 | for (const server of servers) { | |
281 | const res = await getVideoChannelsList(server.url, 0, 1, '-name') | |
282 | ||
283 | const videoChannel = res.body.data.find(c => c.id === secondVideoChannelId) | |
284 | ||
285 | await testImage(server.url, 'avatar-resized', videoChannel.avatar.path, '.png') | |
286 | } | |
287 | }) | |
288 | ||
2422c46b | 289 | it('Should get video channel', async function () { |
8a19bee1 | 290 | const res = await getVideoChannel(servers[0].url, 'second_video_channel') |
5f04dd2f C |
291 | |
292 | const videoChannel = res.body | |
8a19bee1 | 293 | expect(videoChannel.name).to.equal('second_video_channel') |
7bc29171 | 294 | expect(videoChannel.displayName).to.equal('video channel updated') |
5f04dd2f | 295 | expect(videoChannel.description).to.equal('video channel description updated') |
2422c46b | 296 | expect(videoChannel.support).to.equal('video channel support text updated') |
5f04dd2f C |
297 | }) |
298 | ||
0f320037 | 299 | it('Should list the second video channel videos', async function () { |
6b738c7a C |
300 | this.timeout(10000) |
301 | ||
302 | for (const server of servers) { | |
48f07b4a | 303 | const channelURI = 'second_video_channel@localhost:' + servers[0].port |
8a19bee1 | 304 | const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) |
0f320037 C |
305 | expect(res1.body.total).to.equal(1) |
306 | expect(res1.body.data).to.be.an('array') | |
307 | expect(res1.body.data).to.have.lengthOf(1) | |
308 | expect(res1.body.data[0].name).to.equal('my video name') | |
309 | } | |
310 | }) | |
311 | ||
312 | it('Should change the video channel of a video', async function () { | |
313 | this.timeout(10000) | |
314 | ||
315 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { channelId: firstVideoChannelId }) | |
316 | ||
3cd0734f | 317 | await waitJobs(servers) |
0f320037 C |
318 | }) |
319 | ||
320 | it('Should list the first video channel videos', async function () { | |
321 | this.timeout(10000) | |
322 | ||
323 | for (const server of servers) { | |
48f07b4a | 324 | const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port |
8a19bee1 | 325 | const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) |
0f320037 C |
326 | expect(res1.body.total).to.equal(0) |
327 | ||
48f07b4a | 328 | const channelURI = 'root_channel@localhost:' + servers[0].port |
8a19bee1 | 329 | const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) |
0f320037 C |
330 | expect(res2.body.total).to.equal(1) |
331 | ||
332 | const videos: Video[] = res2.body.data | |
333 | expect(videos).to.be.an('array') | |
334 | expect(videos).to.have.lengthOf(1) | |
335 | expect(videos[0].name).to.equal('my video name') | |
6b738c7a C |
336 | } |
337 | }) | |
338 | ||
2422c46b | 339 | it('Should delete video channel', async function () { |
8a19bee1 | 340 | await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel') |
5f04dd2f C |
341 | }) |
342 | ||
2422c46b C |
343 | it('Should have video channel deleted', async function () { |
344 | const res = await getVideoChannelsList(servers[0].url, 0, 10) | |
5f04dd2f C |
345 | |
346 | expect(res.body.total).to.equal(1) | |
347 | expect(res.body.data).to.be.an('array') | |
348 | expect(res.body.data).to.have.lengthOf(1) | |
8a19bee1 C |
349 | expect(res.body.data[0].displayName).to.equal('Main root channel') |
350 | }) | |
351 | ||
352 | it('Should create the main channel with an uuid if there is a conflict', async function () { | |
353 | { | |
354 | const videoChannel = { name: 'toto_channel', displayName: 'My toto channel' } | |
a1587156 | 355 | await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) |
8a19bee1 C |
356 | } |
357 | ||
358 | { | |
a1587156 C |
359 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: 'toto', password: 'password' }) |
360 | const accessToken = await userLogin(servers[0], { username: 'toto', password: 'password' }) | |
8a19bee1 | 361 | |
a1587156 C |
362 | const res = await getMyUserInformation(servers[0].url, accessToken) |
363 | const videoChannel = res.body.videoChannels[0] | |
8a19bee1 C |
364 | 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 | } | |
5f04dd2f C |
366 | }) |
367 | ||
714bfcc5 RK |
368 | it('Should report correct channel statistics', async function () { |
369 | ||
370 | { | |
371 | const res = await getAccountVideoChannelsList({ | |
372 | url: servers[0].url, | |
373 | accountName: userInfo.account.name + '@' + userInfo.account.host, | |
374 | withStats: true | |
375 | }) | |
376 | res.body.data.forEach((channel: VideoChannel) => { | |
377 | expect(channel).to.haveOwnProperty('viewsPerDay') | |
378 | expect(channel.viewsPerDay).to.have.length(30 + 1) // daysPrior + today | |
3d527ba1 | 379 | channel.viewsPerDay.forEach((v: ViewsPerDate) => { |
714bfcc5 RK |
380 | expect(v.date).to.be.an('string') |
381 | expect(v.views).to.equal(0) | |
382 | }) | |
383 | }) | |
384 | } | |
385 | ||
386 | { | |
387 | // video has been posted on channel firstVideoChannelId since last update | |
388 | await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.1,127.0.0.1') | |
389 | await viewVideo(servers[0].url, videoUUID, 204, '0.0.0.2,127.0.0.1') | |
390 | ||
391 | // Wait the repeatable job | |
392 | await wait(8000) | |
393 | ||
394 | const res = await getAccountVideoChannelsList({ | |
395 | url: servers[0].url, | |
396 | accountName: userInfo.account.name + '@' + userInfo.account.host, | |
397 | withStats: true | |
398 | }) | |
399 | const channelWithView = res.body.data.find((channel: VideoChannel) => channel.id === firstVideoChannelId) | |
400 | expect(channelWithView.viewsPerDay.slice(-1)[0].views).to.equal(2) | |
401 | } | |
402 | }) | |
403 | ||
7c3b7976 C |
404 | after(async function () { |
405 | await cleanupTests(servers) | |
5f04dd2f C |
406 | }) |
407 | }) |