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