X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Fjobs.ts;h=d0e222997645dad4cfce802fad172fd38144d6a1;hb=1c5e49e75284100b7b1fc8b4e73c8ba53fe22e89;hp=52948b1d64164dfef47f84c2e5204bc35276724f;hpb=2a8c5d0af13f3ccb9a505e1fbc9d324b9d33ba1f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 52948b1d6..d0e222997 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -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 { killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index' -import { doubleFollow } from '../../../../shared/utils/server/follows' -import { getJobsList, getJobsListPaginationAndSort, waitJobs } from '../../../../shared/utils/server/jobs' -import { flushAndRunMultipleServers } from '../../../../shared/utils/server/servers' -import { uploadVideo } from '../../../../shared/utils/videos/videos' -import { dateIsValid } from '../../../../shared/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,7 +27,7 @@ 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' }) @@ -40,23 +41,62 @@ describe('Test jobs', function () { 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, 'completed', 1, 2, 'createdAt') - expect(res.body.total).to.be.above(2) - expect(res.body.data).to.have.lengthOf(2) + 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) + + 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) - let job = res.body.data[0] - // Skip repeat jobs - if (job.type === 'videos-views') job = res.body.data[1] + for (const j of res.body.data as Job[]) { + expect(j.type).to.equal('activitypub-http-broadcast') + } + } + }) + + it('Should list all jobs', async function () { + const res = await getJobsList(servers[1].url, servers[1].accessToken) + + const jobs = res.body.data as Job[] + + expect(res.body.total).to.be.above(2) + expect(jobs).to.have.length.above(2) - expect(job.state).to.equal('completed') - expect(job.type).to.equal('activitypub-follow') - expect(dateIsValid(job.createdAt)).to.be.true - expect(dateIsValid(job.processedOn)).to.be.true - expect(dateIsValid(job.finishedOn)).to.be.true + // We know there are a least 1 delayed job (video views) and 1 completed job (broadcast) + expect(jobs.find(j => j.state === 'delayed')).to.not.be.undefined + expect(jobs.find(j => j.state === 'completed')).to.not.be.undefined }) after(async function () { - killallServers(servers) + await cleanupTests(servers) }) })