Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Sep 25, 2017
1 parent d6c490d commit f3e01f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { getParams, handleResponse } from '../calculate_indices';
import { getParams, handleResponse, handleError } from '../calculate_indices';

describe('calculateIndices', () => {

Expand Down Expand Up @@ -32,6 +32,22 @@ describe('calculateIndices', () => {

});

describe('handleError', () => {
it('should resolve a promise with an array with the index pattern', () => {
const error = new Error('_field_stats');
error.statusCode = 400;
return handleError('metricbeat-*')(error)
.then(resp => expect(resp).to.eql(['metricbeat-*']));
});

it('should reject a promise if the error is not field stats', () => {
const error = new Error('_');
error.statusCode = 404;
return handleError('metricbeat-*')(error)
.catch(err => expect(err instanceof Error).to.equal(true));
});
});

describe('handleResponse', () => {
it('returns an array of indices', () => {
const resp = {
Expand Down
Expand Up @@ -39,7 +39,7 @@ function handleError(indexPattern) {
const errorCode400 = error.statusCode === 400;
const fieldStatsError = (error.message || '').includes('_field_stats');
if (errorCode400 && fieldStatsError) {
return [indexPattern];
return Promise.resolve([indexPattern]);
}
return Promise.reject(error);
};
Expand All @@ -57,4 +57,5 @@ function calculateIndices(req, indexPattern = '*', timeField = '@timestamp', off

calculateIndices.handleResponse = handleResponse;
calculateIndices.getParams = getParams;
calculateIndices.handleError = handleError;
export default calculateIndices;

0 comments on commit f3e01f2

Please sign in to comment.