|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import expect from '@kbn/expect'; |
| 8 | +import { FtrProviderContext } from '../../ftr_provider_context'; |
| 9 | + |
| 10 | +const API_BASE_PATH = '/api/painless_lab'; |
| 11 | + |
| 12 | +export default function ({ getService }: FtrProviderContext) { |
| 13 | + const supertest = getService('supertest'); |
| 14 | + |
| 15 | + describe('Painless Lab', function () { |
| 16 | + describe('Execute', () => { |
| 17 | + it('should execute a valid painless script', async () => { |
| 18 | + const script = |
| 19 | + '"{\\n \\"script\\": {\\n \\"source\\": \\"return true;\\",\\n \\"params\\": {\\n \\"string_parameter\\": \\"string value\\",\\n \\"number_parameter\\": 1.5,\\n \\"boolean_parameter\\": true\\n}\\n }\\n}"'; |
| 20 | + |
| 21 | + const { body } = await supertest |
| 22 | + .post(`${API_BASE_PATH}/execute`) |
| 23 | + .set('kbn-xsrf', 'xxx') |
| 24 | + .set('Content-Type', 'application/json;charset=UTF-8') |
| 25 | + .send(script) |
| 26 | + .expect(200); |
| 27 | + |
| 28 | + expect(body).to.eql({ |
| 29 | + result: 'true', |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should return error response for invalid painless script', async () => { |
| 34 | + const invalidScript = |
| 35 | + '"{\\n \\"script\\": {\\n \\"source\\": \\"foobar\\",\\n \\"params\\": {\\n \\"string_parameter\\": \\"string value\\",\\n \\"number_parameter\\": 1.5,\\n \\"boolean_parameter\\": true\\n}\\n }\\n}"'; |
| 36 | + |
| 37 | + const { body } = await supertest |
| 38 | + .post(`${API_BASE_PATH}/execute`) |
| 39 | + .set('kbn-xsrf', 'xxx') |
| 40 | + .set('Content-Type', 'application/json;charset=UTF-8') |
| 41 | + .send(invalidScript) |
| 42 | + .expect(200); |
| 43 | + |
| 44 | + expect(body.error).to.not.be(undefined); |
| 45 | + expect(body.error.reason).to.eql('compile error'); |
| 46 | + }); |
| 47 | + }); |
| 48 | + }); |
| 49 | +} |
0 commit comments