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