1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
5 import { cleanupTests, ServerInfo, setAccessTokensToServers } from '../../../../shared/extra-utils/index'
6 import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
7 import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/extra-utils/server/jobs'
8 import { flushAndRunMultipleServers } from '../../../../shared/extra-utils/server/servers'
9 import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
10 import { dateIsValid } from '../../../../shared/extra-utils/miscs/miscs'
11 import { Job } from '../../../../shared/models/server'
13 const expect = chai.expect
15 describe('Test jobs', function () {
16 let servers: ServerInfo[]
18 before(async function () {
21 servers = await flushAndRunMultipleServers(2)
23 await setAccessTokensToServers(servers)
25 // Server 1 and server 2 follow each other
26 await doubleFollow(servers[0], servers[1])
29 it('Should create some jobs', async function () {
32 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video1' })
33 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
35 await waitJobs(servers)
38 it('Should list jobs', async function () {
39 const res = await getJobsList(servers[1].url, servers[1].accessToken, 'completed')
40 expect(res.body.total).to.be.above(2)
41 expect(res.body.data).to.have.length.above(2)
44 it('Should list jobs with sort, pagination and job type', async function () {
46 const res = await getJobsListPaginationAndSort({
48 accessToken: servers[1].accessToken,
54 expect(res.body.total).to.be.above(2)
55 expect(res.body.data).to.have.lengthOf(2)
57 let job: Job = res.body.data[0]
59 if (job.type === 'videos-views') job = res.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 res = await getJobsListPaginationAndSort({
71 accessToken: servers[1].accessToken,
76 jobType: 'activitypub-http-broadcast'
78 expect(res.body.total).to.be.above(2)
80 for (const j of res.body.data as Job[]) {
81 expect(j.type).to.equal('activitypub-http-broadcast')
86 after(async function () {
87 await cleanupTests(servers)