Skip to content

Commit

Permalink
Add Api integration tests for the ES error parser
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga committed Nov 26, 2020
1 parent fcb1e0e commit ed4e84d
Showing 1 changed file with 46 additions and 0 deletions.
Expand Up @@ -191,6 +191,26 @@ export default function ({ getService }) {
'[request body.indexPatterns]: expected value of type [array] '
);
});

it('should parse the ES error and return the cause', async () => {
const templateName = `template-${getRandomString()}`;
const payload = getTemplatePayload(templateName, [getRandomString()]);
const runtime = {
myRuntimeField: {
type: 'boolean',
script: {
source: 'emit("hello with error', // error in script
},
},
};
payload.template.mappings = { ...payload.template.mappings, runtime };
const { body } = await createTemplate(payload).expect(400);

expect(body.attributes).an('object');
expect(body.attributes.message).contain('template after composition is invalid');
// one of the item of the cause array should point to our script
expect(body.attributes.cause.join(',')).contain('"hello with error');
});
});

describe('update', () => {
Expand Down Expand Up @@ -248,6 +268,32 @@ export default function ({ getService }) {
catTemplateResponse.find(({ name: templateName }) => templateName === name).version
).to.equal(updatedVersion.toString());
});

it('should parse the ES error and return the cause', async () => {
const templateName = `template-${getRandomString()}`;
const payload = getTemplatePayload(templateName, [getRandomString()]);
const runtime = {
myRuntimeField: {
type: 'keyword',
script: {
source: 'emit("hello")',
},
},
};

// Add runtime field
payload.template.mappings = { ...payload.template.mappings, runtime };

await createTemplate(payload).expect(200);

// Update template with an error in the runtime field script
payload.template.mappings.runtime.myRuntimeField.script = 'emit("hello with error';
const { body } = await updateTemplate(payload, templateName).expect(400);

expect(body.attributes).an('object');
// one of the item of the cause array should point to our script
expect(body.attributes.cause.join(',')).contain('"hello with error');
});
});

describe('delete', () => {
Expand Down

0 comments on commit ed4e84d

Please sign in to comment.