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