@@ -156,10 +156,9 @@ describe('index', function() {
156156 delete process . env . NODE_CONFIG_DIR ;
157157 } ) ;
158158
159- it ( 'should use the configured router interface ' , function ( done ) {
159+ it ( 'should use pipe interface when _router.controllersInterface is set to `pipe` ' , function ( done ) {
160160 var config = _ . clone ( DEFAULT_PROJECT_CONFIG ) ;
161-
162- process . env . NODE_CONFIG_DIR = path . resolve ( DEFAULT_PROJECT_ROOT , "config_pipe" ) ;
161+ config . configDir = path . resolve ( DEFAULT_PROJECT_ROOT , "config_pipe" ) ;
163162
164163 SwaggerRunner . create ( config , function ( err , runner ) {
165164 if ( err ) { return done ( err ) ; }
@@ -181,8 +180,116 @@ describe('index', function() {
181180 done ( ) ;
182181 } ) ;
183182 } ) ;
184-
185183 } ) ;
184+
185+ it ( 'should use pipe interface when _router.controllersInterface is set to `auto` and operation.length is 2' , function ( done ) {
186+ var config = _ . clone ( DEFAULT_PROJECT_CONFIG ) ;
187+ config . configDir = path . resolve ( DEFAULT_PROJECT_ROOT , "config_auto" ) ;
188+
189+ SwaggerRunner . create ( config , function ( err , runner ) {
190+ if ( err ) { return done ( err ) ; }
191+ runner . config . swagger . bagpipes . should . have . property ( 'swagger_controllers' ) ;
192+
193+ var app = require ( 'connect' ) ( ) ;
194+ runner . connectMiddleware ( ) . register ( app ) ;
195+
196+ var request = require ( 'supertest' ) ;
197+
198+ request ( app )
199+ . get ( '/controller_interface_auto_detected_as_pipe' )
200+ . set ( 'Accept' , 'application/json' )
201+ . expect ( 200 )
202+ . expect ( 'Content-Type' , / j s o n / )
203+ . expect ( 'x-interface' , / p i p e / )
204+ . end ( function ( err , res ) {
205+ should . not . exist ( err , err && err . stack ) ;
206+ res . body . should . eql ( { interface : "pipe" } ) ;
207+ done ( ) ;
208+ } ) ;
209+ } ) ;
210+ } ) ;
211+
212+ it ( 'should use middleware interface when _router.controllersInterface is set to `auto` and operation.length is 3' , function ( done ) {
213+ var config = _ . clone ( DEFAULT_PROJECT_CONFIG ) ;
214+ config . configDir = path . resolve ( DEFAULT_PROJECT_ROOT , "config_auto" ) ;
215+
216+ SwaggerRunner . create ( config , function ( err , runner ) {
217+ if ( err ) { return done ( err ) ; }
218+ runner . config . swagger . bagpipes . should . have . property ( 'swagger_controllers' ) ;
219+
220+ var app = require ( 'connect' ) ( ) ;
221+ runner . connectMiddleware ( ) . register ( app ) ;
222+
223+ var request = require ( 'supertest' ) ;
224+
225+ request ( app )
226+ . get ( '/controller_interface_auto_detected_as_middleware' )
227+ . set ( 'Accept' , 'application/json' )
228+ . expect ( 200 )
229+ . expect ( 'Content-Type' , / j s o n / )
230+ . expect ( 'x-interface' , / m i d d l e w a r e / )
231+ . end ( function ( err , res ) {
232+ should . not . exist ( err , err && err . stack ) ;
233+ res . body . should . eql ( { interface : "middleware" } ) ;
234+ done ( ) ;
235+ } ) ;
236+ } ) ;
237+ } ) ;
238+
239+ it ( 'should use adhere to cascading directgive `x-interface-type` found on path' , function ( done ) {
240+ var config = _ . clone ( DEFAULT_PROJECT_CONFIG ) ;
241+ config . configDir = path . resolve ( DEFAULT_PROJECT_ROOT , "config_auto" ) ;
242+
243+ SwaggerRunner . create ( config , function ( err , runner ) {
244+ if ( err ) { return done ( err ) ; }
245+ runner . config . swagger . bagpipes . should . have . property ( 'swagger_controllers' ) ;
246+
247+ var app = require ( 'connect' ) ( ) ;
248+ runner . connectMiddleware ( ) . register ( app ) ;
249+
250+ var request = require ( 'supertest' ) ;
251+
252+ request ( app )
253+ . get ( '/controller_interface_on_path_cascades' )
254+ . set ( 'Accept' , 'application/json' )
255+ . expect ( 200 )
256+ . expect ( 'Content-Type' , / j s o n / )
257+ . expect ( 'x-interface' , / p i p e / )
258+ . end ( function ( err , res ) {
259+ should . not . exist ( err , err && err . stack ) ;
260+ res . body . should . eql ( { interface : "pipe" } ) ;
261+ done ( ) ;
262+ } ) ;
263+ } ) ;
264+ } ) ;
265+
266+ it ( 'should use adhere to cascading directgive `x-interface-type` found on operation over one found on path' , function ( done ) {
267+ var config = _ . clone ( DEFAULT_PROJECT_CONFIG ) ;
268+ config . configDir = path . resolve ( DEFAULT_PROJECT_ROOT , "config_auto" ) ;
269+
270+ SwaggerRunner . create ( config , function ( err , runner ) {
271+ if ( err ) { return done ( err ) ; }
272+ runner . config . swagger . bagpipes . should . have . property ( 'swagger_controllers' ) ;
273+
274+ var app = require ( 'connect' ) ( ) ;
275+ runner . connectMiddleware ( ) . register ( app ) ;
276+
277+ var request = require ( 'supertest' ) ;
278+
279+ request ( app )
280+ . get ( '/controller_interface_on_operation_cascades' )
281+ . set ( 'Accept' , 'application/json' )
282+ . expect ( 200 )
283+ . expect ( 'Content-Type' , / j s o n / )
284+ . expect ( 'x-interface' , / m i d d l e w a r e / )
285+ . end ( function ( err , res ) {
286+ should . not . exist ( err , err && err . stack ) ;
287+ res . body . should . eql ( { interface : "middleware" } ) ;
288+ done ( ) ;
289+ } ) ;
290+ } ) ;
291+ } ) ;
292+
186293
187294 it ( 'should fail without callback' , function ( ) {
188295 ( function ( ) { SwaggerRunner . create ( DEFAULT_PROJECT_CONFIG ) } ) . should . throw ( 'callback is required' ) ;
0 commit comments