From 4fd0f8ce582e75ac8c5de8c29044cef93ec5c491 Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Thu, 15 Jul 2021 03:53:19 -0400 Subject: [PATCH] [ML] Add api integration test for analytics map endpoint (#105531) (#105685) * adds api integration test for analytics map endpoint in spaces * wrap request code in function * check error value and add messaging Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../ml/data_frame_analytics/get_spaces.ts | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/x-pack/test/api_integration/apis/ml/data_frame_analytics/get_spaces.ts b/x-pack/test/api_integration/apis/ml/data_frame_analytics/get_spaces.ts index 33dcec626450..b65094388319 100644 --- a/x-pack/test/api_integration/apis/ml/data_frame_analytics/get_spaces.ts +++ b/x-pack/test/api_integration/apis/ml/data_frame_analytics/get_spaces.ts @@ -45,6 +45,19 @@ export default ({ getService }: FtrProviderContext) => { return body; } + async function runMapRequest(space: string, expectedStatusCode: number, jobId: string) { + const { body } = await supertest + .get(`/s/${space}/api/ml/data_frame/analytics/map/${jobId}`) + .auth( + USER.ML_VIEWER_ALL_SPACES, + ml.securityCommon.getPasswordForUser(USER.ML_VIEWER_ALL_SPACES) + ) + .set(COMMON_REQUEST_HEADERS) + .expect(expectedStatusCode); + + return body; + } + describe('GET data_frame/analytics with spaces', function () { before(async () => { await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/ihp_outlier'); @@ -140,5 +153,62 @@ export default ({ getService }: FtrProviderContext) => { it('should fail to list jobs stats by job ids if one of them is in a different space', async () => { await runRequest(idSpace1, 404, true, `${jobIdSpace1},${jobIdSpace2}`); }); + + describe('GetDataFrameAnalyticsIdMap with spaces', () => { + it(`should return a map of objects from ${idSpace1} leading up to analytics job id created in ${idSpace1}`, async () => { + const body = await runMapRequest(idSpace1, 200, jobIdSpace1); + + expect(body).to.have.keys('elements', 'details', 'error'); + // Index node, 2 job nodes (with same source index), and 2 edge nodes to connect them + expect(body.elements.length).to.eql( + 5, + `Expected 5 map elements, got ${body.elements.length}` + ); + expect(body.error).to.be(null); + // No space2 related job ids should be returned + for (const detailsId in body.details) { + if (detailsId.includes('analytics')) { + expect(body.details[detailsId].id.includes(idSpace2)).to.eql( + false, + `No space2 related job ids should be returned, got ${body.details[detailsId].id}` + ); + } + } + }); + + it(`should return a map of objects from ${idSpace2} leading up to analytics job id created in ${idSpace2}`, async () => { + const body = await runMapRequest(idSpace2, 200, jobIdSpace2); + + expect(body).to.have.keys('elements', 'details', 'error'); + // Index node, 1 job node and 2 edge nodes to connect them + expect(body.elements.length).to.eql( + 3, + `Expected 3 map elements, got ${body.elements.length}` + ); + expect(body.error).to.be(null); + // No space1 related job ids should be returned + for (const detailsId in body.details) { + if (detailsId.includes('analytics')) { + expect(body.details[detailsId].id.includes(idSpace1)).to.eql( + false, + `No space1 related job ids should be returned, got ${body.details[detailsId].id}` + ); + } + } + }); + + it(`should fail to return a map of objects from one space when requesting with analytics job id created in a different space`, async () => { + const body = await runMapRequest(idSpace2, 200, jobIdSpace1); + + expect(body).to.have.keys('elements', 'details', 'error'); + + expect(body.elements.length).to.eql( + 0, + `Expected 0 map elements, got ${body.elements.length}` + ); + expect(body.details).to.eql({}); + expect(body.error).to.eql(`No known job with id '${jobIdSpace1}'`); + }); + }); }); };