Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Jan 5, 2021
1 parent 086f421 commit 60543b1
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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');
});
});

Expand Down Expand Up @@ -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: {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 () => {
Expand All @@ -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.');
});
});
}

0 comments on commit 60543b1

Please sign in to comment.