11import * as fs from 'fs' ;
22import * as path from 'path' ;
3- import { CommonInputModel } from '../../src/models' ;
3+ import { CommonInputModel , ProcessorOptions } from '../../src/models' ;
44import { InputProcessor } from '../../src/processors/InputProcessor' ;
55import { JsonSchemaInputProcessor } from '../../src/processors/JsonSchemaInputProcessor' ;
66import { AsyncAPIInputProcessor } from '../../src/processors/AsyncAPIInputProcessor' ;
77import { AbstractInputProcessor } from '../../src/processors' ;
8-
8+ import AsyncAPIParser from '@asyncapi/parser' ;
99describe ( 'InputProcessor' , ( ) => {
1010 beforeEach ( ( ) => {
1111 jest . resetAllMocks ( ) ;
@@ -64,7 +64,7 @@ describe('InputProcessor', () => {
6464 await processor . process ( inputSchema ) ;
6565 expect ( asyncInputProcessor . process ) . not . toHaveBeenCalled ( ) ;
6666 expect ( asyncInputProcessor . shouldProcess ) . toHaveBeenNthCalledWith ( 1 , inputSchema ) ;
67- expect ( defaultInputProcessor . process ) . toHaveBeenNthCalledWith ( 1 , inputSchema ) ;
67+ expect ( defaultInputProcessor . process ) . toHaveBeenNthCalledWith ( 1 , inputSchema , undefined ) ;
6868 expect ( defaultInputProcessor . shouldProcess ) . toHaveBeenNthCalledWith ( 1 , inputSchema ) ;
6969 } ) ;
7070
@@ -73,8 +73,25 @@ describe('InputProcessor', () => {
7373 const inputSchemaString = fs . readFileSync ( path . resolve ( __dirname , './AsyncAPIInputProcessor/basic.json' ) , 'utf8' ) ;
7474 const inputSchema = JSON . parse ( inputSchemaString ) ;
7575 await processor . process ( inputSchema ) ;
76- expect ( asyncInputProcessor . process ) . toHaveBeenNthCalledWith ( 1 , inputSchema ) ;
76+ expect ( asyncInputProcessor . process ) . toHaveBeenNthCalledWith ( 1 , inputSchema , undefined ) ;
77+ expect ( asyncInputProcessor . shouldProcess ) . toHaveBeenNthCalledWith ( 1 , inputSchema ) ;
78+ expect ( defaultInputProcessor . process ) . not . toHaveBeenCalled ( ) ;
79+ expect ( defaultInputProcessor . shouldProcess ) . not . toHaveBeenCalled ( ) ;
80+ } ) ;
81+ test ( 'should be able to process AsyncAPI schema input with options' , async ( ) => {
82+ const { processor, asyncInputProcessor, defaultInputProcessor} = getProcessors ( ) ;
83+ const spy = jest . spyOn ( AsyncAPIParser , 'parse' ) ;
84+ const options : ProcessorOptions = {
85+ asyncapi : {
86+ path : 'test'
87+ }
88+ } ;
89+ const inputSchemaString = fs . readFileSync ( path . resolve ( __dirname , './AsyncAPIInputProcessor/basic.json' ) , 'utf8' ) ;
90+ const inputSchema = JSON . parse ( inputSchemaString ) ;
91+ await processor . process ( inputSchema , options ) ;
92+ expect ( asyncInputProcessor . process ) . toHaveBeenNthCalledWith ( 1 , inputSchema , options ) ;
7793 expect ( asyncInputProcessor . shouldProcess ) . toHaveBeenNthCalledWith ( 1 , inputSchema ) ;
94+ expect ( spy ) . toHaveBeenNthCalledWith ( 1 , inputSchema , expect . objectContaining ( options . asyncapi ) ) ;
7895 expect ( defaultInputProcessor . process ) . not . toHaveBeenCalled ( ) ;
7996 expect ( defaultInputProcessor . shouldProcess ) . not . toHaveBeenCalled ( ) ;
8097 } ) ;
0 commit comments