@@ -419,7 +419,6 @@ describe('registry : routes : component', function(){
419
419
} ) ;
420
420
421
421
describe ( 'when getting a component with server.js that sets custom headers' , function ( ) {
422
-
423
422
var code , response , headers ;
424
423
425
424
before ( function ( done ) {
@@ -466,4 +465,104 @@ describe('registry : routes : component', function(){
466
465
} ) ;
467
466
} ) ;
468
467
468
+ describe ( 'when getting a simple component with server.js after headers component no custom headers should be set' , function ( ) {
469
+ var code = { } ,
470
+ response = { } ,
471
+ headers = { } ;
472
+
473
+ before ( function ( done ) {
474
+ var headersComponent = mockedComponents [ 'another-response-headers-component' ] ;
475
+ var simpleComponent = mockedComponents [ 'simple-component' ] ;
476
+
477
+ mockedRepository = {
478
+ getCompiledView : sinon . stub ( ) ,
479
+ getComponent : sinon . stub ( ) ,
480
+ getDataProvider : sinon . stub ( ) ,
481
+ getStaticFilePath : sinon . stub ( ) . returns ( '//my-cdn.com/files/' )
482
+ } ;
483
+
484
+ //Custom repository initialization to give us two components when invoked twice...
485
+ //...the firts one with custom headers and the second - without.
486
+ mockedRepository . getCompiledView . onCall ( 0 ) . yields ( null , headersComponent . view ) ;
487
+ mockedRepository . getCompiledView . onCall ( 1 ) . yields ( null , simpleComponent . view ) ;
488
+
489
+ mockedRepository . getComponent . onCall ( 0 ) . yields ( null , headersComponent . package ) ;
490
+ mockedRepository . getComponent . onCall ( 1 ) . yields ( null , simpleComponent . package ) ;
491
+
492
+ mockedRepository . getDataProvider . onCall ( 0 ) . yields ( null , headersComponent . data ) ;
493
+ mockedRepository . getDataProvider . onCall ( 1 ) . yields ( null , simpleComponent . data ) ;
494
+
495
+ componentRoute = new ComponentRoute ( { } , mockedRepository ) ;
496
+ resJsonStub = sinon . stub ( ) ;
497
+
498
+ var resJson = function ( index , callback ) {
499
+ return function ( calledCode , calledResponse ) {
500
+ code [ index ] = calledCode ;
501
+ response [ index ] = calledResponse ;
502
+ callback && callback ( ) ;
503
+ } ;
504
+ } ;
505
+
506
+ var resSet = function ( index ) {
507
+ return function ( calledHeaders ) {
508
+ headers [ index ] = calledHeaders ;
509
+ } ;
510
+ } ;
511
+
512
+ var requestComponent = function ( componentName , resultIndex ) {
513
+ return new Promise ( function ( resolve , reject ) {
514
+ componentRoute ( {
515
+ headers : { } ,
516
+ params : { componentName : componentName , componentVersion : '1.X.X' }
517
+ } , {
518
+ conf : {
519
+ baseUrl : 'http://component.com/' ,
520
+ executionTimeout : 0.1
521
+ } ,
522
+ json : resJson ( resultIndex , function ( ) { resolve ( ) ; } ) ,
523
+ set : resSet ( resultIndex )
524
+ } ) ;
525
+ } ) ;
526
+ } ;
527
+
528
+ requestComponent ( 'another-response-headers-component' , 0 )
529
+ . then ( requestComponent ( 'simple-component' , 1 ) )
530
+ . then ( function ( ) { done ( ) ; } ) ;
531
+ } ) ;
532
+
533
+ //The first part of the test - checking that another-response-headers-component
534
+ //should return a response with custom headers
535
+ it ( 'should return 200 status code for the first component' , function ( ) {
536
+ expect ( code [ 0 ] ) . to . be . equal ( 200 ) ;
537
+ } ) ;
538
+
539
+ it ( 'should return "response-headers-component" name for the first component\'s name and request version' , function ( ) {
540
+ expect ( response [ 0 ] . name ) . to . equal ( 'another-response-headers-component' ) ;
541
+ expect ( response [ 0 ] . requestVersion ) . to . equal ( '1.X.X' ) ;
542
+ } ) ;
543
+
544
+ it ( 'should set response headers for the first component' , function ( ) {
545
+ expect ( response [ 0 ] . headers ) . to . not . be . null ;
546
+ expect ( response [ 0 ] . headers [ 'another-test-header' ] ) . to . equal ( 'another-test-value' ) ;
547
+ expect ( headers [ 0 ] ) . to . not . be . null ;
548
+ expect ( headers [ 0 ] [ 'another-test-header' ] ) . to . equal ( 'another-test-value' ) ;
549
+ } ) ;
550
+
551
+ //The second part of the test - validating that simple-component should not return
552
+ //the custom headers previously set by another-headers-component.
553
+ it ( 'should return 200 status code for the first component' , function ( ) {
554
+ expect ( code [ 1 ] ) . to . be . equal ( 200 ) ;
555
+ } ) ;
556
+
557
+ it ( 'should return "simple-component" name for the first component\'s name and request version' , function ( ) {
558
+ expect ( response [ 1 ] . name ) . to . equal ( 'simple-component' ) ;
559
+ expect ( response [ 1 ] . requestVersion ) . to . equal ( '1.X.X' ) ;
560
+ } ) ;
561
+
562
+ it ( 'should not set custom response' , function ( ) {
563
+ expect ( response [ 1 ] . headers ) . to . be . undefined ;
564
+ expect ( headers [ 1 ] ) . to . be . undefined ;
565
+ } ) ;
566
+ } ) ;
567
+
469
568
} ) ;
0 commit comments