@@ -32,12 +32,12 @@ describe('MockService', () => {
3232
3333 it ( 'does not create a MockService when consumer is not informed' , ( ) => {
3434 expect ( ( ) => { new MockService ( '' , 'provider' ) } )
35- . to . throw ( Error , 'Please provide the names of the provider and consumer for this Pact.' )
35+ . not . to . throw ( Error ) ;
3636 } )
3737
3838 it ( 'does not create a MockService when provider is not informed' , ( ) => {
3939 expect ( ( ) => { new MockService ( 'consumer' , '' ) } )
40- . to . throw ( Error , 'Please provide the names of the provider and consumer for this Pact.' )
40+ . not . to . throw ( Error ) ;
4141 } )
4242 } )
4343
@@ -64,13 +64,12 @@ describe('MockService', () => {
6464
6565 it ( 'when interactions are removed successfully' , ( done ) => {
6666 nock ( mock . baseUrl ) . delete ( / i n t e r a c t i o n s $ / ) . reply ( 200 )
67- expect ( mock . removeInteractions ( ) ) . to . eventually . notify ( done )
67+ expect ( mock . removeInteractions ( ) ) . to . eventually . be . fulfilled . notify ( done )
6868 } )
6969
7070 it ( 'when interactions fail to be removed' , ( done ) => {
7171 nock ( mock . baseUrl ) . delete ( / i n t e r a c t i o n s $ / ) . reply ( 500 )
72- expect ( mock . removeInteractions ( ) ) . to . eventually . be . rejected
73- done ( )
72+ expect ( mock . removeInteractions ( ) ) . to . eventually . be . rejected . notify ( done )
7473 } )
7574 } )
7675
@@ -79,29 +78,51 @@ describe('MockService', () => {
7978
8079 it ( 'when verification is successful' , ( done ) => {
8180 nock ( mock . baseUrl ) . get ( / i n t e r a c t i o n s \/ v e r i f i c a t i o n $ / ) . reply ( 200 )
82- expect ( mock . verify ( ) ) . to . eventually . notify ( done )
81+ expect ( mock . verify ( ) ) . to . eventually . be . fulfilled . notify ( done )
8382 } )
8483
8584 it ( 'when verification fails' , ( done ) => {
8685 nock ( mock . baseUrl ) . get ( / i n t e r a c t i o n s \/ v e r i f i c a t i o n $ / ) . reply ( 500 )
87- expect ( mock . verify ( ) ) . to . eventually . be . rejected
88- done ( )
86+ expect ( mock . verify ( ) ) . to . eventually . be . rejected . notify ( done )
8987 } )
9088 } )
9189
9290 describe ( '#writePact' , ( ) => {
93- const mock = new MockService ( 'consumer' , 'provider' , 1234 )
94-
95- it ( 'when writing is successful' , ( done ) => {
96- nock ( mock . baseUrl ) . post ( / p a c t $ / ) . reply ( 200 )
97- expect ( mock . writePact ( ) ) . to . eventually . notify ( done )
91+ describe ( 'when consumer and provider details provided' , ( ) => {
92+ const mock = new MockService ( 'aconsumer' , 'aprovider' , 1234 )
93+
94+ describe ( 'and writing is successful' , ( ) => {
95+ it ( 'should write the consumer and provider details into the pact' , ( done ) => {
96+ nock ( mock . baseUrl )
97+ . post ( / p a c t $ / , {
98+ pactfile_write_mode : 'overwrite' ,
99+ consumer : { name : 'aconsumer' } ,
100+ provider : { name : 'aprovider' }
101+ } )
102+ . reply ( 200 )
103+ expect ( mock . writePact ( ) ) . to . eventually . be . fulfilled . notify ( done )
104+ } )
105+ } )
106+
107+ describe ( 'and writing fails' , ( ) => {
108+ it ( 'should return a rejected promise' , ( done ) => {
109+ nock ( mock . baseUrl )
110+ . post ( / p a c t $ / ) . reply ( 500 )
111+ expect ( mock . writePact ( ) ) . to . eventually . be . rejected . notify ( done )
112+ } )
113+ } )
98114 } )
99-
100- it ( 'when writing fails' , ( done ) => {
101- nock ( mock . baseUrl ) . post ( / p a c t $ / ) . reply ( 500 )
102- expect ( mock . writePact ( ) ) . to . eventually . be . rejected
103- done ( )
115+ describe ( 'when consumer and provider details are not provided' , ( ) => {
116+ const mock = new MockService ( undefined , undefined , 1234 )
117+ it ( 'should not write the consumer and provider details into the pact' , ( done ) => {
118+ nock ( mock . baseUrl )
119+ . post ( / p a c t $ / , {
120+ pactfile_write_mode : 'overwrite' ,
121+ consumer : undefined ,
122+ provider : undefined
123+ } ) . reply ( 200 )
124+ expect ( mock . writePact ( ) ) . to . eventually . be . fulfilled . notify ( done )
125+ } )
104126 } )
105127 } )
106-
107128} )
0 commit comments