Skip to content

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Jun 1, 2021
1 parent f150fad commit 22a7e49
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { FtrProviderContext } from '../../../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');

describe('main', () => {
it('can create an index_pattern with just a title', async () => {
Expand Down Expand Up @@ -75,60 +76,80 @@ export default function ({ getService }: FtrProviderContext) {
expect(response.body.index_pattern.sourceFilters[0].value).to.be('foo');
});

it.skip('can specify optional fields attribute when creating an index pattern', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response = await supertest.post('/api/index_patterns/index_pattern').send({
index_pattern: {
title,
fields: {
foo: {
name: 'foo',
type: 'string',
},
},
},
describe('creating fields', () => {
before(async () => {
await esArchiver.load('index_patterns/basic_index');
});

expect(response.status).to.be(200);
expect(response.body.index_pattern.title).to.be(title);
expect(response.body.index_pattern.fields.foo.name).to.be('foo');
expect(response.body.index_pattern.fields.foo.type).to.be('string');
});
after(async () => {
await esArchiver.unload('index_patterns/basic_index');
});

it.skip('can add two fields, one with all fields specified', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response = await supertest.post('/api/index_patterns/index_pattern').send({
index_pattern: {
title,
fields: {
foo: {
name: 'foo',
type: 'string',
},
bar: {
name: 'bar',
type: 'number',
count: 123,
script: '',
esTypes: ['test-type'],
scripted: true,
it('can specify optional fields attribute when creating an index pattern', async () => {
const title = `basic_index*`;
const response = await supertest.post('/api/index_patterns/index_pattern').send({
override: true,
index_pattern: {
title,
fields: {
foo: {
name: 'foo',
type: 'string',
scripted: true,
script: "doc['field_name'].value",
},
},
},
},
});

expect(response.status).to.be(200);
expect(response.body.index_pattern.title).to.be(title);
expect(response.body.index_pattern.fields.foo.name).to.be('foo');
expect(response.body.index_pattern.fields.foo.type).to.be('string');
});

expect(response.status).to.be(200);
expect(response.body.index_pattern.title).to.be(title);
it('Can add scripted fields, other fields created from es index', async () => {
const title = `basic_index*`;
const response = await supertest.post('/api/index_patterns/index_pattern').send({
override: true,
index_pattern: {
title,
fields: {
foo: {
name: 'foo',
type: 'string',
},
fake: {
name: 'fake',
type: 'string',
},
bar: {
name: 'bar',
type: 'number',
count: 123,
script: '',
esTypes: ['test-type'],
scripted: true,
},
},
},
});

expect(response.status).to.be(200);
expect(response.body.index_pattern.title).to.be(title);

expect(response.body.index_pattern.fields.foo.name).to.be('foo');
expect(response.body.index_pattern.fields.foo.type).to.be('string');
expect(response.body.index_pattern.fields.foo.name).to.be('foo');
expect(response.body.index_pattern.fields.foo.type).to.be('number'); // picked up from index

expect(response.body.index_pattern.fields.bar.name).to.be('bar');
expect(response.body.index_pattern.fields.bar.type).to.be('number');
expect(response.body.index_pattern.fields.bar.count).to.be(123);
expect(response.body.index_pattern.fields.bar.script).to.be('');
expect(response.body.index_pattern.fields.bar.esTypes[0]).to.be('test-type');
expect(response.body.index_pattern.fields.bar.scripted).to.be(true);
expect(response.body.index_pattern.fields.fake).to.be(undefined); // not in index, so not created

expect(response.body.index_pattern.fields.bar.name).to.be('bar');
expect(response.body.index_pattern.fields.bar.type).to.be('number');
expect(response.body.index_pattern.fields.bar.count).to.be(123);
expect(response.body.index_pattern.fields.bar.script).to.be('');
expect(response.body.index_pattern.fields.bar.esTypes[0]).to.be('test-type');
expect(response.body.index_pattern.fields.bar.scripted).to.be(true);
});
});

it('can specify optional typeMeta attribute when creating an index pattern', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function ({ getService }: FtrProviderContext) {
it('can create a new scripted field', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
override: true,
index_pattern: {
title,
},
Expand Down

0 comments on commit 22a7e49

Please sign in to comment.