1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { checkVideoFilesWereRemoved, completeVideoCheck, testImage } from '@server/tests/shared'
5 import { wait } from '@shared/core-utils'
6 import { Video, VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultAccountAvatar,
13 setDefaultChannelAvatar,
15 } from '@shared/server-commands'
17 describe('Test a single server', function () {
19 function runSuite (mode: 'legacy' | 'resumable') {
20 let server: PeerTubeServer = null
21 let videoId: number | string
24 let videosListBase: any[] = null
26 const getCheckAttributes = () => ({
27 name: 'my super name',
32 description: 'my super description',
33 support: 'my super support text',
40 tags: [ 'tag1', 'tag2', 'tag3' ],
41 privacy: VideoPrivacy.PUBLIC,
42 commentsEnabled: true,
43 downloadEnabled: true,
45 displayName: 'Main root channel',
50 fixture: 'video_short.webm',
59 const updateCheckAttributes = () => ({
60 name: 'my super video updated',
65 description: 'my super description updated',
66 support: 'my super support text updated',
72 tags: [ 'tagup1', 'tagup2' ],
73 privacy: VideoPrivacy.PUBLIC,
75 commentsEnabled: false,
76 downloadEnabled: false,
79 displayName: 'Main root channel',
83 fixture: 'video_short3.webm',
92 before(async function () {
95 server = await createSingleServer(1)
97 await setAccessTokensToServers([ server ])
98 await setDefaultChannelAvatar(server)
99 await setDefaultAccountAvatar(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 () {
140 name: 'my super name',
144 tags: [ 'tag1', 'tag2', 'tag3' ]
146 const video = await server.videos.upload({ attributes, mode })
147 expect(video).to.not.be.undefined
148 expect(video.id).to.equal(1)
149 expect(video.uuid).to.have.length.above(5)
152 videoUUID = video.uuid
155 it('Should get and seed the uploaded video', async function () {
158 const { data, total } = await server.videos.list()
160 expect(total).to.equal(1)
161 expect(data).to.be.an('array')
162 expect(data.length).to.equal(1)
164 const video = data[0]
165 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
168 it('Should get the video by UUID', async function () {
171 const video = await server.videos.get({ id: videoUUID })
172 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
175 it('Should have the views updated', async function () {
178 await server.views.simulateView({ id: videoId })
179 await server.views.simulateView({ id: videoId })
180 await server.views.simulateView({ id: videoId })
184 await server.views.simulateView({ id: videoId })
185 await server.views.simulateView({ id: videoId })
189 await server.views.simulateView({ id: videoId })
190 await server.views.simulateView({ id: videoId })
192 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
194 const video = await server.videos.get({ id: videoId })
195 expect(video.views).to.equal(3)
198 it('Should remove the video', async function () {
199 const video = await server.videos.get({ id: videoId })
200 await server.videos.remove({ id: videoId })
202 await checkVideoFilesWereRemoved({ video, server })
205 it('Should not have videos', async function () {
206 const { total, data } = await server.videos.list()
208 expect(total).to.equal(0)
209 expect(data).to.be.an('array')
210 expect(data).to.have.lengthOf(0)
213 it('Should upload 6 videos', async function () {
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'
221 for (const video of videos) {
223 name: video + ' name',
224 description: video + ' description',
229 tags: [ 'tag1', 'tag2', 'tag3' ],
233 await server.videos.upload({ attributes, mode })
237 it('Should have the correct durations', async function () {
238 const { total, data } = await server.videos.list()
240 expect(total).to.equal(6)
241 expect(data).to.be.an('array')
242 expect(data).to.have.lengthOf(6)
244 const videosByName: { [ name: string ]: Video } = {}
245 data.forEach(v => { videosByName[v.name] = v })
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)
255 it('Should have the correct thumbnails', async function () {
256 const { data } = await server.videos.list()
259 videosListBase = data
261 for (const video of data) {
262 const videoName = video.name.replace(' name', '')
263 await testImage(server.url, videoName, video.thumbnailPath)
267 it('Should list only the two first videos', async function () {
268 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' })
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)
276 it('Should list only the next three videos', async function () {
277 const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' })
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)
286 it('Should list the last video', async function () {
287 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' })
289 expect(total).to.equal(6)
290 expect(data.length).to.equal(1)
291 expect(data[0].name).to.equal(videosListBase[5].name)
294 it('Should not have the total field', async function () {
295 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true })
297 expect(total).to.not.exist
298 expect(data.length).to.equal(1)
299 expect(data[0].name).to.equal(videosListBase[5].name)
302 it('Should list and sort by name in descending order', async function () {
303 const { total, data } = await server.videos.list({ sort: '-name' })
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')
314 videoId = data[3].uuid
315 videoId2 = data[5].uuid
318 it('Should list and sort by trending in descending order', async function () {
319 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' })
321 expect(total).to.equal(6)
322 expect(data.length).to.equal(2)
325 it('Should list and sort by hotness in descending order', async function () {
326 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' })
328 expect(total).to.equal(6)
329 expect(data.length).to.equal(2)
332 it('Should list and sort by best in descending order', async function () {
333 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' })
335 expect(total).to.equal(6)
336 expect(data.length).to.equal(2)
339 it('Should update a video', async function () {
341 name: 'my super video updated',
346 description: 'my super description updated',
347 commentsEnabled: false,
348 downloadEnabled: false,
349 tags: [ 'tagup1', 'tagup2' ]
351 await server.videos.update({ id: videoId, attributes })
354 it('Should have the video updated', async function () {
357 await waitJobs([ server ])
359 const video = await server.videos.get({ id: videoId })
361 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: updateCheckAttributes() })
364 it('Should update only the tags of a video', async function () {
366 tags: [ 'supertag', 'tag1', 'tag2' ]
368 await server.videos.update({ id: videoId, attributes })
370 const video = await server.videos.get({ id: videoId })
372 await completeVideoCheck({
374 originServer: server,
375 videoUUID: video.uuid,
376 attributes: Object.assign(updateCheckAttributes(), attributes)
380 it('Should update only the description of a video', async function () {
382 description: 'hello everybody'
384 await server.videos.update({ id: videoId, attributes })
386 const video = await server.videos.get({ id: videoId })
388 await completeVideoCheck({
390 originServer: server,
391 videoUUID: video.uuid,
392 attributes: Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
396 it('Should like a video', async function () {
397 await server.videos.rate({ id: videoId, rating: 'like' })
399 const video = await server.videos.get({ id: videoId })
401 expect(video.likes).to.equal(1)
402 expect(video.dislikes).to.equal(0)
405 it('Should dislike the same video', async function () {
406 await server.videos.rate({ id: videoId, rating: 'dislike' })
408 const video = await server.videos.get({ id: videoId })
410 expect(video.likes).to.equal(0)
411 expect(video.dislikes).to.equal(1)
414 it('Should sort by originallyPublishedAt', async function () {
416 const now = new Date()
417 const attributes = { originallyPublishedAt: now.toISOString() }
418 await server.videos.update({ id: videoId, attributes })
420 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
421 const names = data.map(v => v.name)
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')
432 const now = new Date()
433 const attributes = { originallyPublishedAt: now.toISOString() }
434 await server.videos.update({ id: videoId2, attributes })
436 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
437 const names = data.map(v => v.name)
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')
448 after(async function () {
449 await cleanupTests([ server ])
453 describe('Legacy upload', function () {
457 describe('Resumable upload', function () {
458 runSuite('resumable')