From 60543b19de916f13f30164a0903eccd4f1de07ba Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Tue, 5 Jan 2021 17:34:06 +0300 Subject: [PATCH] fix tests --- .../fields_api/update_fields/main.ts | 135 +++++------------- .../delete_scripted_field/errors.ts | 51 ++++--- .../get_scripted_field/errors.ts | 76 +++++----- 3 files changed, 106 insertions(+), 156 deletions(-) diff --git a/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts b/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts index 861987c30705c..ac12e7ef04a1a 100644 --- a/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts +++ b/test/api_integration/apis/index_patterns/fields_api/update_fields/main.ts @@ -22,8 +22,32 @@ import { FtrProviderContext } from '../../../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { const supertest = getService('supertest'); + const esArchiver = getService('esArchiver'); describe('main', () => { + const basicIndex = 'ba*ic_index'; + let indexPattern: any; + + before(async () => { + await esArchiver.load('index_patterns/basic_index'); + + indexPattern = ( + await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title: basicIndex, + }, + }) + ).body.index_pattern; + }); + + after(async () => { + await esArchiver.unload('index_patterns/basic_index'); + + if (indexPattern) { + await supertest.delete('/api/index_patterns/index_pattern/' + indexPattern.id); + } + }); + it('can update multiple fields', async () => { const title = `foo-${Date.now()}-${Math.random()}*`; const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ @@ -171,48 +195,6 @@ export default function ({ getService }: FtrProviderContext) { expect(response3.status).to.be(200); expect(response3.body.index_pattern.fieldAttrs.foo.count).to.be(undefined); }); - - it('can set field "count" attribute on an existing field', async () => { - const title = `foo-${Date.now()}-${Math.random()}*`; - const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ - index_pattern: { - title, - fields: { - foo: { - name: 'foo', - type: 'string', - count: 123, - }, - }, - }, - }); - - expect(response1.status).to.be(200); - expect(response1.body.index_pattern.fieldAttrs.foo).to.be(undefined); - expect(response1.body.index_pattern.fields.foo.count).to.be(123); - - const response2 = await supertest - .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) - .send({ - fields: { - foo: { - count: 456, - }, - }, - }); - - expect(response2.status).to.be(200); - expect(response2.body.index_pattern.fieldAttrs.foo).to.be(undefined); - expect(response2.body.index_pattern.fields.foo.count).to.be(456); - - const response3 = await supertest.get( - `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` - ); - - expect(response3.status).to.be(200); - expect(response3.body.index_pattern.fieldAttrs.foo).to.be(undefined); - expect(response3.body.index_pattern.fields.foo.count).to.be(456); - }); }); describe('customLabel', () => { @@ -323,46 +305,20 @@ export default function ({ getService }: FtrProviderContext) { }); it('can set field "customLabel" attribute on an existing field', async () => { - const title = `foo-${Date.now()}-${Math.random()}*`; - const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ - index_pattern: { - title, - fields: { - foo: { - name: 'foo', - type: 'string', - count: 123, - customLabel: 'foo', - }, + await supertest.post(`/api/index_patterns/index_pattern/${indexPattern.id}/fields`).send({ + fields: { + foo: { + customLabel: 'baz', }, }, }); - expect(response1.status).to.be(200); - expect(response1.body.index_pattern.fieldAttrs.foo).to.be(undefined); - expect(response1.body.index_pattern.fields.foo.customLabel).to.be('foo'); - - const response2 = await supertest - .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) - .send({ - fields: { - foo: { - customLabel: 'baz', - }, - }, - }); - - expect(response2.status).to.be(200); - expect(response2.body.index_pattern.fieldAttrs.foo).to.be(undefined); - expect(response2.body.index_pattern.fields.foo.customLabel).to.be('baz'); - - const response3 = await supertest.get( - `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + const response1 = await supertest.get( + `/api/index_patterns/index_pattern/${indexPattern.id}` ); - expect(response3.status).to.be(200); - expect(response3.body.index_pattern.fieldAttrs.foo).to.be(undefined); - expect(response3.body.index_pattern.fields.foo.customLabel).to.be('baz'); + expect(response1.status).to.be(200); + expect(response1.body.index_pattern.fields.foo.customLabel).to.be('baz'); }); }); @@ -463,31 +419,8 @@ export default function ({ getService }: FtrProviderContext) { }); it('can remove "format" attribute from index_pattern format map', async () => { - const title = `foo-${Date.now()}-${Math.random()}*`; - const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ - index_pattern: { - title, - fieldFormats: { - foo: { - id: 'bar', - params: { - baz: 'qux', - }, - }, - }, - }, - }); - - expect(response1.status).to.be(200); - expect(response1.body.index_pattern.fieldFormats.foo).to.eql({ - id: 'bar', - params: { - baz: 'qux', - }, - }); - const response2 = await supertest - .post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/fields`) + .post(`/api/index_patterns/index_pattern/${indexPattern.id}/fields`) .send({ fields: { foo: { @@ -500,7 +433,7 @@ export default function ({ getService }: FtrProviderContext) { expect(response2.body.index_pattern.fieldFormats.foo).to.be(undefined); const response3 = await supertest.get( - `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}` + `/api/index_patterns/index_pattern/${indexPattern.id}` ); expect(response3.status).to.be(200); diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts index 2182f47d91c08..7e26541680a39 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/delete_scripted_field/errors.ts @@ -21,9 +21,33 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { + const esArchiver = getService('esArchiver'); const supertest = getService('supertest'); describe('errors', () => { + const basicIndex = 'b*sic_index'; + let indexPattern: any; + + before(async () => { + await esArchiver.load('index_patterns/basic_index'); + + indexPattern = ( + await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title: basicIndex, + }, + }) + ).body.index_pattern; + }); + + after(async () => { + await esArchiver.unload('index_patterns/basic_index'); + + if (indexPattern) { + await supertest.delete('/api/index_patterns/index_pattern/' + indexPattern.id); + } + }); + it('returns 404 error on non-existing index_pattern', async () => { const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; const response = await supertest.delete( @@ -34,35 +58,16 @@ export default function ({ getService }: FtrProviderContext) { }); it('returns 404 error on non-existing scripted field', async () => { - const title = `foo-${Date.now()}-${Math.random()}*`; - const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ - index_pattern: { - title, - }, - }); - const response2 = await supertest.delete( - `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` + const response1 = await supertest.delete( + `/api/index_patterns/index_pattern/${indexPattern.id}/scripted_field/test` ); - expect(response2.status).to.be(404); + expect(response1.status).to.be(404); }); it('returns error when attempting to delete a field which is not a scripted field', async () => { - const title = `foo-${Date.now()}-${Math.random()}*`; - const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ - index_pattern: { - title, - fields: { - foo: { - scripted: false, - name: 'foo', - type: 'string', - }, - }, - }, - }); const response2 = await supertest.delete( - `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` + `/api/index_patterns/index_pattern/${indexPattern.id}/scripted_field/foo` ); expect(response2.status).to.be(400); diff --git a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts index 1f39de8c03a96..71c28507b209d 100644 --- a/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts +++ b/test/api_integration/apis/index_patterns/scripted_fields_crud/get_scripted_field/errors.ts @@ -21,9 +21,33 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { + const esArchiver = getService('esArchiver'); const supertest = getService('supertest'); describe('errors', () => { + const basicIndex = '*asic_index'; + let indexPattern: any; + + before(async () => { + await esArchiver.load('index_patterns/basic_index'); + + indexPattern = ( + await supertest.post('/api/index_patterns/index_pattern').send({ + index_pattern: { + title: basicIndex, + }, + }) + ).body.index_pattern; + }); + + after(async () => { + await esArchiver.unload('index_patterns/basic_index'); + + if (indexPattern) { + await supertest.delete('/api/index_patterns/index_pattern/' + indexPattern.id); + } + }); + it('returns 404 error on non-existing index_pattern', async () => { const id = `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-${Date.now()}`; const response = await supertest.get( @@ -34,40 +58,11 @@ export default function ({ getService }: FtrProviderContext) { }); it('returns 404 error on non-existing scripted field', async () => { - const title = `foo-${Date.now()}-${Math.random()}*`; - const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ - index_pattern: { - title, - }, - }); - const response2 = await supertest.get( - `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` - ); - - expect(response2.status).to.be(404); - }); - - it('returns error when attempting to fetch a field which is not a scripted field', async () => { - const title = `foo-${Date.now()}-${Math.random()}*`; - const response1 = await supertest.post('/api/index_patterns/index_pattern').send({ - index_pattern: { - title, - fields: { - foo: { - scripted: false, - name: 'foo', - type: 'string', - }, - }, - }, - }); - const response2 = await supertest.get( - `/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/foo` + const response1 = await supertest.get( + `/api/index_patterns/index_pattern/${indexPattern.id}/scripted_field/sf` ); - expect(response2.status).to.be(400); - expect(response2.body.statusCode).to.be(400); - expect(response2.body.message).to.be('Only scripted fields can be retrieved.'); + expect(response1.status).to.be(404); }); it('returns error when ID is too long', async () => { @@ -81,5 +76,22 @@ export default function ({ getService }: FtrProviderContext) { '[request params.id]: value has length [1759] but it must have a maximum length of [1000].' ); }); + + it('returns 404 error on non-existing scripted field', async () => { + const response1 = await supertest.get( + `/api/index_patterns/index_pattern/${indexPattern.id}/scripted_field/test` + ); + expect(response1.status).to.be(404); + }); + + it('returns error when attempting to fetch a field which is not a scripted field', async () => { + const response2 = await supertest.get( + `/api/index_patterns/index_pattern/${indexPattern.id}/scripted_field/foo` + ); + + expect(response2.status).to.be(400); + expect(response2.body.statusCode).to.be(400); + expect(response2.body.message).to.be('Only scripted fields can be retrieved.'); + }); }); }