1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 checkVideoFilesWereRemoved,
11 setAccessTokensToServers,
14 } from '@shared/extra-utils'
15 import { Video, VideoPrivacy } from '@shared/models'
17 const expect = chai.expect
19 describe('Test a single server', function () {
21 function runSuite (mode: 'legacy' | 'resumable') {
22 let server: PeerTubeServer = null
23 let videoId: number | string
26 let videosListBase: any[] = null
28 const getCheckAttributes = () => ({
29 name: 'my super name',
34 description: 'my super description',
35 support: 'my super support text',
38 host: 'localhost:' + server.port
42 tags: [ 'tag1', 'tag2', 'tag3' ],
43 privacy: VideoPrivacy.PUBLIC,
44 commentsEnabled: true,
45 downloadEnabled: true,
47 displayName: 'Main root channel',
52 fixture: 'video_short.webm',
61 const updateCheckAttributes = () => ({
62 name: 'my super video updated',
67 description: 'my super description updated',
68 support: 'my super support text updated',
71 host: 'localhost:' + server.port
74 tags: [ 'tagup1', 'tagup2' ],
75 privacy: VideoPrivacy.PUBLIC,
77 commentsEnabled: false,
78 downloadEnabled: false,
81 displayName: 'Main root channel',
85 fixture: 'video_short3.webm',
94 before(async function () {
97 server = await createSingleServer(1)
99 await setAccessTokensToServers([ server ])
102 it('Should list video categories', async function () {
103 const categories = await server.videos.getCategories()
104 expect(Object.keys(categories)).to.have.length.above(10)
106 expect(categories[11]).to.equal('News & Politics')
109 it('Should list video licences', async function () {
110 const licences = await server.videos.getLicences()
111 expect(Object.keys(licences)).to.have.length.above(5)
113 expect(licences[3]).to.equal('Attribution - No Derivatives')
116 it('Should list video languages', async function () {
117 const languages = await server.videos.getLanguages()
118 expect(Object.keys(languages)).to.have.length.above(5)
120 expect(languages['ru']).to.equal('Russian')
123 it('Should list video privacies', async function () {
124 const privacies = await server.videos.getPrivacies()
125 expect(Object.keys(privacies)).to.have.length.at.least(3)
127 expect(privacies[3]).to.equal('Private')
130 it('Should not have videos', async function () {
131 const { data, total } = await server.videos.list()
133 expect(total).to.equal(0)
134 expect(data).to.be.an('array')
135 expect(data.length).to.equal(0)
138 it('Should upload the video', async function () {
142 name: 'my super name',
146 tags: [ 'tag1', 'tag2', 'tag3' ]
148 const video = await server.videos.upload({ attributes, mode })
149 expect(video).to.not.be.undefined
150 expect(video.id).to.equal(1)
151 expect(video.uuid).to.have.length.above(5)
154 videoUUID = video.uuid
157 it('Should get and seed the uploaded video', async function () {
160 const { data, total } = await server.videos.list()
162 expect(total).to.equal(1)
163 expect(data).to.be.an('array')
164 expect(data.length).to.equal(1)
166 const video = data[0]
167 await completeVideoCheck(server, video, getCheckAttributes())
170 it('Should get the video by UUID', async function () {
173 const video = await server.videos.get({ id: videoUUID })
174 await completeVideoCheck(server, video, getCheckAttributes())
177 it('Should have the views updated', async function () {
180 await server.videos.view({ id: videoId })
181 await server.videos.view({ id: videoId })
182 await server.videos.view({ id: videoId })
186 await server.videos.view({ id: videoId })
187 await server.videos.view({ id: videoId })
191 await server.videos.view({ id: videoId })
192 await server.videos.view({ id: videoId })
194 // Wait the repeatable job
197 const video = await server.videos.get({ id: videoId })
198 expect(video.views).to.equal(3)
201 it('Should remove the video', async function () {
202 const video = await server.videos.get({ id: videoId })
203 await server.videos.remove({ id: videoId })
205 await checkVideoFilesWereRemoved({ video, server })
208 it('Should not have videos', async function () {
209 const { total, data } = await server.videos.list()
211 expect(total).to.equal(0)
212 expect(data).to.be.an('array')
213 expect(data).to.have.lengthOf(0)
216 it('Should upload 6 videos', async function () {
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'
224 for (const video of videos) {
226 name: video + ' name',
227 description: video + ' description',
232 tags: [ 'tag1', 'tag2', 'tag3' ],
236 await server.videos.upload({ attributes, mode })
240 it('Should have the correct durations', async function () {
241 const { total, data } = await server.videos.list()
243 expect(total).to.equal(6)
244 expect(data).to.be.an('array')
245 expect(data).to.have.lengthOf(6)
247 const videosByName: { [ name: string ]: Video } = {}
248 data.forEach(v => { videosByName[v.name] = v })
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)
258 it('Should have the correct thumbnails', async function () {
259 const { data } = await server.videos.list()
262 videosListBase = data
264 for (const video of data) {
265 const videoName = video.name.replace(' name', '')
266 await testImage(server.url, videoName, video.thumbnailPath)
270 it('Should list only the two first videos', async function () {
271 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' })
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)
279 it('Should list only the next three videos', async function () {
280 const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' })
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)
289 it('Should list the last video', async function () {
290 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' })
292 expect(total).to.equal(6)
293 expect(data.length).to.equal(1)
294 expect(data[0].name).to.equal(videosListBase[5].name)
297 it('Should not have the total field', async function () {
298 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true })
300 expect(total).to.not.exist
301 expect(data.length).to.equal(1)
302 expect(data[0].name).to.equal(videosListBase[5].name)
305 it('Should list and sort by name in descending order', async function () {
306 const { total, data } = await server.videos.list({ sort: '-name' })
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')
317 videoId = data[3].uuid
318 videoId2 = data[5].uuid
321 it('Should list and sort by trending in descending order', async function () {
322 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' })
324 expect(total).to.equal(6)
325 expect(data.length).to.equal(2)
328 it('Should list and sort by hotness in descending order', async function () {
329 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' })
331 expect(total).to.equal(6)
332 expect(data.length).to.equal(2)
335 it('Should list and sort by best in descending order', async function () {
336 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' })
338 expect(total).to.equal(6)
339 expect(data.length).to.equal(2)
342 it('Should update a video', async function () {
344 name: 'my super video updated',
349 description: 'my super description updated',
350 commentsEnabled: false,
351 downloadEnabled: false,
352 tags: [ 'tagup1', 'tagup2' ]
354 await server.videos.update({ id: videoId, attributes })
357 it('Should have the video updated', async function () {
360 const video = await server.videos.get({ id: videoId })
362 await completeVideoCheck(server, video, updateCheckAttributes())
365 it('Should update only the tags of a video', async function () {
367 tags: [ 'supertag', 'tag1', 'tag2' ]
369 await server.videos.update({ id: videoId, attributes })
371 const video = await server.videos.get({ id: videoId })
373 await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes))
376 it('Should update only the description of a video', async function () {
378 description: 'hello everybody'
380 await server.videos.update({ id: videoId, attributes })
382 const video = await server.videos.get({ id: videoId })
384 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
385 await completeVideoCheck(server, video, expectedAttributes)
388 it('Should like a video', async function () {
389 await server.videos.rate({ id: videoId, rating: 'like' })
391 const video = await server.videos.get({ id: videoId })
393 expect(video.likes).to.equal(1)
394 expect(video.dislikes).to.equal(0)
397 it('Should dislike the same video', async function () {
398 await server.videos.rate({ id: videoId, rating: 'dislike' })
400 const video = await server.videos.get({ id: videoId })
402 expect(video.likes).to.equal(0)
403 expect(video.dislikes).to.equal(1)
406 it('Should sort by originallyPublishedAt', async function () {
408 const now = new Date()
409 const attributes = { originallyPublishedAt: now.toISOString() }
410 await server.videos.update({ id: videoId, attributes })
412 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
413 const names = data.map(v => v.name)
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')
424 const now = new Date()
425 const attributes = { originallyPublishedAt: now.toISOString() }
426 await server.videos.update({ id: videoId2, attributes })
428 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
429 const names = data.map(v => v.name)
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')
440 after(async function () {
441 await cleanupTests([ server ])
445 describe('Legacy upload', function () {
449 describe('Resumable upload', function () {
450 runSuite('resumable')