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