From 44cdf201586cf1b8163f0d0799cbf64dddbb06c0 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Thu, 7 Oct 2021 14:51:23 +0300 Subject: [PATCH] Improve integration tests --- .../builtin_action_types/servicenow.ts | 748 +++++++++--------- 1 file changed, 377 insertions(+), 371 deletions(-) diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts index 16a6db3a1b5d2..852c42f5eb876 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts @@ -19,7 +19,7 @@ export default function serviceNowTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const configService = getService('config'); - describe.skip('ServiceNow', () => { + describe('ServiceNow', () => { let serviceNowSimulatorURL: string = ''; let serviceNowServer: http.Server; let proxyServer: httpProxy | undefined; @@ -52,133 +52,135 @@ export default function serviceNowTest({ getService }: FtrProviderContext) { connectorWithParams: Record, connectorType: string ) => { - it('should return 200 when creating a servicenow action successfully', async () => { - const { body: createdAction } = await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'foo') - .send({ + describe(`ServiceNow: Create connector: Connector Type: ${connectorType}`, () => { + it('should return 200 when creating a servicenow action successfully', async () => { + const { body: createdAction } = await supertest + .post('/api/actions/connector') + .set('kbn-xsrf', 'foo') + .send({ + name: `A connector with type ${connectorType}`, + connector_type_id: connectorType, + config: { + apiUrl: serviceNowSimulatorURL, + }, + secrets: connectorWithParams.secrets, + }) + .expect(200); + + expect(createdAction).to.eql({ + id: createdAction.id, + is_preconfigured: false, name: `A connector with type ${connectorType}`, connector_type_id: connectorType, + is_missing_secrets: false, config: { apiUrl: serviceNowSimulatorURL, + isLegacy: false, }, - secrets: connectorWithParams.secrets, - }) - .expect(200); - - expect(createdAction).to.eql({ - id: createdAction.id, - is_preconfigured: false, - name: `A connector with type ${connectorType}`, - connector_type_id: connectorType, - is_missing_secrets: false, - config: { - apiUrl: serviceNowSimulatorURL, - isLegacy: false, - }, - }); + }); - const { body: fetchedAction } = await supertest - .get(`/api/actions/connector/${createdAction.id}`) - .expect(200); - - expect(fetchedAction).to.eql({ - id: fetchedAction.id, - is_preconfigured: false, - name: `A connector with type ${connectorType}`, - connector_type_id: connectorType, - is_missing_secrets: false, - config: { - apiUrl: serviceNowSimulatorURL, - isLegacy: false, - }, - }); - }); + const { body: fetchedAction } = await supertest + .get(`/api/actions/connector/${createdAction.id}`) + .expect(200); - it('should set the isLegacy to false when not provided', async () => { - const { body: createdAction } = await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'foo') - .send({ + expect(fetchedAction).to.eql({ + id: fetchedAction.id, + is_preconfigured: false, name: `A connector with type ${connectorType}`, connector_type_id: connectorType, + is_missing_secrets: false, config: { apiUrl: serviceNowSimulatorURL, + isLegacy: false, }, - secrets: connectorWithParams.secrets, - }) - .expect(200); + }); + }); + + it('should set the isLegacy to false when not provided', async () => { + const { body: createdAction } = await supertest + .post('/api/actions/connector') + .set('kbn-xsrf', 'foo') + .send({ + name: `A connector with type ${connectorType}`, + connector_type_id: connectorType, + config: { + apiUrl: serviceNowSimulatorURL, + }, + secrets: connectorWithParams.secrets, + }) + .expect(200); - const { body: fetchedAction } = await supertest - .get(`/api/actions/connector/${createdAction.id}`) - .expect(200); + const { body: fetchedAction } = await supertest + .get(`/api/actions/connector/${createdAction.id}`) + .expect(200); - expect(fetchedAction.config.isLegacy).to.be(false); - }); + expect(fetchedAction.config.isLegacy).to.be(false); + }); - it('should respond with a 400 Bad Request when creating a servicenow action with no apiUrl', async () => { - await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'foo') - .send({ - name: `A connector with type ${connectorType}`, - connector_type_id: connectorType, - config: {}, - }) - .expect(400) - .then((resp: any) => { - expect(resp.body).to.eql({ - statusCode: 400, - error: 'Bad Request', - message: - 'error validating action type config: [apiUrl]: expected value of type [string] but got [undefined]', + it('should respond with a 400 Bad Request when creating a servicenow action with no apiUrl', async () => { + await supertest + .post('/api/actions/connector') + .set('kbn-xsrf', 'foo') + .send({ + name: `A connector with type ${connectorType}`, + connector_type_id: connectorType, + config: {}, + }) + .expect(400) + .then((resp: any) => { + expect(resp.body).to.eql({ + statusCode: 400, + error: 'Bad Request', + message: + 'error validating action type config: [apiUrl]: expected value of type [string] but got [undefined]', + }); }); - }); - }); + }); - it('should respond with a 400 Bad Request when creating a servicenow action with a not present in allowedHosts apiUrl', async () => { - await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'foo') - .send({ - name: `A connector with type ${connectorType}`, - connector_type_id: connectorType, - config: { - apiUrl: 'http://servicenow.mynonexistent.com', - }, - secrets: connectorWithParams.secrets, - }) - .expect(400) - .then((resp: any) => { - expect(resp.body).to.eql({ - statusCode: 400, - error: 'Bad Request', - message: - 'error validating action type config: error configuring connector action: target url "http://servicenow.mynonexistent.com" is not added to the Kibana config xpack.actions.allowedHosts', + it('should respond with a 400 Bad Request when creating a servicenow action with a not present in allowedHosts apiUrl', async () => { + await supertest + .post('/api/actions/connector') + .set('kbn-xsrf', 'foo') + .send({ + name: `A connector with type ${connectorType}`, + connector_type_id: connectorType, + config: { + apiUrl: 'http://servicenow.mynonexistent.com', + }, + secrets: connectorWithParams.secrets, + }) + .expect(400) + .then((resp: any) => { + expect(resp.body).to.eql({ + statusCode: 400, + error: 'Bad Request', + message: + 'error validating action type config: error configuring connector action: target url "http://servicenow.mynonexistent.com" is not added to the Kibana config xpack.actions.allowedHosts', + }); }); - }); - }); + }); - it('should respond with a 400 Bad Request when creating a servicenow action without secrets', async () => { - await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'foo') - .send({ - name: `A connector with type ${connectorType}`, - connector_type_id: connectorType, - config: { - apiUrl: serviceNowSimulatorURL, - }, - }) - .expect(400) - .then((resp: any) => { - expect(resp.body).to.eql({ - statusCode: 400, - error: 'Bad Request', - message: - 'error validating action type secrets: [password]: expected value of type [string] but got [undefined]', + it('should respond with a 400 Bad Request when creating a servicenow action without secrets', async () => { + await supertest + .post('/api/actions/connector') + .set('kbn-xsrf', 'foo') + .send({ + name: `A connector with type ${connectorType}`, + connector_type_id: connectorType, + config: { + apiUrl: serviceNowSimulatorURL, + }, + }) + .expect(400) + .then((resp: any) => { + expect(resp.body).to.eql({ + statusCode: 400, + error: 'Bad Request', + message: + 'error validating action type secrets: [password]: expected value of type [string] but got [undefined]', + }); }); - }); + }); }); }; @@ -188,231 +190,185 @@ export default function serviceNowTest({ getService }: FtrProviderContext) { ) => { let connectorId: string = ''; - before(async () => { - const { body } = await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'foo') - .send({ - name: 'A servicenow simulator', - connector_type_id: connectorType, - config: { - apiUrl: serviceNowSimulatorURL, - isLegacy: false, - }, - secrets: connectorWithParams.secrets, - }); - - connectorId = body.id; - }); + describe(`ServiceNow: Execute Validation: Connector Type: ${connectorType}`, () => { + before(async () => { + const { body } = await supertest + .post('/api/actions/connector') + .set('kbn-xsrf', 'foo') + .send({ + name: 'A servicenow simulator', + connector_type_id: connectorType, + config: { + apiUrl: serviceNowSimulatorURL, + isLegacy: false, + }, + secrets: connectorWithParams.secrets, + }); - it('should handle failing with a simulated success without action', async () => { - await supertest - .post(`/api/actions/connector/${connectorId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: {}, - }) - .then((resp: any) => { - expect(Object.keys(resp.body)).to.eql(['status', 'message', 'retry', 'connector_id']); - expect(resp.body.connector_id).to.eql(connectorId); - expect(resp.body.status).to.eql('error'); - expect(resp.body.retry).to.eql(false); - // Node.js 12 oddity: - // - // The first time after the server is booted, the error message will be: - // - // undefined is not iterable (cannot read property Symbol(Symbol.iterator)) - // - // After this, the error will be: - // - // Cannot destructure property 'value' of 'undefined' as it is undefined. - // - // The error seems to come from the exact same place in the code based on the - // exact same circumstances: - // - // https://github.com/elastic/kibana/blob/b0a223ebcbac7e404e8ae6da23b2cc6a4b509ff1/packages/kbn-config-schema/src/types/literal_type.ts#L28 - // - // What triggers the error is that the `handleError` function expects its 2nd - // argument to be an object containing a `valids` property of type array. - // - // In this test the object does not contain a `valids` property, so hence the - // error. - // - // Why the error message isn't the same in all scenarios is unknown to me and - // could be a bug in V8. - expect(resp.body.message).to.match( - /^error validating action params: (undefined is not iterable \(cannot read property Symbol\(Symbol.iterator\)\)|Cannot destructure property 'value' of 'undefined' as it is undefined\.)$/ - ); - }); - }); + connectorId = body.id; + }); - it('should handle failing with a simulated success without unsupported action', async () => { - await supertest - .post(`/api/actions/connector/${connectorId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { subAction: 'non-supported' }, - }) - .then((resp: any) => { - expect(resp.body).to.eql({ - connector_id: connectorId, - status: 'error', - retry: false, - message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subAction]: expected value to equal [pushToService]\n- [4.subAction]: expected value to equal [getChoices]', + it('should handle failing with a simulated success without action', async () => { + await supertest + .post(`/api/actions/connector/${connectorId}/_execute`) + .set('kbn-xsrf', 'foo') + .send({ + params: {}, + }) + .then((resp: any) => { + expect(Object.keys(resp.body)).to.eql(['status', 'message', 'retry', 'connector_id']); + expect(resp.body.connector_id).to.eql(connectorId); + expect(resp.body.status).to.eql('error'); + expect(resp.body.retry).to.eql(false); + // Node.js 12 oddity: + // + // The first time after the server is booted, the error message will be: + // + // undefined is not iterable (cannot read property Symbol(Symbol.iterator)) + // + // After this, the error will be: + // + // Cannot destructure property 'value' of 'undefined' as it is undefined. + // + // The error seems to come from the exact same place in the code based on the + // exact same circumstances: + // + // https://github.com/elastic/kibana/blob/b0a223ebcbac7e404e8ae6da23b2cc6a4b509ff1/packages/kbn-config-schema/src/types/literal_type.ts#L28 + // + // What triggers the error is that the `handleError` function expects its 2nd + // argument to be an object containing a `valids` property of type array. + // + // In this test the object does not contain a `valids` property, so hence the + // error. + // + // Why the error message isn't the same in all scenarios is unknown to me and + // could be a bug in V8. + expect(resp.body.message).to.match( + /^error validating action params: (undefined is not iterable \(cannot read property Symbol\(Symbol.iterator\)\)|Cannot destructure property 'value' of 'undefined' as it is undefined\.)$/ + ); }); - }); - }); + }); - it('should handle failing with a simulated success without subActionParams', async () => { - await supertest - .post(`/api/actions/connector/${connectorId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { subAction: 'pushToService' }, - }) - .then((resp: any) => { - expect(resp.body).to.eql({ - connector_id: connectorId, - status: 'error', - retry: false, - message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subActionParams.incident.short_description]: expected value of type [string] but got [undefined]\n- [4.subAction]: expected value to equal [getChoices]', + it('should handle failing with a simulated success without unsupported action', async () => { + await supertest + .post(`/api/actions/connector/${connectorId}/_execute`) + .set('kbn-xsrf', 'foo') + .send({ + params: { subAction: 'non-supported' }, + }) + .then((resp: any) => { + expect(resp.body).to.eql({ + connector_id: connectorId, + status: 'error', + retry: false, + message: + 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subAction]: expected value to equal [pushToService]\n- [4.subAction]: expected value to equal [getChoices]', + }); }); - }); - }); + }); - it('should handle failing with a simulated success without title', async () => { - await supertest - .post(`/api/actions/connector/${connectorId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { - ...connectorWithParams.params, - subActionParams: { - savedObjectId: 'success', - }, - }, - }) - .then((resp: any) => { - expect(resp.body).to.eql({ - connector_id: connectorId, - status: 'error', - retry: false, - message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subActionParams.incident.short_description]: expected value of type [string] but got [undefined]\n- [4.subAction]: expected value to equal [getChoices]', + it('should handle failing with a simulated success without subActionParams', async () => { + await supertest + .post(`/api/actions/connector/${connectorId}/_execute`) + .set('kbn-xsrf', 'foo') + .send({ + params: { subAction: 'pushToService' }, + }) + .then((resp: any) => { + expect(resp.body).to.eql({ + connector_id: connectorId, + status: 'error', + retry: false, + message: + 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subActionParams.incident.short_description]: expected value of type [string] but got [undefined]\n- [4.subAction]: expected value to equal [getChoices]', + }); }); - }); - }); + }); - it('should handle failing with a simulated success without commentId', async () => { - await supertest - .post(`/api/actions/connector/${connectorId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { - ...connectorWithParams.params, - subActionParams: { - incident: { - ...connectorWithParams.params.subActionParams.incident, - short_description: 'success', + it('should handle failing with a simulated success without title', async () => { + await supertest + .post(`/api/actions/connector/${connectorId}/_execute`) + .set('kbn-xsrf', 'foo') + .send({ + params: { + ...connectorWithParams.params, + subActionParams: { + savedObjectId: 'success', }, - comments: [{ comment: 'boo' }], }, - }, - }) - .then((resp: any) => { - expect(resp.body).to.eql({ - connector_id: connectorId, - status: 'error', - retry: false, - message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.commentId]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]\n- [4.subAction]: expected value to equal [getChoices]', + }) + .then((resp: any) => { + expect(resp.body).to.eql({ + connector_id: connectorId, + status: 'error', + retry: false, + message: + 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subActionParams.incident.short_description]: expected value of type [string] but got [undefined]\n- [4.subAction]: expected value to equal [getChoices]', + }); }); - }); - }); + }); - it('should handle failing with a simulated success without comment message', async () => { - await supertest - .post(`/api/actions/connector/${connectorId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { - ...connectorWithParams.params, - subActionParams: { - incident: { - ...connectorWithParams.params.subActionParams.incident, - short_description: 'success', + it('should handle failing with a simulated success without commentId', async () => { + await supertest + .post(`/api/actions/connector/${connectorId}/_execute`) + .set('kbn-xsrf', 'foo') + .send({ + params: { + ...connectorWithParams.params, + subActionParams: { + incident: { + ...connectorWithParams.params.subActionParams.incident, + short_description: 'success', + }, + comments: [{ comment: 'boo' }], }, - comments: [{ commentId: 'success' }], }, - }, - }) - .then((resp: any) => { - expect(resp.body).to.eql({ - connector_id: connectorId, - status: 'error', - retry: false, - message: - 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.comment]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]\n- [4.subAction]: expected value to equal [getChoices]', + }) + .then((resp: any) => { + expect(resp.body).to.eql({ + connector_id: connectorId, + status: 'error', + retry: false, + message: + 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.commentId]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]\n- [4.subAction]: expected value to equal [getChoices]', + }); }); - }); - }); - }; - - const testExecute = (connectorWithParams: Record, connectorType: string) => { - const tableName = connectorType === '.servicenow-sir' ? 'sn_si_incident' : 'incident'; - let connectorId: string = ''; - - before(async () => { - const { body } = await supertest - .post('/api/actions/connector') - .set('kbn-xsrf', 'foo') - .send({ - name: 'A servicenow simulator', - connector_type_id: connectorType, - config: { - apiUrl: serviceNowSimulatorURL, - isLegacy: true, - }, - secrets: connectorWithParams.secrets, - }); - - connectorId = body.id; - }); + }); - describe('Import set API', () => { - it('should handle creating an incident without comments', async () => { - const { body: result } = await supertest + it('should handle failing with a simulated success without comment message', async () => { + await supertest .post(`/api/actions/connector/${connectorId}/_execute`) .set('kbn-xsrf', 'foo') .send({ params: { ...connectorWithParams.params, subActionParams: { - incident: connectorWithParams.params.subActionParams.incident, - comments: [], + incident: { + ...connectorWithParams.params.subActionParams.incident, + short_description: 'success', + }, + comments: [{ commentId: 'success' }], }, }, }) - .expect(200); - - expect(proxyHaveBeenCalled).to.equal(true); - expect(result).to.eql({ - status: 'ok', - connector_id: connectorId, - data: { - id: '123', - title: 'INC01', - pushedDate: '2020-03-10T12:24:20.000Z', - url: `${serviceNowSimulatorURL}/nav_to.do?uri=${tableName}.do?sys_id=123`, - }, - }); + .then((resp: any) => { + expect(resp.body).to.eql({ + connector_id: connectorId, + status: 'error', + retry: false, + message: + 'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getFields]\n- [1.subAction]: expected value to equal [getIncident]\n- [2.subAction]: expected value to equal [handshake]\n- [3.subActionParams.comments]: types that failed validation:\n - [subActionParams.comments.0.0.comment]: expected value of type [string] but got [undefined]\n - [subActionParams.comments.1]: expected value to equal [null]\n- [4.subAction]: expected value to equal [getChoices]', + }); + }); }); }); + }; - // Legacy connectors - describe('Table API', () => { + const testExecute = (connectorWithParams: Record, connectorType: string) => { + const tableName = connectorType === '.servicenow-sir' ? 'sn_si_incident' : 'incident'; + let connectorId: string = ''; + + describe(`ServiceNow: Execute: Connector Type: ${connectorType}`, () => { before(async () => { const { body } = await supertest .post('/api/actions/connector') @@ -430,79 +386,129 @@ export default function serviceNowTest({ getService }: FtrProviderContext) { connectorId = body.id; }); - it('should handle creating an incident without comments', async () => { - const { body: result } = await supertest - .post(`/api/actions/connector/${connectorId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { - ...connectorWithParams.params, - subActionParams: { - incident: connectorWithParams.params.subActionParams.incident, - comments: [], + describe('Import set API', () => { + it('should handle creating an incident without comments', async () => { + const { body: result } = await supertest + .post(`/api/actions/connector/${connectorId}/_execute`) + .set('kbn-xsrf', 'foo') + .send({ + params: { + ...connectorWithParams.params, + subActionParams: { + incident: connectorWithParams.params.subActionParams.incident, + comments: [], + }, }, - }, - }) - .expect(200); + }) + .expect(200); - expect(proxyHaveBeenCalled).to.equal(true); - expect(result).to.eql({ - status: 'ok', - connector_id: connectorId, - data: { - id: '123', - title: 'INC01', - pushedDate: '2020-03-10T12:24:20.000Z', - url: `${serviceNowSimulatorURL}/nav_to.do?uri=${tableName}.do?sys_id=123`, - }, + expect(proxyHaveBeenCalled).to.equal(true); + expect(result).to.eql({ + status: 'ok', + connector_id: connectorId, + data: { + id: '123', + title: 'INC01', + pushedDate: '2020-03-10T12:24:20.000Z', + url: `${serviceNowSimulatorURL}/nav_to.do?uri=${tableName}.do?sys_id=123`, + }, + }); }); }); - }); - describe('getChoices', () => { - it('should get choices', async () => { - const { body: result } = await supertest - .post(`/api/actions/connector/${connectorId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { - subAction: 'getChoices', - subActionParams: { fields: ['priority'] }, - }, - }) - .expect(200); + // Legacy connectors + describe('Table API', () => { + before(async () => { + const { body } = await supertest + .post('/api/actions/connector') + .set('kbn-xsrf', 'foo') + .send({ + name: 'A servicenow simulator', + connector_type_id: connectorType, + config: { + apiUrl: serviceNowSimulatorURL, + isLegacy: true, + }, + secrets: connectorWithParams.secrets, + }); - expect(proxyHaveBeenCalled).to.equal(true); - expect(result).to.eql({ - status: 'ok', - connector_id: connectorId, - data: [ - { - dependent_value: '', - label: '1 - Critical', - value: '1', - }, - { - dependent_value: '', - label: '2 - High', - value: '2', - }, - { - dependent_value: '', - label: '3 - Moderate', - value: '3', - }, - { - dependent_value: '', - label: '4 - Low', - value: '4', - }, - { - dependent_value: '', - label: '5 - Planning', - value: '5', + connectorId = body.id; + }); + + it('should handle creating an incident without comments', async () => { + const { body: result } = await supertest + .post(`/api/actions/connector/${connectorId}/_execute`) + .set('kbn-xsrf', 'foo') + .send({ + params: { + ...connectorWithParams.params, + subActionParams: { + incident: connectorWithParams.params.subActionParams.incident, + comments: [], + }, + }, + }) + .expect(200); + + expect(proxyHaveBeenCalled).to.equal(true); + expect(result).to.eql({ + status: 'ok', + connector_id: connectorId, + data: { + id: '123', + title: 'INC01', + pushedDate: '2020-03-10T12:24:20.000Z', + url: `${serviceNowSimulatorURL}/nav_to.do?uri=${tableName}.do?sys_id=123`, }, - ], + }); + }); + }); + + describe('getChoices', () => { + it('should get choices', async () => { + const { body: result } = await supertest + .post(`/api/actions/connector/${connectorId}/_execute`) + .set('kbn-xsrf', 'foo') + .send({ + params: { + subAction: 'getChoices', + subActionParams: { fields: ['priority'] }, + }, + }) + .expect(200); + + expect(proxyHaveBeenCalled).to.equal(true); + expect(result).to.eql({ + status: 'ok', + connector_id: connectorId, + data: [ + { + dependent_value: '', + label: '1 - Critical', + value: '1', + }, + { + dependent_value: '', + label: '2 - High', + value: '2', + }, + { + dependent_value: '', + label: '3 - Moderate', + value: '3', + }, + { + dependent_value: '', + label: '4 - Low', + value: '4', + }, + { + dependent_value: '', + label: '5 - Planning', + value: '5', + }, + ], + }); }); }); });