File tree 2 files changed +76
-2
lines changed
2 files changed +76
-2
lines changed Original file line number Diff line number Diff line change 1
1
const fs = require ( 'fs' ) ;
2
2
const lc = require ( 'lightcookie' ) ;
3
-
3
+ const override = require ( 'deep-override' ) ;
4
4
const path = require ( 'path' ) ;
5
5
const Tosser = require ( './Tosser' ) ;
6
6
const Expect = require ( './expect' ) ;
@@ -284,7 +284,8 @@ class Spec {
284
284
}
285
285
286
286
withCore ( options ) {
287
- this . _request . core = options ;
287
+ this . _request . core = this . _request . core || { } ;
288
+ override ( this . _request . core , options ) ;
288
289
return this ;
289
290
}
290
291
Original file line number Diff line number Diff line change @@ -604,6 +604,79 @@ describe('Mock', () => {
604
604
. expectStatus ( 200 ) ;
605
605
} ) ;
606
606
607
+ it ( 'GET - with core options & auth - override with auth' , async ( ) => {
608
+ await pactum . spec ( )
609
+ . useInteraction ( {
610
+ request : {
611
+ method : 'GET' ,
612
+ path : '/api/core' ,
613
+ headers : {
614
+ 'authorization' : 'Basic dXNlcjpwYXNz'
615
+ }
616
+ } ,
617
+ response : {
618
+ status : 200
619
+ }
620
+ } )
621
+ . get ( 'http://localhost:9393' )
622
+ . withCore ( {
623
+ path : '/api/core' ,
624
+ auth : 'user:invalid-pass'
625
+ } )
626
+ . withAuth ( 'user' , 'pass' )
627
+ . expectStatus ( 200 ) ;
628
+ } ) ;
629
+
630
+ it ( 'GET - with core options & auth - override with core' , async ( ) => {
631
+ await pactum . spec ( )
632
+ . useInteraction ( {
633
+ request : {
634
+ method : 'GET' ,
635
+ path : '/api/core' ,
636
+ headers : {
637
+ 'authorization' : 'Basic dXNlcjpwYXNz'
638
+ }
639
+ } ,
640
+ response : {
641
+ status : 200
642
+ }
643
+ } )
644
+ . get ( 'http://localhost:9393' )
645
+ . withAuth ( 'user' , 'invalid-pass' )
646
+ . withCore ( {
647
+ path : '/api/core' ,
648
+ auth : 'user:pass'
649
+ } )
650
+ . expectStatus ( 200 ) ;
651
+ } ) ;
652
+
653
+ it ( 'GET - with core options & auth - override with core invalid auth' , async ( ) => {
654
+ try {
655
+ await pactum . spec ( )
656
+ . useInteraction ( {
657
+ request : {
658
+ method : 'GET' ,
659
+ path : '/api/core' ,
660
+ headers : {
661
+ 'authorization' : 'Basic dXNlcjpwYXNz'
662
+ }
663
+ } ,
664
+ response : {
665
+ status : 200
666
+ }
667
+ } )
668
+ . get ( 'http://localhost:9393' )
669
+ . withAuth ( 'user' , 'pass' )
670
+ . withCore ( {
671
+ path : '/api/core' ,
672
+ auth : 'user:invalid-pass'
673
+ } )
674
+ } catch ( error ) {
675
+ err = error
676
+ }
677
+ expect ( err . message ) . contains ( 'Interaction not exercised: GET - /api/core' ) ;
678
+ } ) ;
679
+
607
680
it ( 'GET - with auth' , async ( ) => {
608
681
await pactum . spec ( )
609
682
. useInteraction ( {
You can’t perform that action at this time.
0 commit comments