Skip to content

Commit

Permalink
updates tests after rebase with master
Browse files Browse the repository at this point in the history
  • Loading branch information
dhurley14 committed Nov 11, 2019
1 parent c305cac commit c10dd18
Showing 1 changed file with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ const mockLogger: Logger = {
return logString;
}),
trace: jest.fn(),
debug: jest.fn(),
debug: jest.fn((logString: string) => {
return logString;
}),
error: jest.fn((logString: string) => {
return logString;
}),
Expand Down Expand Up @@ -115,7 +117,7 @@ describe('utils', () => {
mockService,
mockLogger
);
expect(mockLogger.info).toHaveBeenCalledTimes(2);
expect(mockLogger.debug).toHaveBeenCalledTimes(2);
expect(mockLogger.warn).toHaveBeenCalledTimes(0);
expect(successfulSingleBulkIndex).toEqual(true);
});
Expand All @@ -138,9 +140,9 @@ describe('utils', () => {
mockService,
mockLogger
);
expect(mockLogger.info).toHaveBeenCalledTimes(0);
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
expect(successfulSingleBulkIndex).toEqual(false);
expect(mockLogger.debug).toHaveBeenCalledTimes(0);
expect(mockLogger.error).toHaveBeenCalledTimes(0);
expect(successfulSingleBulkIndex).toEqual(true);
});
test('create unsuccessful bulk index due to bulk index errors', async () => {
// need a sample search result, sample signal params, mock service, mock logger
Expand Down Expand Up @@ -178,7 +180,7 @@ describe('utils', () => {
mockService,
mockLogger
);
expect(mockLogger.info).toHaveBeenCalledTimes(2);
expect(mockLogger.debug).toHaveBeenCalledTimes(2);
expect(mockLogger.warn).toHaveBeenCalledTimes(0);
expect(mockLogger.error).toHaveBeenCalledTimes(1);
expect(successfulSingleBulkIndex).toEqual(false);
Expand Down Expand Up @@ -283,6 +285,33 @@ describe('utils', () => {
});
});
describe('searchAfterAndBulkIndex', () => {
test('if successful with empty search results', async () => {
const searchAfterSortId = '1234567891111';
const sampleParams = sampleSignalAlertParams(undefined);
const savedObjectsClient = savedObjectsClientMock.create();
const expectedSearchAfterQuery = buildEventsSearchQuery({
index: sampleParams.index,
from: sampleParams.from,
to: sampleParams.to,
filter: sampleParams.filter,
size: sampleParams.size ? sampleParams.size : 1,
searchAfterSortId,
maxDocs: undefined,
});
const mockService: AlertServices = {
callCluster: jest.fn(),
alertInstanceFactory: jest.fn(),
savedObjectsClient,
};
const result = await searchAfterAndBulkIndex(
sampleEmptyDocSearchResults,
sampleParams,
mockService,
mockLogger
);
expect(mockService.callCluster).toHaveBeenCalledTimes(0);
expect(result).toEqual(true);
});
test('if one successful iteration of searchAfterAndBulkIndex', async () => {
const searchAfterSortId = '1234567891111';
const sampleParams = sampleSignalAlertParams(undefined);
Expand Down Expand Up @@ -396,7 +425,7 @@ describe('utils', () => {
mockService,
mockLogger
);
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
expect(mockLogger.error).toHaveBeenCalledTimes(2);
expect(result).toEqual(false);
});
test('if unsuccessful iteration of searchAfterAndBulkIndex due to empty sort ids', async () => {
Expand Down Expand Up @@ -530,7 +559,7 @@ describe('utils', () => {
mockService,
mockLogger
);
expect(mockLogger.warn).toHaveBeenCalledTimes(1);
expect(mockLogger.error).toHaveBeenCalledTimes(1);
expect(result).toEqual(true);
});
test('if logs error when iteration is unsuccessful when bulk index results in a failure', async () => {
Expand Down

0 comments on commit c10dd18

Please sign in to comment.