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