kibana/x-pack/test/reporting_api_integration/reporting_without_security/job_apis_csv_deprecated.ts
Tim Sullivan 488f112f47
[Reporting/Tests] Consolidate test archives, move kbn objects to kbn_archiver (#116528)
* remove unused

* remove kibana objects from reporting es_archives

* import objects using kibanaServer for tests

* consolidate ecommerce_kibana_spaces

* self-review

* fix nanos test

* fix loading of reporting/ecommerce_kibana_spaces

* fix csv snapshots

* fix more csv tests

* archive rename

* consolidate canvas_disallowed_url archive

* clean up snapshots

* fix CSV tests

* polish

* remove unused

* Update x-pack/test/reporting_api_integration/reporting_and_security/network_policy.ts
2021-11-03 01:27:52 +00:00

190 lines
6 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import expect from '@kbn/expect';
import { pick } from 'lodash';
import { ReportApiJSON } from '../../../plugins/reporting/common/types';
import { FtrProviderContext } from '../ftr_provider_context';
import { JOB_PARAMS_RISON_CSV_DEPRECATED } from '../services/fixtures';
const apiResponseFields = [
'attempts',
'created_by',
'jobtype',
'meta',
'payload.isDeprecated',
'payload.title',
'payload.type',
'status',
];
const parseApiJSON = (apiResponseText: string): { job: ReportApiJSON; path: string } =>
JSON.parse(apiResponseText);
// eslint-disable-next-line import/no-default-export
export default function ({ getService }: FtrProviderContext) {
const supertestNoAuth = getService('supertestWithoutAuth');
const reportingAPI = getService('reportingAPI');
describe('Job Listing APIs: Deprecated CSV Export', () => {
before(async () => {
await reportingAPI.initLogs();
});
after(async () => {
await reportingAPI.teardownLogs();
});
afterEach(async () => {
await reportingAPI.deleteAllReports();
});
it('Posted CSV job is visible in the job count', async () => {
const { status: resStatus, text: resText } = await supertestNoAuth
.post(`/api/reporting/generate/csv`)
.set('kbn-xsrf', 'xxx')
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
expect(resStatus).to.be(200);
const { job, path } = parseApiJSON(resText);
expectSnapshot(pick(job, apiResponseFields)).toMatchInline(`
Object {
"attempts": 0,
"created_by": false,
"jobtype": "csv",
"meta": Object {
"isDeprecated": true,
},
"payload": Object {
"isDeprecated": true,
"title": "A Saved Search With a DATE FILTER",
"type": "search",
},
"status": "pending",
}
`);
// call the job count api
const { text: countText } = await supertestNoAuth
.get(`/api/reporting/jobs/count`)
.set('kbn-xsrf', 'xxx');
const countResult = JSON.parse(countText);
expect(countResult).to.be(1);
await reportingAPI.waitForJobToFinish(path);
});
it('Posted CSV job is visible in the status check', async () => {
const { status: resStatus, text: resText } = await supertestNoAuth
.post(`/api/reporting/generate/csv`)
.set('kbn-xsrf', 'xxx')
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
expect(resStatus).to.be(200);
const { job, path } = parseApiJSON(resText);
// call the single job listing api (status check)
const { text: listText } = await supertestNoAuth
.get(`/api/reporting/jobs/list?page=0&ids=${job.id}`)
.set('kbn-xsrf', 'xxx');
const listingJobs: ReportApiJSON[] = JSON.parse(listText);
expect(listingJobs[0].id).to.be(job.id);
expectSnapshot(listingJobs.map((j) => pick(j, apiResponseFields))).toMatchInline(`
Array [
Object {
"attempts": 0,
"created_by": false,
"jobtype": "csv",
"meta": Object {
"isDeprecated": true,
},
"payload": Object {
"isDeprecated": true,
"title": "A Saved Search With a DATE FILTER",
"type": "search",
},
"status": "pending",
},
]
`);
await reportingAPI.waitForJobToFinish(path);
});
it('Posted CSV job is visible in the first page of jobs listing', async () => {
const { status: resStatus, text: resText } = await supertestNoAuth
.post(`/api/reporting/generate/csv`)
.set('kbn-xsrf', 'xxx')
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
expect(resStatus).to.be(200);
const { job, path } = parseApiJSON(resText);
// call the ALL job listing api
const { text: listText } = await supertestNoAuth
.get(`/api/reporting/jobs/list?page=0`)
.set('kbn-xsrf', 'xxx');
const listingJobs: ReportApiJSON[] = JSON.parse(listText);
expect(listingJobs[0].id).to.eql(job.id);
expectSnapshot(listingJobs.map((j) => pick(j, apiResponseFields))).toMatchInline(`
Array [
Object {
"attempts": 0,
"created_by": false,
"jobtype": "csv",
"meta": Object {
"isDeprecated": true,
},
"payload": Object {
"isDeprecated": true,
"title": "A Saved Search With a DATE FILTER",
"type": "search",
},
"status": "pending",
},
]
`);
await reportingAPI.waitForJobToFinish(path);
});
it('Posted CSV job details are visible in the info API', async () => {
const { status: resStatus, text: resText } = await supertestNoAuth
.post(`/api/reporting/generate/csv`)
.set('kbn-xsrf', 'xxx')
.send({ jobParams: JOB_PARAMS_RISON_CSV_DEPRECATED });
expect(resStatus).to.be(200);
const { job, path } = parseApiJSON(resText);
const { text: infoText } = await supertestNoAuth
.get(`/api/reporting/jobs/info/${job.id}`)
.set('kbn-xsrf', 'xxx');
const info = JSON.parse(infoText);
expectSnapshot(pick(info, apiResponseFields)).toMatchInline(`
Object {
"attempts": 0,
"created_by": false,
"jobtype": "csv",
"meta": Object {
"isDeprecated": true,
},
"payload": Object {
"isDeprecated": true,
"title": "A Saved Search With a DATE FILTER",
"type": "search",
},
"status": "pending",
}
`);
await reportingAPI.waitForJobToFinish(path);
});
});
}