Skip to content

Commit

Permalink
add explicit OpenAPIInputProcessor parameter schema unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkenyonjonesfs committed Sep 5, 2023
1 parent 6b32737 commit b21c87b
Showing 1 changed file with 48 additions and 6 deletions.
54 changes: 48 additions & 6 deletions test/processors/OpenAPIInputProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ const basicDoc = JSON.parse(
)
);
jest.mock('../../src/utils/LoggingInterface');
jest.spyOn(OpenAPIInputProcessor, 'convertToInternalSchema');
const processorSpy = jest.spyOn(
OpenAPIInputProcessor,
'convertToInternalSchema'
);
const mockedReturnModels = [new CommonModel()];
const mockedMetaModel = new AnyModel('', undefined);
jest.mock('../../src/helpers/CommonModelToMetaModel', () => {
Expand All @@ -34,6 +37,9 @@ describe('OpenAPIInputProcessor', () => {
afterAll(() => {
jest.restoreAllMocks();
});
afterEach(() => {
jest.clearAllMocks();
});
describe('shouldProcess()', () => {
const processor = new OpenAPIInputProcessor();
test('should be able to process OpenAPI 3.0.0 documents', () => {
Expand Down Expand Up @@ -82,11 +88,47 @@ describe('OpenAPIInputProcessor', () => {
const processor = new OpenAPIInputProcessor();
const commonInputModel = await processor.process(basicDoc);
expect(commonInputModel).toMatchSnapshot();
expect(
(
OpenAPIInputProcessor.convertToInternalSchema as any as jest.SpyInstance
).mock.calls
).toMatchSnapshot();
expect(processorSpy.mock.calls).toMatchSnapshot();
});
test('should include schema for parameters', async () => {
const doc = {
openapi: '3.0.3',
info: {},
paths: {
'/test': {
parameters: [
{
name: 'path_parameter',
in: 'header',
schema: { type: 'string' }
}
],
get: {
parameters: [
{
name: 'operation_parameter',
in: 'query',
schema: { type: 'string' }
}
],
responses: {
204: {}
}
}
}
}
};

const processor = new OpenAPIInputProcessor();
await processor.process(doc);
expect(processorSpy.mock.calls).toContainEqual([
{ type: 'string' },
'test_get_parameters_query_operation_parameter'
]);
expect(processorSpy.mock.calls).toContainEqual([
{ type: 'string' },
'test_parameters_header_path_parameter'
]);
});
});
});

0 comments on commit b21c87b

Please sign in to comment.