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 () {
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, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
170 it('Should get the video by UUID', async function () {
173 const video = await server.videos.get({ id: videoUUID })
174 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
177 it('Should have the views updated', async function () {
180 await server.views.simulateView({ id: videoId })
181 await server.views.simulateView({ id: videoId })
182 await server.views.simulateView({ id: videoId })
186 await server.views.simulateView({ id: videoId })
187 await server.views.simulateView({ id: videoId })
191 await server.views.simulateView({ id: videoId })
192 await server.views.simulateView({ id: videoId })
194 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
196 const video = await server.videos.get({ id: videoId })
197 expect(video.views).to.equal(3)
200 it('Should remove the video', async function () {
201 const video = await server.videos.get({ id: videoId })
202 await server.videos.remove({ id: videoId })
204 await checkVideoFilesWereRemoved({ video, server })
207 it('Should not have videos', async function () {
208 const { total, data } = await server.videos.list()
210 expect(total).to.equal(0)
211 expect(data).to.be.an('array')
212 expect(data).to.have.lengthOf(0)
215 it('Should upload 6 videos', async function () {
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'
223 for (const video of videos) {
225 name: video + ' name',
226 description: video + ' description',
231 tags: [ 'tag1', 'tag2', 'tag3' ],
235 await server.videos.upload({ attributes, mode })
239 it('Should have the correct durations', async function () {
240 const { total, data } = await server.videos.list()
242 expect(total).to.equal(6)
243 expect(data).to.be.an('array')
244 expect(data).to.have.lengthOf(6)
246 const videosByName: { [ name: string ]: Video } = {}
247 data.forEach(v => { videosByName[v.name] = v })
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)
257 it('Should have the correct thumbnails', async function () {
258 const { data } = await server.videos.list()
261 videosListBase = data
263 for (const video of data) {
264 const videoName = video.name.replace(' name', '')
265 await testImage(server.url, videoName, video.thumbnailPath)
269 it('Should list only the two first videos', async function () {
270 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' })
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)
278 it('Should list only the next three videos', async function () {
279 const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' })
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)
288 it('Should list the last video', async function () {
289 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' })
291 expect(total).to.equal(6)
292 expect(data.length).to.equal(1)
293 expect(data[0].name).to.equal(videosListBase[5].name)
296 it('Should not have the total field', async function () {
297 const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true })
299 expect(total).to.not.exist
300 expect(data.length).to.equal(1)
301 expect(data[0].name).to.equal(videosListBase[5].name)
304 it('Should list and sort by name in descending order', async function () {
305 const { total, data } = await server.videos.list({ sort: '-name' })
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')
316 videoId = data[3].uuid
317 videoId2 = data[5].uuid
320 it('Should list and sort by trending in descending order', async function () {
321 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' })
323 expect(total).to.equal(6)
324 expect(data.length).to.equal(2)
327 it('Should list and sort by hotness in descending order', async function () {
328 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' })
330 expect(total).to.equal(6)
331 expect(data.length).to.equal(2)
334 it('Should list and sort by best in descending order', async function () {
335 const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' })
337 expect(total).to.equal(6)
338 expect(data.length).to.equal(2)
341 it('Should update a video', async function () {
343 name: 'my super video updated',
348 description: 'my super description updated',
349 commentsEnabled: false,
350 downloadEnabled: false,
351 tags: [ 'tagup1', 'tagup2' ]
353 await server.videos.update({ id: videoId, attributes })
356 it('Should have the video updated', async function () {
359 await waitJobs([ server ])
361 const video = await server.videos.get({ id: videoId })
363 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: updateCheckAttributes() })
366 it('Should update only the tags of a video', async function () {
368 tags: [ 'supertag', 'tag1', 'tag2' ]
370 await server.videos.update({ id: videoId, attributes })
372 const video = await server.videos.get({ id: videoId })
374 await completeVideoCheck({
376 originServer: server,
377 videoUUID: video.uuid,
378 attributes: Object.assign(updateCheckAttributes(), attributes)
382 it('Should update only the description of a video', async function () {
384 description: 'hello everybody'
386 await server.videos.update({ id: videoId, attributes })
388 const video = await server.videos.get({ id: videoId })
390 await completeVideoCheck({
392 originServer: server,
393 videoUUID: video.uuid,
394 attributes: Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
398 it('Should like a video', async function () {
399 await server.videos.rate({ id: videoId, rating: 'like' })
401 const video = await server.videos.get({ id: videoId })
403 expect(video.likes).to.equal(1)
404 expect(video.dislikes).to.equal(0)
407 it('Should dislike the same video', async function () {
408 await server.videos.rate({ id: videoId, rating: 'dislike' })
410 const video = await server.videos.get({ id: videoId })
412 expect(video.likes).to.equal(0)
413 expect(video.dislikes).to.equal(1)
416 it('Should sort by originallyPublishedAt', async function () {
418 const now = new Date()
419 const attributes = { originallyPublishedAt: now.toISOString() }
420 await server.videos.update({ id: videoId, attributes })
422 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
423 const names = data.map(v => v.name)
425 expect(names[0]).to.equal('my super video updated')
426 expect(names[1]).to.equal('video_short2.webm name')
427 expect(names[2]).to.equal('video_short1.webm name')
428 expect(names[3]).to.equal('video_short.webm name')
429 expect(names[4]).to.equal('video_short.ogv name')
430 expect(names[5]).to.equal('video_short.mp4 name')
434 const now = new Date()
435 const attributes = { originallyPublishedAt: now.toISOString() }
436 await server.videos.update({ id: videoId2, attributes })
438 const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
439 const names = data.map(v => v.name)
441 expect(names[0]).to.equal('video_short1.webm name')
442 expect(names[1]).to.equal('my super video updated')
443 expect(names[2]).to.equal('video_short2.webm name')
444 expect(names[3]).to.equal('video_short.webm name')
445 expect(names[4]).to.equal('video_short.ogv name')
446 expect(names[5]).to.equal('video_short.mp4 name')
450 after(async function () {
451 await cleanupTests([ server ])
455 describe('Legacy upload', function () {
459 describe('Resumable upload', function () {
460 runSuite('resumable')