Skip to content

Commit

Permalink
added jest tests for common cases on the info route
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Oct 28, 2021
1 parent c1763e5 commit 8bfd291
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions x-pack/plugins/reporting/server/routes/management/jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,36 @@ describe('GET /api/reporting/jobs/download', () => {
await supertest(httpSetup.server.listener).get('/api/reporting/jobs/download/poo').expect(401);
});

it(`returns job's info`, async () => {
mockEsClient.search.mockResolvedValueOnce({
body: getHits({
jobtype: 'base64EncodedJobType',
payload: {}, // payload is irrelevant
}),
} as any);

registerJobInfoRoutes(core);

await server.start();

await supertest(httpSetup.server.listener).get('/api/reporting/jobs/info/test').expect(200);
});

it(`returns 403 if a user cannot view a job's info`, async () => {
mockEsClient.search.mockResolvedValueOnce({
body: getHits({
jobtype: 'customForbiddenJobType',
payload: {}, // payload is irrelevant
}),
} as any);

registerJobInfoRoutes(core);

await server.start();

await supertest(httpSetup.server.listener).get('/api/reporting/jobs/info/test').expect(403);
});

it('when a job is incomplete', async () => {
mockEsClient.search.mockResolvedValueOnce({
body: getHits({
Expand Down

0 comments on commit 8bfd291

Please sign in to comment.