forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [Cases] Follow up jest tests for elastic#84587 (e…
- Loading branch information
1 parent
38c5cde
commit eeb7d4a
Showing
17 changed files
with
1,087 additions
and
749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
x-pack/plugins/case/server/client/configure/get_fields.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ConnectorTypes } from '../../../common/api'; | ||
|
||
import { createMockSavedObjectsRepository, mockCaseMappings } from '../../routes/api/__fixtures__'; | ||
import { createCaseClientWithMockSavedObjectsClient } from '../mocks'; | ||
import { actionsClientMock } from '../../../../actions/server/actions_client.mock'; | ||
import { actionsErrResponse, mappings, mockGetFieldsResponse } from './mock'; | ||
describe('get_fields', () => { | ||
const execute = jest.fn().mockReturnValue(mockGetFieldsResponse); | ||
const actionsMock = { ...actionsClientMock.create(), execute }; | ||
beforeEach(async () => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('happy path', () => { | ||
test('it gets fields', async () => { | ||
const savedObjectsClient = createMockSavedObjectsRepository({ | ||
caseMappingsSavedObject: mockCaseMappings, | ||
}); | ||
const caseClient = await createCaseClientWithMockSavedObjectsClient(savedObjectsClient); | ||
const res = await caseClient.client.getFields({ | ||
actionsClient: actionsMock, | ||
connectorType: ConnectorTypes.jira, | ||
connectorId: '123', | ||
}); | ||
expect(res).toEqual({ | ||
fields: [ | ||
{ id: 'summary', name: 'Summary', required: true, type: 'text' }, | ||
{ id: 'description', name: 'Description', required: false, type: 'text' }, | ||
], | ||
defaultMappings: mappings[ConnectorTypes.jira], | ||
}); | ||
}); | ||
}); | ||
|
||
describe('unhappy path', () => { | ||
test('it throws error', async () => { | ||
const savedObjectsClient = createMockSavedObjectsRepository({ | ||
caseMappingsSavedObject: mockCaseMappings, | ||
}); | ||
const caseClient = await createCaseClientWithMockSavedObjectsClient(savedObjectsClient); | ||
await caseClient.client | ||
.getFields({ | ||
actionsClient: { ...actionsMock, execute: jest.fn().mockReturnValue(actionsErrResponse) }, | ||
connectorType: ConnectorTypes.jira, | ||
connectorId: '123', | ||
}) | ||
.catch((e) => { | ||
expect(e).not.toBeNull(); | ||
expect(e.isBoom).toBe(true); | ||
expect(e.output.statusCode).toBe(424); | ||
}); | ||
}); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
x-pack/plugins/case/server/client/configure/get_mappings.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ConnectorTypes } from '../../../common/api'; | ||
|
||
import { createMockSavedObjectsRepository, mockCaseMappings } from '../../routes/api/__fixtures__'; | ||
import { createCaseClientWithMockSavedObjectsClient } from '../mocks'; | ||
import { actionsClientMock } from '../../../../actions/server/actions_client.mock'; | ||
import { mappings, mockGetFieldsResponse } from './mock'; | ||
|
||
describe('get_mappings', () => { | ||
const execute = jest.fn().mockReturnValue(mockGetFieldsResponse); | ||
const actionsMock = { ...actionsClientMock.create(), execute }; | ||
beforeEach(async () => { | ||
jest.restoreAllMocks(); | ||
const spyOnDate = jest.spyOn(global, 'Date') as jest.SpyInstance<{}, []>; | ||
spyOnDate.mockImplementation(() => ({ | ||
toISOString: jest.fn().mockReturnValue('2019-11-25T21:54:48.952Z'), | ||
})); | ||
}); | ||
|
||
describe('happy path', () => { | ||
test('it gets existing mappings', async () => { | ||
const savedObjectsClient = createMockSavedObjectsRepository({ | ||
caseMappingsSavedObject: mockCaseMappings, | ||
}); | ||
const caseClient = await createCaseClientWithMockSavedObjectsClient(savedObjectsClient); | ||
const res = await caseClient.client.getMappings({ | ||
actionsClient: actionsMock, | ||
caseClient: caseClient.client, | ||
connectorType: ConnectorTypes.jira, | ||
connectorId: '123', | ||
}); | ||
|
||
expect(res).toEqual(mappings[ConnectorTypes.jira]); | ||
}); | ||
test('it creates new mappings', async () => { | ||
const savedObjectsClient = createMockSavedObjectsRepository({ | ||
caseMappingsSavedObject: [], | ||
}); | ||
const caseClient = await createCaseClientWithMockSavedObjectsClient(savedObjectsClient); | ||
const res = await caseClient.client.getMappings({ | ||
actionsClient: actionsMock, | ||
caseClient: caseClient.client, | ||
connectorType: ConnectorTypes.jira, | ||
connectorId: '123', | ||
}); | ||
|
||
expect(res).toEqual(mappings[ConnectorTypes.jira]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.