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