]> 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 c0535be09d3be2e1a16c516786551008800678bf..9fd52933f7cc9cfa7e2084d29a508fe4635967a4 100644 (file)
@@ -1,20 +1,18 @@
 /* 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,
   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 () {
 
@@ -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' ],
@@ -97,6 +95,8 @@ describe('Test a single server', function () {
       server = await createSingleServer(1)
 
       await setAccessTokensToServers([ server ])
+      await setDefaultChannelAvatar(server)
+      await setDefaultAccountAvatar(server)
     })
 
     it('Should list video categories', async function () {
@@ -164,44 +164,44 @@ describe('Test a single server', function () {
       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.videos.get({ id: videoUUID })
-      await completeVideoCheck(server, video, getCheckAttributes())
+      await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
     })
 
     it('Should have the views updated', async function () {
       this.timeout(20000)
 
-      await server.videos.view({ id: videoId })
-      await server.videos.view({ id: videoId })
-      await server.videos.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.videos.view({ id: videoId })
-      await server.videos.view({ id: videoId })
+      await server.views.simulateView({ id: videoId })
+      await server.views.simulateView({ id: videoId })
 
       await wait(1500)
 
-      await server.videos.view({ id: videoId })
-      await server.videos.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.videos.get({ id: videoId })
       expect(video.views).to.equal(3)
     })
 
     it('Should remove the video', async function () {
+      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 () {
@@ -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',
@@ -353,25 +353,14 @@ describe('Test a single server', function () {
       await server.videos.update({ id: videoId, attributes })
     })
 
-    it('Should filter by tags and category', async function () {
-      {
-        const { data, total } = await server.videos.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.videos.list({ tagsAllOf: [ 'tagup1', 'tagup2' ], categoryOneOf: [ 3 ] })
-        expect(total).to.equal(0)
-      }
-    })
-
     it('Should have the video updated', async function () {
       this.timeout(60000)
 
+      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 () {
@@ -382,7 +371,12 @@ describe('Test a single server', function () {
 
       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 () {
@@ -393,8 +387,12 @@ describe('Test a single server', function () {
 
       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 () {