1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
13 } from '@shared/extra-utils'
15 const expect = chai.expect
17 describe('Test jobs', function () {
18 let servers: PeerTubeServer[]
20 before(async function () {
23 servers = await createMultipleServers(2)
25 await setAccessTokensToServers(servers)
27 // Server 1 and server 2 follow each other
28 await doubleFollow(servers[0], servers[1])
31 it('Should create some jobs', async function () {
34 await servers[1].videos.upload({ attributes: { name: 'video1' } })
35 await servers[1].videos.upload({ attributes: { name: 'video2' } })
37 await waitJobs(servers)
40 it('Should list jobs', async function () {
41 const body = await servers[1].jobs.getJobsList({ state: 'completed' })
42 expect(body.total).to.be.above(2)
43 expect(body.data).to.have.length.above(2)
46 it('Should list jobs with sort, pagination and job type', async function () {
48 const body = await servers[1].jobs.getJobsList({
54 expect(body.total).to.be.above(2)
55 expect(body.data).to.have.lengthOf(2)
57 let job = body.data[0]
59 if (job.type === 'videos-views') job = body.data[1]
61 expect(job.state).to.equal('completed')
62 expect(job.type.startsWith('activitypub-')).to.be.true
63 expect(dateIsValid(job.createdAt as string)).to.be.true
64 expect(dateIsValid(job.processedOn as string)).to.be.true
65 expect(dateIsValid(job.finishedOn as string)).to.be.true
69 const body = await servers[1].jobs.getJobsList({
74 jobType: 'activitypub-http-broadcast'
76 expect(body.total).to.be.above(2)
78 for (const j of body.data) {
79 expect(j.type).to.equal('activitypub-http-broadcast')
84 it('Should list all jobs', async function () {
85 const body = await servers[1].jobs.getJobsList()
86 expect(body.total).to.be.above(2)
88 const jobs = body.data
89 expect(jobs).to.have.length.above(2)
91 // We know there are a least 1 delayed job (video views) and 1 completed job (broadcast)
92 expect(jobs.find(j => j.state === 'delayed')).to.not.be.undefined
93 expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined
96 after(async function () {
97 await cleanupTests(servers)