]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { checkVideoFilesWereRemoved, completeVideoCheck, testImage } from '@server/tests/shared' | |
5 | import { wait } from '@shared/core-utils' | |
6 | import { Video, VideoPrivacy } from '@shared/models' | |
7 | import { | |
8 | cleanupTests, | |
9 | createSingleServer, | |
10 | PeerTubeServer, | |
11 | setAccessTokensToServers, | |
12 | setDefaultAccountAvatar, | |
13 | setDefaultChannelAvatar, | |
14 | waitJobs | |
15 | } from '@shared/server-commands' | |
16 | ||
17 | describe('Test a single server', function () { | |
18 | ||
19 | function runSuite (mode: 'legacy' | 'resumable') { | |
20 | let server: PeerTubeServer = null | |
21 | let videoId: number | string | |
22 | let videoId2: string | |
23 | let videoUUID = '' | |
24 | let videosListBase: any[] = null | |
25 | ||
26 | const getCheckAttributes = () => ({ | |
27 | name: 'my super name', | |
28 | category: 2, | |
29 | licence: 6, | |
30 | language: 'zh', | |
31 | nsfw: true, | |
32 | description: 'my super description', | |
33 | support: 'my super support text', | |
34 | account: { | |
35 | name: 'root', | |
36 | host: server.host | |
37 | }, | |
38 | isLocal: true, | |
39 | duration: 5, | |
40 | tags: [ 'tag1', 'tag2', 'tag3' ], | |
41 | privacy: VideoPrivacy.PUBLIC, | |
42 | commentsEnabled: true, | |
43 | downloadEnabled: true, | |
44 | channel: { | |
45 | displayName: 'Main root channel', | |
46 | name: 'root_channel', | |
47 | description: '', | |
48 | isLocal: true | |
49 | }, | |
50 | fixture: 'video_short.webm', | |
51 | files: [ | |
52 | { | |
53 | resolution: 720, | |
54 | size: 218910 | |
55 | } | |
56 | ] | |
57 | }) | |
58 | ||
59 | const updateCheckAttributes = () => ({ | |
60 | name: 'my super video updated', | |
61 | category: 4, | |
62 | licence: 2, | |
63 | language: 'ar', | |
64 | nsfw: false, | |
65 | description: 'my super description updated', | |
66 | support: 'my super support text updated', | |
67 | account: { | |
68 | name: 'root', | |
69 | host: server.host | |
70 | }, | |
71 | isLocal: true, | |
72 | tags: [ 'tagup1', 'tagup2' ], | |
73 | privacy: VideoPrivacy.PUBLIC, | |
74 | duration: 5, | |
75 | commentsEnabled: false, | |
76 | downloadEnabled: false, | |
77 | channel: { | |
78 | name: 'root_channel', | |
79 | displayName: 'Main root channel', | |
80 | description: '', | |
81 | isLocal: true | |
82 | }, | |
83 | fixture: 'video_short3.webm', | |
84 | files: [ | |
85 | { | |
86 | resolution: 720, | |
87 | size: 292677 | |
88 | } | |
89 | ] | |
90 | }) | |
91 | ||
92 | before(async function () { | |
93 | this.timeout(30000) | |
94 | ||
95 | server = await createSingleServer(1) | |
96 | ||
97 | await setAccessTokensToServers([ server ]) | |
98 | await setDefaultChannelAvatar(server) | |
99 | await setDefaultAccountAvatar(server) | |
100 | }) | |
101 | ||
102 | it('Should list video categories', async function () { | |
103 | const categories = await server.videos.getCategories() | |
104 | expect(Object.keys(categories)).to.have.length.above(10) | |
105 | ||
106 | expect(categories[11]).to.equal('News & Politics') | |
107 | }) | |
108 | ||
109 | it('Should list video licences', async function () { | |
110 | const licences = await server.videos.getLicences() | |
111 | expect(Object.keys(licences)).to.have.length.above(5) | |
112 | ||
113 | expect(licences[3]).to.equal('Attribution - No Derivatives') | |
114 | }) | |
115 | ||
116 | it('Should list video languages', async function () { | |
117 | const languages = await server.videos.getLanguages() | |
118 | expect(Object.keys(languages)).to.have.length.above(5) | |
119 | ||
120 | expect(languages['ru']).to.equal('Russian') | |
121 | }) | |
122 | ||
123 | it('Should list video privacies', async function () { | |
124 | const privacies = await server.videos.getPrivacies() | |
125 | expect(Object.keys(privacies)).to.have.length.at.least(3) | |
126 | ||
127 | expect(privacies[3]).to.equal('Private') | |
128 | }) | |
129 | ||
130 | it('Should not have videos', async function () { | |
131 | const { data, total } = await server.videos.list() | |
132 | ||
133 | expect(total).to.equal(0) | |
134 | expect(data).to.be.an('array') | |
135 | expect(data.length).to.equal(0) | |
136 | }) | |
137 | ||
138 | it('Should upload the video', async function () { | |
139 | this.timeout(10000) | |
140 | ||
141 | const attributes = { | |
142 | name: 'my super name', | |
143 | category: 2, | |
144 | nsfw: true, | |
145 | licence: 6, | |
146 | tags: [ 'tag1', 'tag2', 'tag3' ] | |
147 | } | |
148 | const video = await server.videos.upload({ attributes, mode }) | |
149 | expect(video).to.not.be.undefined | |
150 | expect(video.id).to.equal(1) | |
151 | expect(video.uuid).to.have.length.above(5) | |
152 | ||
153 | videoId = video.id | |
154 | videoUUID = video.uuid | |
155 | }) | |
156 | ||
157 | it('Should get and seed the uploaded video', async function () { | |
158 | this.timeout(5000) | |
159 | ||
160 | const { data, total } = await server.videos.list() | |
161 | ||
162 | expect(total).to.equal(1) | |
163 | expect(data).to.be.an('array') | |
164 | expect(data.length).to.equal(1) | |
165 | ||
166 | const video = data[0] | |
167 | await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() }) | |
168 | }) | |
169 | ||
170 | it('Should get the video by UUID', async function () { | |
171 | this.timeout(5000) | |
172 | ||
173 | const video = await server.videos.get({ id: videoUUID }) | |
174 | await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() }) | |
175 | }) | |
176 | ||
177 | it('Should have the views updated', async function () { | |
178 | this.timeout(20000) | |
179 | ||
180 | await server.views.simulateView({ id: videoId }) | |
181 | await server.views.simulateView({ id: videoId }) | |
182 | await server.views.simulateView({ id: videoId }) | |
183 | ||
184 | await wait(1500) | |
185 | ||
186 | await server.views.simulateView({ id: videoId }) | |
187 | await server.views.simulateView({ id: videoId }) | |
188 | ||
189 | await wait(1500) | |
190 | ||
191 | await server.views.simulateView({ id: videoId }) | |
192 | await server.views.simulateView({ id: videoId }) | |
193 | ||
194 | await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } }) | |
195 | ||
196 | const video = await server.videos.get({ id: videoId }) | |
197 | expect(video.views).to.equal(3) | |
198 | }) | |
199 | ||
200 | it('Should remove the video', async function () { | |
201 | const video = await server.videos.get({ id: videoId }) | |
202 | await server.videos.remove({ id: videoId }) | |
203 | ||
204 | await checkVideoFilesWereRemoved({ video, server }) | |
205 | }) | |
206 | ||
207 | it('Should not have videos', async function () { | |
208 | const { total, data } = await server.videos.list() | |
209 | ||
210 | expect(total).to.equal(0) | |
211 | expect(data).to.be.an('array') | |
212 | expect(data).to.have.lengthOf(0) | |
213 | }) | |
214 | ||
215 | it('Should upload 6 videos', async function () { | |
216 | this.timeout(25000) | |
217 | ||
218 | const videos = new Set([ | |
219 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | |
220 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | |
221 | ]) | |
222 | ||
223 | for (const video of videos) { | |
224 | const attributes = { | |
225 | name: video + ' name', | |
226 | description: video + ' description', | |
227 | category: 2, | |
228 | licence: 1, | |
229 | language: 'en', | |
230 | nsfw: true, | |
231 | tags: [ 'tag1', 'tag2', 'tag3' ], | |
232 | fixture: video | |
233 | } | |
234 | ||
235 | await server.videos.upload({ attributes, mode }) | |
236 | } | |
237 | }) | |
238 | ||
239 | it('Should have the correct durations', async function () { | |
240 | const { total, data } = await server.videos.list() | |
241 | ||
242 | expect(total).to.equal(6) | |
243 | expect(data).to.be.an('array') | |
244 | expect(data).to.have.lengthOf(6) | |
245 | ||
246 | const videosByName: { [ name: string ]: Video } = {} | |
247 | data.forEach(v => { videosByName[v.name] = v }) | |
248 | ||
249 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) | |
250 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) | |
251 | expect(videosByName['video_short.webm name'].duration).to.equal(5) | |
252 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) | |
253 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) | |
254 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) | |
255 | }) | |
256 | ||
257 | it('Should have the correct thumbnails', async function () { | |
258 | const { data } = await server.videos.list() | |
259 | ||
260 | // For the next test | |
261 | videosListBase = data | |
262 | ||
263 | for (const video of data) { | |
264 | const videoName = video.name.replace(' name', '') | |
265 | await testImage(server.url, videoName, video.thumbnailPath) | |
266 | } | |
267 | }) | |
268 | ||
269 | it('Should list only the two first videos', async function () { | |
270 | const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' }) | |
271 | ||
272 | expect(total).to.equal(6) | |
273 | expect(data.length).to.equal(2) | |
274 | expect(data[0].name).to.equal(videosListBase[0].name) | |
275 | expect(data[1].name).to.equal(videosListBase[1].name) | |
276 | }) | |
277 | ||
278 | it('Should list only the next three videos', async function () { | |
279 | const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' }) | |
280 | ||
281 | expect(total).to.equal(6) | |
282 | expect(data.length).to.equal(3) | |
283 | expect(data[0].name).to.equal(videosListBase[2].name) | |
284 | expect(data[1].name).to.equal(videosListBase[3].name) | |
285 | expect(data[2].name).to.equal(videosListBase[4].name) | |
286 | }) | |
287 | ||
288 | it('Should list the last video', async function () { | |
289 | const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' }) | |
290 | ||
291 | expect(total).to.equal(6) | |
292 | expect(data.length).to.equal(1) | |
293 | expect(data[0].name).to.equal(videosListBase[5].name) | |
294 | }) | |
295 | ||
296 | it('Should not have the total field', async function () { | |
297 | const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true }) | |
298 | ||
299 | expect(total).to.not.exist | |
300 | expect(data.length).to.equal(1) | |
301 | expect(data[0].name).to.equal(videosListBase[5].name) | |
302 | }) | |
303 | ||
304 | it('Should list and sort by name in descending order', async function () { | |
305 | const { total, data } = await server.videos.list({ sort: '-name' }) | |
306 | ||
307 | expect(total).to.equal(6) | |
308 | expect(data.length).to.equal(6) | |
309 | expect(data[0].name).to.equal('video_short.webm name') | |
310 | expect(data[1].name).to.equal('video_short.ogv name') | |
311 | expect(data[2].name).to.equal('video_short.mp4 name') | |
312 | expect(data[3].name).to.equal('video_short3.webm name') | |
313 | expect(data[4].name).to.equal('video_short2.webm name') | |
314 | expect(data[5].name).to.equal('video_short1.webm name') | |
315 | ||
316 | videoId = data[3].uuid | |
317 | videoId2 = data[5].uuid | |
318 | }) | |
319 | ||
320 | it('Should list and sort by trending in descending order', async function () { | |
321 | const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' }) | |
322 | ||
323 | expect(total).to.equal(6) | |
324 | expect(data.length).to.equal(2) | |
325 | }) | |
326 | ||
327 | it('Should list and sort by hotness in descending order', async function () { | |
328 | const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' }) | |
329 | ||
330 | expect(total).to.equal(6) | |
331 | expect(data.length).to.equal(2) | |
332 | }) | |
333 | ||
334 | it('Should list and sort by best in descending order', async function () { | |
335 | const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' }) | |
336 | ||
337 | expect(total).to.equal(6) | |
338 | expect(data.length).to.equal(2) | |
339 | }) | |
340 | ||
341 | it('Should update a video', async function () { | |
342 | const attributes = { | |
343 | name: 'my super video updated', | |
344 | category: 4, | |
345 | licence: 2, | |
346 | language: 'ar', | |
347 | nsfw: false, | |
348 | description: 'my super description updated', | |
349 | commentsEnabled: false, | |
350 | downloadEnabled: false, | |
351 | tags: [ 'tagup1', 'tagup2' ] | |
352 | } | |
353 | await server.videos.update({ id: videoId, attributes }) | |
354 | }) | |
355 | ||
356 | it('Should have the video updated', async function () { | |
357 | this.timeout(60000) | |
358 | ||
359 | await waitJobs([ server ]) | |
360 | ||
361 | const video = await server.videos.get({ id: videoId }) | |
362 | ||
363 | await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: updateCheckAttributes() }) | |
364 | }) | |
365 | ||
366 | it('Should update only the tags of a video', async function () { | |
367 | const attributes = { | |
368 | tags: [ 'supertag', 'tag1', 'tag2' ] | |
369 | } | |
370 | await server.videos.update({ id: videoId, attributes }) | |
371 | ||
372 | const video = await server.videos.get({ id: videoId }) | |
373 | ||
374 | await completeVideoCheck({ | |
375 | server, | |
376 | originServer: server, | |
377 | videoUUID: video.uuid, | |
378 | attributes: Object.assign(updateCheckAttributes(), attributes) | |
379 | }) | |
380 | }) | |
381 | ||
382 | it('Should update only the description of a video', async function () { | |
383 | const attributes = { | |
384 | description: 'hello everybody' | |
385 | } | |
386 | await server.videos.update({ id: videoId, attributes }) | |
387 | ||
388 | const video = await server.videos.get({ id: videoId }) | |
389 | ||
390 | await completeVideoCheck({ | |
391 | server, | |
392 | originServer: server, | |
393 | videoUUID: video.uuid, | |
394 | attributes: Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) | |
395 | }) | |
396 | }) | |
397 | ||
398 | it('Should like a video', async function () { | |
399 | await server.videos.rate({ id: videoId, rating: 'like' }) | |
400 | ||
401 | const video = await server.videos.get({ id: videoId }) | |
402 | ||
403 | expect(video.likes).to.equal(1) | |
404 | expect(video.dislikes).to.equal(0) | |
405 | }) | |
406 | ||
407 | it('Should dislike the same video', async function () { | |
408 | await server.videos.rate({ id: videoId, rating: 'dislike' }) | |
409 | ||
410 | const video = await server.videos.get({ id: videoId }) | |
411 | ||
412 | expect(video.likes).to.equal(0) | |
413 | expect(video.dislikes).to.equal(1) | |
414 | }) | |
415 | ||
416 | it('Should sort by originallyPublishedAt', async function () { | |
417 | { | |
418 | const now = new Date() | |
419 | const attributes = { originallyPublishedAt: now.toISOString() } | |
420 | await server.videos.update({ id: videoId, attributes }) | |
421 | ||
422 | const { data } = await server.videos.list({ sort: '-originallyPublishedAt' }) | |
423 | const names = data.map(v => v.name) | |
424 | ||
425 | expect(names[0]).to.equal('my super video updated') | |
426 | expect(names[1]).to.equal('video_short2.webm name') | |
427 | expect(names[2]).to.equal('video_short1.webm name') | |
428 | expect(names[3]).to.equal('video_short.webm name') | |
429 | expect(names[4]).to.equal('video_short.ogv name') | |
430 | expect(names[5]).to.equal('video_short.mp4 name') | |
431 | } | |
432 | ||
433 | { | |
434 | const now = new Date() | |
435 | const attributes = { originallyPublishedAt: now.toISOString() } | |
436 | await server.videos.update({ id: videoId2, attributes }) | |
437 | ||
438 | const { data } = await server.videos.list({ sort: '-originallyPublishedAt' }) | |
439 | const names = data.map(v => v.name) | |
440 | ||
441 | expect(names[0]).to.equal('video_short1.webm name') | |
442 | expect(names[1]).to.equal('my super video updated') | |
443 | expect(names[2]).to.equal('video_short2.webm name') | |
444 | expect(names[3]).to.equal('video_short.webm name') | |
445 | expect(names[4]).to.equal('video_short.ogv name') | |
446 | expect(names[5]).to.equal('video_short.mp4 name') | |
447 | } | |
448 | }) | |
449 | ||
450 | after(async function () { | |
451 | await cleanupTests([ server ]) | |
452 | }) | |
453 | } | |
454 | ||
455 | describe('Legacy upload', function () { | |
456 | runSuite('legacy') | |
457 | }) | |
458 | ||
459 | describe('Resumable upload', function () { | |
460 | runSuite('resumable') | |
461 | }) | |
462 | }) |