Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Apr 14, 2020
1 parent 4655aea commit 81b9859
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { buildRouteValidation } from './route_validation';
import * as rt from 'io-ts';
import { RouteValidationResultFactory } from '../../../../../../../src/core/server/http';

describe('buildRouteValidation', () => {
const schema = rt.type({
ids: rt.array(rt.string),
});
const validationResult: RouteValidationResultFactory = {
ok: jest.fn().mockImplementation(validatedInput => validatedInput),
badRequest: jest.fn().mockImplementation(e => e),
};

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

test('return validation error', () => {
const input = { id: 'someId' };
const result = buildRouteValidation(schema)(input, validationResult);

expect(result).toEqual(
'Invalid value undefined supplied to : { ids: Array<string> }/ids: Array<string>'
);
});

test('return validated input', () => {
const input = { ids: ['someId'] };
const result = buildRouteValidation(schema)(input, validationResult);

expect(result).toEqual(input);
});
});

0 comments on commit 81b9859

Please sign in to comment.