From 1061c73fde3005100ead8764eacb444f240440d6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 4 Dec 2019 14:49:59 +0100 Subject: Add ability to filter per job type --- server/tests/api/check-params/jobs.ts | 12 ++++++++ server/tests/api/server/handle-down.ts | 9 +++++- server/tests/api/server/jobs.ts | 50 ++++++++++++++++++++++++++-------- 3 files changed, 58 insertions(+), 13 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index c70139514..22e237964 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -51,6 +51,17 @@ describe('Test jobs API validators', function () { }) }) + it('Should fail with an incorrect job type', async function () { + await makeGetRequest({ + url: server.url, + token: server.accessToken, + path, + query: { + jobType: 'toto' + } + }) + }) + it('Should fail with a bad start pagination', async function () { await checkBadStartPagination(server.url, path, server.accessToken) }) @@ -79,6 +90,7 @@ describe('Test jobs API validators', function () { statusCodeExpected: 403 }) }) + }) after(async function () { diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index a0f505474..7e36067f1 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -184,7 +184,14 @@ describe('Test handle downs', function () { const states: JobState[] = [ 'waiting', 'active' ] for (const state of states) { - const res = await getJobsListPaginationAndSort(servers[ 0 ].url, servers[ 0 ].accessToken, state,0, 50, '-createdAt') + const res = await getJobsListPaginationAndSort({ + url: servers[ 0 ].url, + accessToken: servers[ 0 ].accessToken, + state: state, + start: 0, + count: 50, + sort: '-createdAt' + }) expect(res.body.data).to.have.length(0) } }) diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index ceea47a85..58d8c8c10 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -41,20 +41,46 @@ 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 + } - let job = res.body.data[0] - // Skip repeat jobs - if (job.type === 'videos-views') job = res.body.data[1] + { + 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) - expect(job.state).to.equal('completed') - expect(job.type.startsWith('activitypub-')).to.be.true - expect(dateIsValid(job.createdAt)).to.be.true - expect(dateIsValid(job.processedOn)).to.be.true - expect(dateIsValid(job.finishedOn)).to.be.true + for (const j of res.body.data as Job[]) { + expect(j.type).to.equal('activitypub-http-broadcast') + } + } }) after(async function () { -- cgit v1.2.3