]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/single-server.ts
Remove transcoding scripts
[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 () {
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
b2111066
C
180 await server.views.simulateView({ id: videoId })
181 await server.views.simulateView({ id: videoId })
182 await server.views.simulateView({ id: videoId })
0e1dc3e7 183
f6d6e7f8 184 await wait(1500)
0e1dc3e7 185
b2111066
C
186 await server.views.simulateView({ id: videoId })
187 await server.views.simulateView({ id: videoId })
fe987656 188
f6d6e7f8 189 await wait(1500)
fe987656 190
b2111066
C
191 await server.views.simulateView({ id: videoId })
192 await server.views.simulateView({ id: videoId })
0e1dc3e7 193
b2111066 194 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
0b74c74a 195
89d241a7 196 const video = await server.videos.get({ id: videoId })
f6d6e7f8 197 expect(video.views).to.equal(3)
198 })
923d3d5a 199
f6d6e7f8 200 it('Should remove the video', async function () {
83903cb6 201 const video = await server.videos.get({ id: videoId })
89d241a7 202 await server.videos.remove({ id: videoId })
923d3d5a 203
83903cb6 204 await checkVideoFilesWereRemoved({ video, server })
f6d6e7f8 205 })
3d4e112d 206
f6d6e7f8 207 it('Should not have videos', async function () {
89d241a7 208 const { total, data } = await server.videos.list()
3d4e112d 209
d23dd9fb
C
210 expect(total).to.equal(0)
211 expect(data).to.be.an('array')
212 expect(data).to.have.lengthOf(0)
f6d6e7f8 213 })
0e1dc3e7 214
f6d6e7f8 215 it('Should upload 6 videos', async function () {
216 this.timeout(25000)
d525fc39 217
f6d6e7f8 218 const videos = new Set([
219 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
220 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
221 ])
d525fc39 222
f6d6e7f8 223 for (const video of videos) {
d23dd9fb 224 const attributes = {
f6d6e7f8 225 name: video + ' name',
226 description: video + ' description',
227 category: 2,
228 licence: 1,
229 language: 'en',
230 nsfw: true,
231 tags: [ 'tag1', 'tag2', 'tag3' ],
232 fixture: video
233 }
0e1dc3e7 234
89d241a7 235 await server.videos.upload({ attributes, mode })
f6d6e7f8 236 }
237 })
238
239 it('Should have the correct durations', async function () {
89d241a7 240 const { total, data } = await server.videos.list()
d23dd9fb
C
241
242 expect(total).to.equal(6)
243 expect(data).to.be.an('array')
244 expect(data).to.have.lengthOf(6)
f6d6e7f8 245
d23dd9fb
C
246 const videosByName: { [ name: string ]: Video } = {}
247 data.forEach(v => { videosByName[v.name] = v })
f6d6e7f8 248
f6d6e7f8 249 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
250 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
251 expect(videosByName['video_short.webm name'].duration).to.equal(5)
252 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
253 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
254 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
255 })
256
257 it('Should have the correct thumbnails', async function () {
89d241a7 258 const { data } = await server.videos.list()
f6d6e7f8 259
f6d6e7f8 260 // For the next test
d23dd9fb 261 videosListBase = data
f6d6e7f8 262
d23dd9fb 263 for (const video of data) {
f6d6e7f8 264 const videoName = video.name.replace(' name', '')
265 await testImage(server.url, videoName, video.thumbnailPath)
266 }
267 })
268
269 it('Should list only the two first videos', async function () {
89d241a7 270 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' })
f6d6e7f8 271
d23dd9fb
C
272 expect(total).to.equal(6)
273 expect(data.length).to.equal(2)
274 expect(data[0].name).to.equal(videosListBase[0].name)
275 expect(data[1].name).to.equal(videosListBase[1].name)
f6d6e7f8 276 })
277
278 it('Should list only the next three videos', async function () {
89d241a7 279 const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' })
f6d6e7f8 280
d23dd9fb
C
281 expect(total).to.equal(6)
282 expect(data.length).to.equal(3)
283 expect(data[0].name).to.equal(videosListBase[2].name)
284 expect(data[1].name).to.equal(videosListBase[3].name)
285 expect(data[2].name).to.equal(videosListBase[4].name)
f6d6e7f8 286 })
287
288 it('Should list the last video', async function () {
89d241a7 289 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' })
f6d6e7f8 290
d23dd9fb
C
291 expect(total).to.equal(6)
292 expect(data.length).to.equal(1)
293 expect(data[0].name).to.equal(videosListBase[5].name)
f6d6e7f8 294 })
295
296 it('Should not have the total field', async function () {
89d241a7 297 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true })
f6d6e7f8 298
d23dd9fb
C
299 expect(total).to.not.exist
300 expect(data.length).to.equal(1)
301 expect(data[0].name).to.equal(videosListBase[5].name)
f6d6e7f8 302 })
303
304 it('Should list and sort by name in descending order', async function () {
89d241a7 305 const { total, data } = await server.videos.list({ sort: '-name' })
f6d6e7f8 306
d23dd9fb
C
307 expect(total).to.equal(6)
308 expect(data.length).to.equal(6)
309 expect(data[0].name).to.equal('video_short.webm name')
310 expect(data[1].name).to.equal('video_short.ogv name')
311 expect(data[2].name).to.equal('video_short.mp4 name')
312 expect(data[3].name).to.equal('video_short3.webm name')
313 expect(data[4].name).to.equal('video_short2.webm name')
314 expect(data[5].name).to.equal('video_short1.webm name')
f6d6e7f8 315
d23dd9fb
C
316 videoId = data[3].uuid
317 videoId2 = data[5].uuid
f6d6e7f8 318 })
319
320 it('Should list and sort by trending in descending order', async function () {
89d241a7 321 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' })
f6d6e7f8 322
d23dd9fb
C
323 expect(total).to.equal(6)
324 expect(data.length).to.equal(2)
f6d6e7f8 325 })
326
327 it('Should list and sort by hotness in descending order', async function () {
89d241a7 328 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' })
f6d6e7f8 329
d23dd9fb
C
330 expect(total).to.equal(6)
331 expect(data.length).to.equal(2)
f6d6e7f8 332 })
333
334 it('Should list and sort by best in descending order', async function () {
89d241a7 335 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' })
f6d6e7f8 336
d23dd9fb
C
337 expect(total).to.equal(6)
338 expect(data.length).to.equal(2)
f6d6e7f8 339 })
340
341 it('Should update a video', async function () {
342 const attributes = {
343 name: 'my super video updated',
344 category: 4,
345 licence: 2,
346 language: 'ar',
347 nsfw: false,
348 description: 'my super description updated',
349 commentsEnabled: false,
350 downloadEnabled: false,
351 tags: [ 'tagup1', 'tagup2' ]
352 }
89d241a7 353 await server.videos.update({ id: videoId, attributes })
f6d6e7f8 354 })
0e1dc3e7 355
f6d6e7f8 356 it('Should have the video updated', async function () {
357 this.timeout(60000)
0e1dc3e7 358
06ac1289
C
359 await waitJobs([ server ])
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})