Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 30, 2020
1 parent 1a64bf6 commit 3603141
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const mapParams = (
return Object.keys(params).reduce((prev: AnyParams, curr: string): AnyParams => {
const field = mapping.get(curr);
if (field) {
prev[field.target] = get(curr, params);
prev[field.target] = get(params, curr);
}
return prev;
}, {});
Expand Down
24 changes: 12 additions & 12 deletions x-pack/plugins/actions/server/builtin_action_types/jira/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { ExternalService } from '../case/types';
describe('api', () => {
let externalService: jest.Mocked<ExternalService>;

beforeAll(() => {
beforeEach(() => {
externalService = externalServiceMock.create();
});

beforeEach(() => {
afterEach(() => {
jest.clearAllMocks();
});

Expand All @@ -26,7 +26,7 @@ describe('api', () => {
const res = await api.pushToService({ externalService, mapping, params });

expect(res).toEqual({
id: '1',
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
Expand All @@ -48,7 +48,7 @@ describe('api', () => {
const res = await api.pushToService({ externalService, mapping, params });

expect(res).toEqual({
id: '1',
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
Expand All @@ -74,7 +74,7 @@ describe('api', () => {
await api.pushToService({ externalService, mapping, params });
expect(externalService.createComment).toHaveBeenCalledTimes(2);
expect(externalService.createComment).toHaveBeenNthCalledWith(1, {
incidentId: '1',
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-1',
version: 'WzU3LDFd',
Expand All @@ -94,7 +94,7 @@ describe('api', () => {
});

expect(externalService.createComment).toHaveBeenNthCalledWith(2, {
incidentId: '1',
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-2',
version: 'WlK3LDFd',
Expand All @@ -120,8 +120,8 @@ describe('api', () => {
const res = await api.pushToService({ externalService, mapping, params: apiParams });

expect(res).toEqual({
id: 'incident-2',
title: 'INC02',
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
comments: [
Expand All @@ -142,8 +142,8 @@ describe('api', () => {
const res = await api.pushToService({ externalService, mapping, params });

expect(res).toEqual({
id: 'incident-2',
title: 'INC02',
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
});
Expand All @@ -169,7 +169,7 @@ describe('api', () => {
await api.pushToService({ externalService, mapping, params });
expect(externalService.createComment).toHaveBeenCalledTimes(2);
expect(externalService.createComment).toHaveBeenNthCalledWith(1, {
incidentId: 'incident-2',
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-1',
version: 'WzU3LDFd',
Expand All @@ -189,7 +189,7 @@ describe('api', () => {
});

expect(externalService.createComment).toHaveBeenNthCalledWith(2, {
incidentId: 'incident-2',
incidentId: 'incident-1',
comment: {
commentId: 'case-comment-2',
version: 'WlK3LDFd',
Expand Down
72 changes: 43 additions & 29 deletions x-pack/plugins/actions/server/builtin_action_types/jira/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,55 @@ import {
MapRecord,
} from '../case/types';

const createMock = (): jest.Mocked<ExternalService> => ({
getIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: '1',
key: 'CK-1',
summary: 'title from jira',
description: 'description from jira',
created: '2020-04-27T10:59:46.202Z',
updated: '2020-04-27T10:59:46.202Z',
})
),
createIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: '1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
})
),
updateIncident: jest.fn().mockImplementation(() =>
const createMock = (): jest.Mocked<ExternalService> => {
const service = {
getIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: 'incident-1',
key: 'CK-1',
summary: 'title from jira',
description: 'description from jira',
created: '2020-04-27T10:59:46.202Z',
updated: '2020-04-27T10:59:46.202Z',
})
),
createIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
})
),
updateIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
})
),
createComment: jest.fn(),
};

service.createComment.mockImplementationOnce(() =>
Promise.resolve({
id: 'incident-2',
title: 'INC02',
commentId: 'case-comment-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
externalCommentId: '1',
})
),
createComment: jest.fn().mockImplementation(() =>
);

service.createComment.mockImplementationOnce(() =>
Promise.resolve({
commentId: 'comment-1',
commentId: 'case-comment-2',
pushedDate: '2020-04-27T10:59:46.202Z',
externalCommentId: '1',
externalCommentId: '2',
})
),
});
);

return service;
};

const externalServiceMock = {
create: createMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import { ExternalService } from '../case/types';
describe('api', () => {
let externalService: jest.Mocked<ExternalService>;

beforeAll(() => {
beforeEach(() => {
externalService = externalServiceMock.create();
jest.clearAllMocks();
});

beforeEach(() => {
afterEach(() => {
jest.clearAllMocks();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,48 @@ import {
MapRecord,
} from '../case/types';

const createMock = (): jest.Mocked<ExternalService> => ({
getIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
short_description: 'title from servicenow',
description: 'description from servicenow',
})
),
createIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: 'incident-1',
title: 'INC01',
pushedDate: '2020-03-10T12:24:20.000Z',
url: 'https://instance.service-now.com/nav_to.do?uri=incident.do?sys_id=123',
})
),
updateIncident: jest.fn().mockImplementation(() =>
const createMock = (): jest.Mocked<ExternalService> => {
const service = {
getIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
short_description: 'title from servicenow',
description: 'description from servicenow',
})
),
createIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: 'incident-1',
title: 'INC01',
pushedDate: '2020-03-10T12:24:20.000Z',
url: 'https://instance.service-now.com/nav_to.do?uri=incident.do?sys_id=123',
})
),
updateIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: 'incident-2',
title: 'INC02',
pushedDate: '2020-03-10T12:24:20.000Z',
url: 'https://instance.service-now.com/nav_to.do?uri=incident.do?sys_id=123',
})
),
createComment: jest.fn(),
};

service.createComment.mockImplementationOnce(() =>
Promise.resolve({
id: 'incident-2',
title: 'INC02',
commentId: 'case-comment-1',
pushedDate: '2020-03-10T12:24:20.000Z',
url: 'https://instance.service-now.com/nav_to.do?uri=incident.do?sys_id=123',
})
),
createComment: jest.fn().mockImplementation(() =>
);

service.createComment.mockImplementationOnce(() =>
Promise.resolve({
commentId: 'comment-1',
commentId: 'case-comment-2',
pushedDate: '2020-03-10T12:24:20.000Z',
})
),
});
);
return service;
};

const externalServiceMock = {
create: createMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
} from '../../../../common/fixtures/plugins/actions';
} from '../../../../common/fixtures/plugins/actions_simulators';

const mapping = [
{
Expand Down Expand Up @@ -325,8 +325,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
actionId: simulatedActionId,
status: 'error',
retry: false,
message:
'error validating action params: [subAction]: expected at least one defined value but got [undefined]',
message: `error validating action params: Cannot read property 'Symbol(Symbol.iterator)' of undefined`,
});
});
});
Expand All @@ -344,7 +343,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [subAction]: types that failed validation:\n- [subAction.0]: expected value to equal [getIncident]\n- [subAction.1]: expected value to equal [pushToService]\n- [subAction.2]: expected value to equal [handshake]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subAction]: expected value to equal [pushToService]',
});
});
});
Expand All @@ -362,7 +361,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [subActionParams.caseId]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.caseId]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -380,7 +379,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [subActionParams.caseId]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.caseId]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -403,7 +402,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [subActionParams.title]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.title]: expected value of type [string] but got [undefined]',
});
});
});
Expand All @@ -427,7 +426,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [subActionParams.createdAt]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.createdAt]: expected value of type [string] but got [undefined]',
});
});
});
Expand Down Expand Up @@ -455,7 +454,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [subActionParams.comments.0.commentId]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.commentId]: expected value of type [string] but got [undefined]',
});
});
});
Expand Down Expand Up @@ -483,7 +482,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [subActionParams.comments.0.comment]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.comment]: expected value of type [string] but got [undefined]',
});
});
});
Expand Down Expand Up @@ -511,7 +510,7 @@ export default function jiraTest({ getService }: FtrProviderContext) {
status: 'error',
retry: false,
message:
'error validating action params: [subActionParams.comments.0.createdAt]: expected value of type [string] but got [undefined]',
'error validating action params: types that failed validation:\n- [0.subAction]: expected value to equal [getIncident]\n- [1.subAction]: expected value to equal [handshake]\n- [2.subActionParams.comments.0.createdAt]: expected value of type [string] but got [undefined]',
});
});
});
Expand Down
Loading

0 comments on commit 3603141

Please sign in to comment.