From 4b3295c5e5b70d83a469281881bbdc7e52211730 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Thu, 23 Apr 2020 19:32:08 -0700 Subject: [PATCH] Revert "Fix API integration tests by removing tests for deleted rollup search endpoint." This reverts commit 9e190e6b70f9cb3bf91247a2acc751f5a60b1c26. --- .../apis/management/rollup/index.js | 1 + .../apis/management/rollup/rollup_search.js | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 x-pack/test/api_integration/apis/management/rollup/rollup_search.js diff --git a/x-pack/test/api_integration/apis/management/rollup/index.js b/x-pack/test/api_integration/apis/management/rollup/index.js index f04abf0050ec1..b55622381bc3c 100644 --- a/x-pack/test/api_integration/apis/management/rollup/index.js +++ b/x-pack/test/api_integration/apis/management/rollup/index.js @@ -8,5 +8,6 @@ export default function({ loadTestFile }) { describe('rollup', () => { loadTestFile(require.resolve('./rollup')); loadTestFile(require.resolve('./index_patterns_extensions')); + loadTestFile(require.resolve('./rollup_search')); }); } diff --git a/x-pack/test/api_integration/apis/management/rollup/rollup_search.js b/x-pack/test/api_integration/apis/management/rollup/rollup_search.js new file mode 100644 index 0000000000000..4fd7b304dd78b --- /dev/null +++ b/x-pack/test/api_integration/apis/management/rollup/rollup_search.js @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from '@kbn/expect'; + +import { registerHelpers } from './rollup.test_helpers'; +import { API_BASE_PATH } from './constants'; +import { getRandomString } from './lib'; + +export default function({ getService }) { + const supertest = getService('supertest'); + const es = getService('legacyEs'); + + const { createIndexWithMappings, getJobPayload, createJob, cleanUp } = registerHelpers({ + supertest, + es, + }); + + describe('search', () => { + const URI = `${API_BASE_PATH}/search`; + + it('return a 404 if the rollup index does not exist', async () => { + const { body } = await supertest + .post(URI) + .set('kbn-xsrf', 'xxx') + .send([{ index: 'unknown', query: {} }]) + .expect(404); + + expect(body.message).to.contain('no such index [unknown]'); + }); + + it('should return a 200 when searching on existing rollup index', async () => { + // Create a Rollup job on an index with the INDEX_TO_ROLLUP_MAPPINGS + const indexName = await createIndexWithMappings(); + const rollupIndex = getRandomString(); + await createJob(getJobPayload(indexName, undefined, rollupIndex)); + + const { body } = await supertest + .post(URI) + .set('kbn-xsrf', 'xxx') + .send([{ index: rollupIndex, query: { size: 0 } }]) + .expect(200); + + // make sure total hits is an integer and not an object + expect(body[0].hits.total).to.equal(0); + + await cleanUp(); + }); + }); +}