Skip to content

Commit

Permalink
fix api integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Feb 21, 2022
1 parent 69a5cc6 commit 6002821
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function ({ getService }: FtrProviderContext) {
};

// wait for the the pending job to complete
await reportingAPI.waitForJobToFinish(downloadPath);
await reportingAPI.waitForJobToFinish(downloadPath, true);

expect(await reportingAPI.getJobErrorCode(report.id)).to.be('unknown_error');

Expand Down
14 changes: 12 additions & 2 deletions x-pack/test/reporting_api_integration/services/scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ export function createScenarios({ getService }: Pick<FtrProviderContext, 'getSer
password = process.env.TEST_KIBANA_PASS || 'changeme'
) => {
const jobParams = rison.encode(job as object as RisonValue);

return await supertestWithoutAuth
.post(`/api/reporting/generate/csv_searchsource`)
.auth(username, password)
Expand Down Expand Up @@ -191,10 +192,19 @@ export function createScenarios({ getService }: Pick<FtrProviderContext, 'getSer
return response.text as unknown;
};

const getJobErrorCode = async (id: string): Promise<undefined | string> => {
const getJobErrorCode = async (
id: string,
username = 'elastic',
password = process.env.TEST_KIBANA_PASS || 'changeme'
): Promise<undefined | string> => {
const {
body: [job],
} = await supertest.get(`/api/reporting/jobs/?page=0&ids=${id}`);
} = await supertestWithoutAuth
.get(`/api/reporting/jobs/list?page=0&ids=${id}`)
.auth(username, password)
.set('kbn-xsrf', 'xxx')
.send()
.expect(200);
return job?.output?.error_code;
};

Expand Down
7 changes: 4 additions & 3 deletions x-pack/test/reporting_api_integration/services/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createUsageServices({ getService }: FtrProviderContext) {
const supertest = getService('supertest');

return {
async waitForJobToFinish(downloadReportPath: string) {
async waitForJobToFinish(downloadReportPath: string, ignoreFailure?: boolean) {
log.debug(`Waiting for job to finish: ${downloadReportPath}`);
const JOB_IS_PENDING_CODE = 503;

Expand All @@ -65,8 +65,9 @@ export function createUsageServices({ getService }: FtrProviderContext) {
}
}, 1500);
});

expect(statusCode).to.be(200);
if (!ignoreFailure) {
expect(statusCode).to.be(200);
}
},

/**
Expand Down

0 comments on commit 6002821

Please sign in to comment.