Skip to content

Commit

Permalink
fix: fix tests #1720
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriy Zaleskyy committed Aug 27, 2021
1 parent 2a0b086 commit 13b57ac
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/services/__tests__/models/Response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,38 @@ import { RedocNormalizedOptions } from '../../RedocNormalizedOptions';
const opts = new RedocNormalizedOptions({});
describe('Models', () => {
describe('ResponseModel', () => {
let parser;
let parser, props;

beforeEach(() => {
parser = new OpenAPIParser({ openapi: '3.0.0' } as any, undefined, opts);
props = {
parser,
defaultAsError: false,
infoOrRef: {},
options: opts,
reverseEventsReadWriteProps: false,
code: 'default',
};
});

test('should calculate response type based on code', () => {
let resp = new ResponseModel(parser, '200', false, {}, opts);
let resp = new ResponseModel({...props, code: '200' });
expect(resp.type).toEqual('success');
resp = new ResponseModel(parser, '120', false, {}, opts);
resp = new ResponseModel({...props, code: '120' });
expect(resp.type).toEqual('info');
resp = new ResponseModel(parser, '301', false, {}, opts);
resp = new ResponseModel({...props, code: '301' });
expect(resp.type).toEqual('redirect');
resp = new ResponseModel(parser, '400', false, {}, opts);
resp = new ResponseModel({...props, code: '400' });
expect(resp.type).toEqual('error');
});

test('default should be successful by default', () => {
const resp = new ResponseModel(parser, 'default', false, {}, opts);
const resp = new ResponseModel({...props, code: 'default' });
expect(resp.type).toEqual('success');
});

test('default should be error if defaultAsError is true', () => {
const resp = new ResponseModel(parser, 'default', true, {}, opts);
const resp = new ResponseModel({...props, code: 'default', defaultAsError: true });
expect(resp.type).toEqual('error');
});
});
Expand Down

0 comments on commit 13b57ac

Please sign in to comment.