]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/jobs.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / jobs.ts
index 2e17e71a423af89191e1439c66e3b1a82e2a2c5b..19c8836b59ba8641ebb04ac02661b19518585d6a 100644 (file)
@@ -1,13 +1,14 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import * as chai from 'chai'
 import 'mocha'
-import { flushTests, killallServers, ServerInfo, setAccessTokensToServers, wait } from '../../utils/index'
-import { doubleFollow } from '../../utils/server/follows'
-import { getJobsList, getJobsListPaginationAndSort } from '../../utils/server/jobs'
-import { flushAndRunMultipleServers } from '../../utils/server/servers'
-import { uploadVideo } from '../../utils/videos/videos'
-import { dateIsValid } from '../../utils/miscs/miscs'
+import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
+import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
+import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
+import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers'
+import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
+import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
+import { Job } from '../../../../shared/models/server'
 
 const expect = chai.expect
 
@@ -26,39 +27,63 @@ describe('Test jobs', function () {
   })
 
   it('Should create some jobs', async function () {
-    this.timeout(30000)
+    this.timeout(60000)
 
     await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
     await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
 
-    await wait(15000)
+    await waitJobs(servers)
   })
 
   it('Should list jobs', async function () {
-    const res = await getJobsList(servers[1].url, servers[1].accessToken)
+    const res = await getJobsList(servers[1].url, servers[1].accessToken, 'completed')
     expect(res.body.total).to.be.above(2)
     expect(res.body.data).to.have.length.above(2)
   })
 
-  it('Should list jobs with sort and pagination', async function () {
-    const res = await getJobsListPaginationAndSort(servers[1].url, servers[1].accessToken, 4, 1, 'createdAt')
-    expect(res.body.total).to.be.above(2)
-    expect(res.body.data).to.have.lengthOf(1)
-
-    const job = res.body.data[0]
-    expect(job.state).to.equal('success')
-    expect(job.category).to.equal('transcoding')
-    expect(job.handlerName).to.have.length.above(3)
-    expect(dateIsValid(job.createdAt)).to.be.true
-    expect(dateIsValid(job.updatedAt)).to.be.true
-  })
+  it('Should list jobs with sort, pagination and job type', async function () {
+    {
+      const res = await getJobsListPaginationAndSort({
+        url: servers[1].url,
+        accessToken: servers[1].accessToken,
+        state: 'completed',
+        start: 1,
+        count: 2,
+        sort: 'createdAt'
+      })
+      expect(res.body.total).to.be.above(2)
+      expect(res.body.data).to.have.lengthOf(2)
 
-  after(async function () {
-    killallServers(servers)
+      let job: Job = res.body.data[0]
+      // Skip repeat jobs
+      if (job.type === 'videos-views') job = res.body.data[1]
+
+      expect(job.state).to.equal('completed')
+      expect(job.type.startsWith('activitypub-')).to.be.true
+      expect(dateIsValid(job.createdAt as string)).to.be.true
+      expect(dateIsValid(job.processedOn as string)).to.be.true
+      expect(dateIsValid(job.finishedOn as string)).to.be.true
+    }
+
+    {
+      const res = await getJobsListPaginationAndSort({
+        url: servers[1].url,
+        accessToken: servers[1].accessToken,
+        state: 'completed',
+        start: 0,
+        count: 100,
+        sort: 'createdAt',
+        jobType: 'activitypub-http-broadcast'
+      })
+      expect(res.body.total).to.be.above(2)
 
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
+      for (const j of res.body.data as Job[]) {
+        expect(j.type).to.equal('activitypub-http-broadcast')
+      }
     }
   })
+
+  after(async function () {
+    await cleanupTests(servers)
+  })
 })