]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { User, Video, VideoChannel, VideoDetails } from '../../../../shared/index' | |
6 | import { | |
7 | cleanupTests, | |
8 | createUser, | |
9 | doubleFollow, | |
10 | flushAndRunMultipleServers, | |
11 | getVideo, | |
12 | getVideoChannelVideos, | |
13 | testImage, | |
14 | updateVideo, | |
15 | updateVideoChannelAvatar, | |
16 | uploadVideo, | |
17 | userLogin | |
18 | } from '../../../../shared/extra-utils' | |
19 | import { | |
20 | addVideoChannel, | |
21 | deleteVideoChannel, | |
22 | getAccountVideoChannelsList, | |
23 | getMyUserInformation, | |
24 | getVideoChannel, | |
25 | getVideoChannelsList, | |
26 | ServerInfo, | |
27 | setAccessTokensToServers, | |
28 | updateVideoChannel | |
29 | } from '../../../../shared/extra-utils/index' | |
30 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
31 | ||
32 | const expect = chai.expect | |
33 | ||
34 | describe('Test video channels', function () { | |
35 | let servers: ServerInfo[] | |
36 | let userInfo: User | |
37 | let firstVideoChannelId: number | |
38 | let secondVideoChannelId: number | |
39 | let videoUUID: string | |
40 | ||
41 | before(async function () { | |
42 | this.timeout(60000) | |
43 | ||
44 | servers = await flushAndRunMultipleServers(2) | |
45 | ||
46 | await setAccessTokensToServers(servers) | |
47 | await doubleFollow(servers[0], servers[1]) | |
48 | ||
49 | { | |
50 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
51 | const user: User = res.body | |
52 | ||
53 | firstVideoChannelId = user.videoChannels[0].id | |
54 | } | |
55 | ||
56 | await waitJobs(servers) | |
57 | }) | |
58 | ||
59 | it('Should have one video channel (created with root)', async () => { | |
60 | const res = await getVideoChannelsList(servers[0].url, 0, 2) | |
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 | ||
67 | it('Should create another video channel', async function () { | |
68 | this.timeout(10000) | |
69 | ||
70 | { | |
71 | const videoChannel = { | |
72 | name: 'second_video_channel', | |
73 | displayName: 'second video channel', | |
74 | description: 'super video channel description', | |
75 | support: 'super video channel support text' | |
76 | } | |
77 | const res = await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) | |
78 | secondVideoChannelId = res.body.videoChannel.id | |
79 | } | |
80 | ||
81 | // The channel is 1 is propagated to servers 2 | |
82 | { | |
83 | const videoAttributesArg = { name: 'my video name', channelId: secondVideoChannelId, support: 'video support field' } | |
84 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributesArg) | |
85 | videoUUID = res.body.video.uuid | |
86 | } | |
87 | ||
88 | await waitJobs(servers) | |
89 | }) | |
90 | ||
91 | it('Should have two video channels when getting my information', async () => { | |
92 | const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) | |
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 | |
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') | |
103 | expect(videoChannels[1].displayName).to.equal('second video channel') | |
104 | expect(videoChannels[1].description).to.equal('super video channel description') | |
105 | expect(videoChannels[1].support).to.equal('super video channel support text') | |
106 | }) | |
107 | ||
108 | it('Should have two video channels when getting account channels on server 1', async function () { | |
109 | const res = await getAccountVideoChannelsList({ | |
110 | url: servers[0].url, | |
111 | accountName: userInfo.account.name + '@' + userInfo.account.host | |
112 | }) | |
113 | ||
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 | |
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') | |
123 | expect(videoChannels[1].displayName).to.equal('second video channel') | |
124 | expect(videoChannels[1].description).to.equal('super video channel description') | |
125 | expect(videoChannels[1].support).to.equal('super video channel support text') | |
126 | }) | |
127 | ||
128 | it('Should paginate and sort account channels', async function () { | |
129 | { | |
130 | const res = await getAccountVideoChannelsList({ | |
131 | url: servers[0].url, | |
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 | ||
141 | const videoChannel: VideoChannel = res.body.data[0] | |
142 | expect(videoChannel.name).to.equal('root_channel') | |
143 | } | |
144 | ||
145 | { | |
146 | const res = await getAccountVideoChannelsList({ | |
147 | url: servers[0].url, | |
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 | ||
157 | const videoChannel: VideoChannel = res.body.data[0] | |
158 | expect(videoChannel.name).to.equal('second_video_channel') | |
159 | } | |
160 | ||
161 | { | |
162 | const res = await getAccountVideoChannelsList({ | |
163 | url: servers[0].url, | |
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 | ||
173 | const videoChannel: VideoChannel = res.body.data[0] | |
174 | expect(videoChannel.name).to.equal('root_channel') | |
175 | } | |
176 | }) | |
177 | ||
178 | it('Should have one video channel when getting account channels on server 2', async function () { | |
179 | const res = await getAccountVideoChannelsList({ | |
180 | url: servers[1].url, | |
181 | accountName: userInfo.account.name + '@' + userInfo.account.host | |
182 | }) | |
183 | ||
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) | |
187 | ||
188 | const videoChannels = res.body.data | |
189 | expect(videoChannels[0].name).to.equal('second_video_channel') | |
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') | |
193 | }) | |
194 | ||
195 | it('Should list video channels', async function () { | |
196 | const res = await getVideoChannelsList(servers[0].url, 1, 1, '-name') | |
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) | |
201 | expect(res.body.data[0].name).to.equal('root_channel') | |
202 | expect(res.body.data[0].displayName).to.equal('Main root channel') | |
203 | }) | |
204 | ||
205 | it('Should update video channel', async function () { | |
206 | this.timeout(15000) | |
207 | ||
208 | const videoChannelAttributes = { | |
209 | displayName: 'video channel updated', | |
210 | description: 'video channel description updated', | |
211 | support: 'support updated' | |
212 | } | |
213 | ||
214 | await updateVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel', videoChannelAttributes) | |
215 | ||
216 | await waitJobs(servers) | |
217 | }) | |
218 | ||
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') | |
222 | ||
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) | |
226 | expect(res.body.data[0].name).to.equal('second_video_channel') | |
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') | |
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) | |
259 | } | |
260 | }) | |
261 | ||
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, | |
270 | videoChannelName: 'second_video_channel', | |
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 | ||
287 | it('Should get video channel', async function () { | |
288 | const res = await getVideoChannel(servers[0].url, 'second_video_channel') | |
289 | ||
290 | const videoChannel = res.body | |
291 | expect(videoChannel.name).to.equal('second_video_channel') | |
292 | expect(videoChannel.displayName).to.equal('video channel updated') | |
293 | expect(videoChannel.description).to.equal('video channel description updated') | |
294 | expect(videoChannel.support).to.equal('video channel support text updated') | |
295 | }) | |
296 | ||
297 | it('Should list the second video channel videos', async function () { | |
298 | this.timeout(10000) | |
299 | ||
300 | for (const server of servers) { | |
301 | const channelURI = 'second_video_channel@localhost:' + servers[0].port | |
302 | const res1 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) | |
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 | ||
315 | await waitJobs(servers) | |
316 | }) | |
317 | ||
318 | it('Should list the first video channel videos', async function () { | |
319 | this.timeout(10000) | |
320 | ||
321 | for (const server of servers) { | |
322 | const secondChannelURI = 'second_video_channel@localhost:' + servers[0].port | |
323 | const res1 = await getVideoChannelVideos(server.url, server.accessToken, secondChannelURI, 0, 5) | |
324 | expect(res1.body.total).to.equal(0) | |
325 | ||
326 | const channelURI = 'root_channel@localhost:' + servers[0].port | |
327 | const res2 = await getVideoChannelVideos(server.url, server.accessToken, channelURI, 0, 5) | |
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') | |
334 | } | |
335 | }) | |
336 | ||
337 | it('Should delete video channel', async function () { | |
338 | await deleteVideoChannel(servers[0].url, servers[0].accessToken, 'second_video_channel') | |
339 | }) | |
340 | ||
341 | it('Should have video channel deleted', async function () { | |
342 | const res = await getVideoChannelsList(servers[0].url, 0, 10) | |
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) | |
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' } | |
353 | await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) | |
354 | } | |
355 | ||
356 | { | |
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' }) | |
359 | ||
360 | const res = await getMyUserInformation(servers[0].url, accessToken) | |
361 | const videoChannel = res.body.videoChannels[0] | |
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 | } | |
364 | }) | |
365 | ||
366 | after(async function () { | |
367 | await cleanupTests(servers) | |
368 | }) | |
369 | }) |