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