Skip to content

Commit

Permalink
fixed due to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Mar 16, 2021
1 parent 749793c commit db83818
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 190 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ActionType } from '../../../types';
import { httpServiceMock } from '../../../../../../../src/core/public/mocks';
import { loadActionTypes } from './index';

const http = httpServiceMock.createStartContract();

beforeEach(() => jest.resetAllMocks());

describe('loadActionTypes', () => {
test('should call get types API', async () => {
const apiResponseValue = [
{
id: 'test',
name: 'Test',
enabled: true,
enabled_in_config: true,
enabled_in_license: true,
minimum_license_required: 'basic',
},
];
http.get.mockResolvedValueOnce(apiResponseValue);

const resolvedValue: ActionType[] = [
{
id: 'test',
name: 'Test',
enabled: true,
enabledInConfig: true,
enabledInLicense: true,
minimumLicenseRequired: 'basic',
},
];

const result = await loadActionTypes({ http });
expect(result).toEqual(resolvedValue);
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/actions/connector_types",
]
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { httpServiceMock } from '../../../../../../../src/core/public/mocks';
import { loadAllActions } from './index';

const http = httpServiceMock.createStartContract();

beforeEach(() => jest.resetAllMocks());

describe('loadAllActions', () => {
test('should call getAll actions API', async () => {
http.get.mockResolvedValueOnce([]);

const result = await loadAllActions({ http });
expect(result).toEqual([]);
expect(http.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/actions/connectors",
]
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ActionConnectorWithoutId } from '../../../types';
import { httpServiceMock } from '../../../../../../../src/core/public/mocks';
import { createActionConnector } from './index';

const http = httpServiceMock.createStartContract();

beforeEach(() => jest.resetAllMocks());

describe('createActionConnector', () => {
test('should call create action API', async () => {
const apiResponse = {
connector_type_id: 'test',
is_preconfigured: false,
name: 'My test',
config: {},
secrets: {},
id: '123',
};
http.post.mockResolvedValueOnce(apiResponse);

const connector: ActionConnectorWithoutId<{}, {}> = {
actionTypeId: 'test',
isPreconfigured: false,
name: 'My test',
config: {},
secrets: {},
};
const resolvedValue = { ...connector, id: '123' };

const result = await createActionConnector({ http, connector });
expect(result).toEqual(resolvedValue);
expect(http.post.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/actions/connector",
Object {
"body": "{\\"name\\":\\"My test\\",\\"config\\":{},\\"secrets\\":{},\\"connector_type_id\\":\\"test\\",\\"is_preconfigured\\":false}",
},
]
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { httpServiceMock } from '../../../../../../../src/core/public/mocks';
import { deleteActions } from './index';

const http = httpServiceMock.createStartContract();

beforeEach(() => jest.resetAllMocks());

describe('deleteActions', () => {
test('should call delete API per action', async () => {
const ids = ['1', '2', '3'];

const result = await deleteActions({ ids, http });
expect(result).toEqual({ errors: [], successes: [undefined, undefined, undefined] });
expect(http.delete.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"/api/actions/connector/1",
],
Array [
"/api/actions/connector/2",
],
Array [
"/api/actions/connector/3",
],
]
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { httpServiceMock } from '../../../../../../../src/core/public/mocks';
import { executeAction } from './index';

const http = httpServiceMock.createStartContract();

beforeEach(() => jest.resetAllMocks());

describe('executeAction', () => {
test('should call execute API', async () => {
const id = '123';
const params = {
stringParams: 'someString',
numericParams: 123,
};

http.post.mockResolvedValueOnce({
connector_id: id,
status: 'ok',
});

const result = await executeAction({ id, http, params });
expect(result).toEqual({
actionId: id,
status: 'ok',
});
expect(http.post.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"/api/actions/connector/123/_execute",
Object {
"body": "{\\"params\\":{\\"stringParams\\":\\"someString\\",\\"numericParams\\":123}}",
},
]
`);
});
});
Loading

0 comments on commit db83818

Please sign in to comment.