]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/single-server.ts
Fix reset sequelize instance
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / single-server.ts
index da0b2011e2d815df812fb64619b5efa984415042..9fd52933f7cc9cfa7e2084d29a508fe4635967a4 100644 (file)
@@ -1,25 +1,23 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
+import { expect } from 'chai'
+import { checkVideoFilesWereRemoved, completeVideoCheck, testImage } from '@server/tests/shared'
+import { wait } from '@shared/core-utils'
+import { Video, VideoPrivacy } from '@shared/models'
 import {
-  checkVideoFilesWereRemoved,
   cleanupTests,
-  completeVideoCheck,
-  flushAndRunServer,
-  ServerInfo,
+  createSingleServer,
+  PeerTubeServer,
   setAccessTokensToServers,
-  testImage,
-  wait
-} from '@shared/extra-utils'
-import { Video, VideoPrivacy } from '@shared/models'
-
-const expect = chai.expect
+  setDefaultAccountAvatar,
+  setDefaultChannelAvatar,
+  waitJobs
+} from '@shared/server-commands'
 
 describe('Test a single server', function () {
 
   function runSuite (mode: 'legacy' | 'resumable') {
-    let server: ServerInfo = null
+    let server: PeerTubeServer = null
     let videoId: number | string
     let videoId2: string
     let videoUUID = ''
@@ -35,7 +33,7 @@ describe('Test a single server', function () {
       support: 'my super support text',
       account: {
         name: 'root',
-        host: 'localhost:' + server.port
+        host: server.host
       },
       isLocal: true,
       duration: 5,
@@ -68,7 +66,7 @@ describe('Test a single server', function () {
       support: 'my super support text updated',
       account: {
         name: 'root',
-        host: 'localhost:' + server.port
+        host: server.host
       },
       isLocal: true,
       tags: [ 'tagup1', 'tagup2' ],
@@ -94,41 +92,43 @@ describe('Test a single server', function () {
     before(async function () {
       this.timeout(30000)
 
-      server = await flushAndRunServer(1)
+      server = await createSingleServer(1)
 
       await setAccessTokensToServers([ server ])
+      await setDefaultChannelAvatar(server)
+      await setDefaultAccountAvatar(server)
     })
 
     it('Should list video categories', async function () {
-      const categories = await server.videosCommand.getCategories()
+      const categories = await server.videos.getCategories()
       expect(Object.keys(categories)).to.have.length.above(10)
 
       expect(categories[11]).to.equal('News & Politics')
     })
 
     it('Should list video licences', async function () {
-      const licences = await server.videosCommand.getLicences()
+      const licences = await server.videos.getLicences()
       expect(Object.keys(licences)).to.have.length.above(5)
 
       expect(licences[3]).to.equal('Attribution - No Derivatives')
     })
 
     it('Should list video languages', async function () {
-      const languages = await server.videosCommand.getLanguages()
+      const languages = await server.videos.getLanguages()
       expect(Object.keys(languages)).to.have.length.above(5)
 
       expect(languages['ru']).to.equal('Russian')
     })
 
     it('Should list video privacies', async function () {
-      const privacies = await server.videosCommand.getPrivacies()
+      const privacies = await server.videos.getPrivacies()
       expect(Object.keys(privacies)).to.have.length.at.least(3)
 
       expect(privacies[3]).to.equal('Private')
     })
 
     it('Should not have videos', async function () {
-      const { data, total } = await server.videosCommand.list()
+      const { data, total } = await server.videos.list()
 
       expect(total).to.equal(0)
       expect(data).to.be.an('array')
@@ -145,7 +145,7 @@ describe('Test a single server', function () {
         licence: 6,
         tags: [ 'tag1', 'tag2', 'tag3' ]
       }
-      const video = await server.videosCommand.upload({ attributes, mode })
+      const video = await server.videos.upload({ attributes, mode })
       expect(video).to.not.be.undefined
       expect(video.id).to.equal(1)
       expect(video.uuid).to.have.length.above(5)
@@ -157,55 +157,55 @@ describe('Test a single server', function () {
     it('Should get and seed the uploaded video', async function () {
       this.timeout(5000)
 
-      const { data, total } = await server.videosCommand.list()
+      const { data, total } = await server.videos.list()
 
       expect(total).to.equal(1)
       expect(data).to.be.an('array')
       expect(data.length).to.equal(1)
 
       const video = data[0]
-      await completeVideoCheck(server, video, getCheckAttributes())
+      await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
     })
 
     it('Should get the video by UUID', async function () {
       this.timeout(5000)
 
-      const video = await server.videosCommand.get({ id: videoUUID })
-      await completeVideoCheck(server, video, getCheckAttributes())
+      const video = await server.videos.get({ id: videoUUID })
+      await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
     })
 
     it('Should have the views updated', async function () {
       this.timeout(20000)
 
-      await server.videosCommand.view({ id: videoId })
-      await server.videosCommand.view({ id: videoId })
-      await server.videosCommand.view({ id: videoId })
+      await server.views.simulateView({ id: videoId })
+      await server.views.simulateView({ id: videoId })
+      await server.views.simulateView({ id: videoId })
 
       await wait(1500)
 
-      await server.videosCommand.view({ id: videoId })
-      await server.videosCommand.view({ id: videoId })
+      await server.views.simulateView({ id: videoId })
+      await server.views.simulateView({ id: videoId })
 
       await wait(1500)
 
-      await server.videosCommand.view({ id: videoId })
-      await server.videosCommand.view({ id: videoId })
+      await server.views.simulateView({ id: videoId })
+      await server.views.simulateView({ id: videoId })
 
-      // Wait the repeatable job
-      await wait(8000)
+      await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
 
-      const video = await server.videosCommand.get({ id: videoId })
+      const video = await server.videos.get({ id: videoId })
       expect(video.views).to.equal(3)
     })
 
     it('Should remove the video', async function () {
-      await server.videosCommand.remove({ id: videoId })
+      const video = await server.videos.get({ id: videoId })
+      await server.videos.remove({ id: videoId })
 
-      await checkVideoFilesWereRemoved(videoUUID, server)
+      await checkVideoFilesWereRemoved({ video, server })
     })
 
     it('Should not have videos', async function () {
-      const { total, data } = await server.videosCommand.list()
+      const { total, data } = await server.videos.list()
 
       expect(total).to.equal(0)
       expect(data).to.be.an('array')
@@ -213,7 +213,7 @@ describe('Test a single server', function () {
     })
 
     it('Should upload 6 videos', async function () {
-      this.timeout(25000)
+      this.timeout(50000)
 
       const videos = new Set([
         'video_short.mp4', 'video_short.ogv', 'video_short.webm',
@@ -232,12 +232,12 @@ describe('Test a single server', function () {
           fixture: video
         }
 
-        await server.videosCommand.upload({ attributes, mode })
+        await server.videos.upload({ attributes, mode })
       }
     })
 
     it('Should have the correct durations', async function () {
-      const { total, data } = await server.videosCommand.list()
+      const { total, data } = await server.videos.list()
 
       expect(total).to.equal(6)
       expect(data).to.be.an('array')
@@ -255,7 +255,7 @@ describe('Test a single server', function () {
     })
 
     it('Should have the correct thumbnails', async function () {
-      const { data } = await server.videosCommand.list()
+      const { data } = await server.videos.list()
 
       // For the next test
       videosListBase = data
@@ -267,7 +267,7 @@ describe('Test a single server', function () {
     })
 
     it('Should list only the two first videos', async function () {
-      const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: 'name' })
+      const { total, data } = await server.videos.list({ start: 0, count: 2, sort: 'name' })
 
       expect(total).to.equal(6)
       expect(data.length).to.equal(2)
@@ -276,7 +276,7 @@ describe('Test a single server', function () {
     })
 
     it('Should list only the next three videos', async function () {
-      const { total, data } = await server.videosCommand.list({ start: 2, count: 3, sort: 'name' })
+      const { total, data } = await server.videos.list({ start: 2, count: 3, sort: 'name' })
 
       expect(total).to.equal(6)
       expect(data.length).to.equal(3)
@@ -286,7 +286,7 @@ describe('Test a single server', function () {
     })
 
     it('Should list the last video', async function () {
-      const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name' })
+      const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name' })
 
       expect(total).to.equal(6)
       expect(data.length).to.equal(1)
@@ -294,7 +294,7 @@ describe('Test a single server', function () {
     })
 
     it('Should not have the total field', async function () {
-      const { total, data } = await server.videosCommand.list({ start: 5, count: 6, sort: 'name', skipCount: true })
+      const { total, data } = await server.videos.list({ start: 5, count: 6, sort: 'name', skipCount: true })
 
       expect(total).to.not.exist
       expect(data.length).to.equal(1)
@@ -302,7 +302,7 @@ describe('Test a single server', function () {
     })
 
     it('Should list and sort by name in descending order', async function () {
-      const { total, data } = await server.videosCommand.list({ sort: '-name' })
+      const { total, data } = await server.videos.list({ sort: '-name' })
 
       expect(total).to.equal(6)
       expect(data.length).to.equal(6)
@@ -318,21 +318,21 @@ describe('Test a single server', function () {
     })
 
     it('Should list and sort by trending in descending order', async function () {
-      const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-trending' })
+      const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-trending' })
 
       expect(total).to.equal(6)
       expect(data.length).to.equal(2)
     })
 
     it('Should list and sort by hotness in descending order', async function () {
-      const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-hot' })
+      const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-hot' })
 
       expect(total).to.equal(6)
       expect(data.length).to.equal(2)
     })
 
     it('Should list and sort by best in descending order', async function () {
-      const { total, data } = await server.videosCommand.list({ start: 0, count: 2, sort: '-best' })
+      const { total, data } = await server.videos.list({ start: 0, count: 2, sort: '-best' })
 
       expect(total).to.equal(6)
       expect(data.length).to.equal(2)
@@ -350,66 +350,64 @@ describe('Test a single server', function () {
         downloadEnabled: false,
         tags: [ 'tagup1', 'tagup2' ]
       }
-      await server.videosCommand.update({ id: videoId, attributes })
-    })
-
-    it('Should filter by tags and category', async function () {
-      {
-        const { data, total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 4 ] })
-        expect(total).to.equal(1)
-        expect(data[0].name).to.equal('my super video updated')
-      }
-
-      {
-        const { total } = await server.videosCommand.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
-        expect(total).to.equal(0)
-      }
+      await server.videos.update({ id: videoId, attributes })
     })
 
     it('Should have the video updated', async function () {
       this.timeout(60000)
 
-      const video = await server.videosCommand.get({ id: videoId })
+      await waitJobs([ server ])
+
+      const video = await server.videos.get({ id: videoId })
 
-      await completeVideoCheck(server, video, updateCheckAttributes())
+      await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: updateCheckAttributes() })
     })
 
     it('Should update only the tags of a video', async function () {
       const attributes = {
         tags: [ 'supertag', 'tag1', 'tag2' ]
       }
-      await server.videosCommand.update({ id: videoId, attributes })
+      await server.videos.update({ id: videoId, attributes })
 
-      const video = await server.videosCommand.get({ id: videoId })
+      const video = await server.videos.get({ id: videoId })
 
-      await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes))
+      await completeVideoCheck({
+        server,
+        originServer: server,
+        videoUUID: video.uuid,
+        attributes: Object.assign(updateCheckAttributes(), attributes)
+      })
     })
 
     it('Should update only the description of a video', async function () {
       const attributes = {
         description: 'hello everybody'
       }
-      await server.videosCommand.update({ id: videoId, attributes })
+      await server.videos.update({ id: videoId, attributes })
 
-      const video = await server.videosCommand.get({ id: videoId })
+      const video = await server.videos.get({ id: videoId })
 
-      const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
-      await completeVideoCheck(server, video, expectedAttributes)
+      await completeVideoCheck({
+        server,
+        originServer: server,
+        videoUUID: video.uuid,
+        attributes: Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
+      })
     })
 
     it('Should like a video', async function () {
-      await server.videosCommand.rate({ id: videoId, rating: 'like' })
+      await server.videos.rate({ id: videoId, rating: 'like' })
 
-      const video = await server.videosCommand.get({ id: videoId })
+      const video = await server.videos.get({ id: videoId })
 
       expect(video.likes).to.equal(1)
       expect(video.dislikes).to.equal(0)
     })
 
     it('Should dislike the same video', async function () {
-      await server.videosCommand.rate({ id: videoId, rating: 'dislike' })
+      await server.videos.rate({ id: videoId, rating: 'dislike' })
 
-      const video = await server.videosCommand.get({ id: videoId })
+      const video = await server.videos.get({ id: videoId })
 
       expect(video.likes).to.equal(0)
       expect(video.dislikes).to.equal(1)
@@ -419,9 +417,9 @@ describe('Test a single server', function () {
       {
         const now = new Date()
         const attributes = { originallyPublishedAt: now.toISOString() }
-        await server.videosCommand.update({ id: videoId, attributes })
+        await server.videos.update({ id: videoId, attributes })
 
-        const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' })
+        const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
         const names = data.map(v => v.name)
 
         expect(names[0]).to.equal('my super video updated')
@@ -435,9 +433,9 @@ describe('Test a single server', function () {
       {
         const now = new Date()
         const attributes = { originallyPublishedAt: now.toISOString() }
-        await server.videosCommand.update({ id: videoId2, attributes })
+        await server.videos.update({ id: videoId2, attributes })
 
-        const { data } = await server.videosCommand.list({ sort: '-originallyPublishedAt' })
+        const { data } = await server.videos.list({ sort: '-originallyPublishedAt' })
         const names = data.map(v => v.name)
 
         expect(names[0]).to.equal('video_short1.webm name')