@@ -31,12 +31,12 @@ describe('MockService', () => {
3131
3232 it ( 'does not create a MockService when consumer is not informed' , ( ) => {
3333 expect ( ( ) => { new MockService ( ) } )
34- . to . throw ( Error , 'Please provide the names of the provider and consumer for this Pact.' )
34+ . not . to . throw ( Error )
3535 } )
3636
3737 it ( 'does not create a MockService when provider is not informed' , ( ) => {
3838 expect ( ( ) => { new MockService ( 'consumer' ) } )
39- . to . throw ( Error , 'Please provide the names of the provider and consumer for this Pact.' )
39+ . not . to . throw ( Error )
4040 } )
4141 } )
4242
@@ -48,13 +48,12 @@ describe('MockService', () => {
4848
4949 it ( 'when Interaction added successfully' , ( done ) => {
5050 nock ( mock . _baseURL ) . post ( / i n t e r a c t i o n s $ / ) . reply ( 200 )
51- expect ( mock . addInteraction ( interaction ) ) . to . eventually . notify ( done )
51+ expect ( mock . addInteraction ( interaction ) ) . to . eventually . be . fulfilled . notify ( done )
5252 } )
5353
5454 it ( 'when Interaction fails to be added' , ( done ) => {
5555 nock ( mock . _baseURL ) . post ( / i n t e r a c t i o n s $ / ) . reply ( 500 )
56- expect ( mock . addInteraction ( interaction ) ) . to . eventually . be . rejected
57- done ( )
56+ expect ( mock . addInteraction ( interaction ) ) . to . eventually . be . rejected . notify ( done )
5857 } )
5958 } )
6059
@@ -63,13 +62,12 @@ describe('MockService', () => {
6362
6463 it ( 'when interactions are removed successfully' , ( done ) => {
6564 nock ( mock . _baseURL ) . delete ( / i n t e r a c t i o n s $ / ) . reply ( 200 )
66- expect ( mock . removeInteractions ( ) ) . to . eventually . notify ( done )
65+ expect ( mock . removeInteractions ( ) ) . to . eventually . be . fulfilled . notify ( done )
6766 } )
6867
6968 it ( 'when interactions fail to be removed' , ( done ) => {
7069 nock ( mock . _baseURL ) . delete ( / i n t e r a c t i o n s $ / ) . reply ( 500 )
71- expect ( mock . removeInteractions ( ) ) . to . eventually . be . rejected
72- done ( )
70+ expect ( mock . removeInteractions ( ) ) . to . eventually . be . rejected . notify ( done )
7371 } )
7472 } )
7573
@@ -78,29 +76,51 @@ describe('MockService', () => {
7876
7977 it ( 'when verification is successful' , ( done ) => {
8078 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 )
81- expect ( mock . verify ( ) ) . to . eventually . notify ( done )
79+ expect ( mock . verify ( ) ) . to . eventually . be . fulfilled . notify ( done )
8280 } )
8381
8482 it ( 'when verification fails' , ( done ) => {
8583 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 )
86- expect ( mock . verify ( ) ) . to . eventually . be . rejected
87- done ( )
84+ expect ( mock . verify ( ) ) . to . eventually . be . rejected . notify ( done )
8885 } )
8986 } )
9087
9188 describe ( '#writePact' , ( ) => {
92- const mock = new MockService ( 'consumer' , 'provider' , 1234 )
93-
94- it ( 'when writing is successful' , ( done ) => {
95- nock ( mock . _baseURL ) . post ( / p a c t $ / ) . reply ( 200 )
96- expect ( mock . writePact ( ) ) . to . eventually . notify ( done )
89+ describe ( 'when consumer and provider details provided' , ( ) => {
90+ const mock = new MockService ( 'aconsumer' , 'aprovider' , 1234 )
91+
92+ describe ( 'and writing is successful' , ( ) => {
93+ it ( 'should write the consumer and provider details into the pact' , ( done ) => {
94+ nock ( mock . _baseURL )
95+ . post ( / p a c t $ / , {
96+ pactfile_write_mode : 'overwrite' ,
97+ consumer : { name : 'aconsumer' } ,
98+ provider : { name : 'aprovider' }
99+ } )
100+ . reply ( 200 )
101+ expect ( mock . writePact ( ) ) . to . eventually . be . fulfilled . notify ( done )
102+ } )
103+ } )
104+
105+ describe ( 'and writing fails' , ( ) => {
106+ it ( 'should return a rejected promise' , ( done ) => {
107+ nock ( mock . _baseURL )
108+ . post ( / p a c t $ / ) . reply ( 500 )
109+ expect ( mock . writePact ( ) ) . to . eventually . be . rejected . notify ( done )
110+ } )
111+ } )
97112 } )
98-
99- it ( 'when writing fails' , ( done ) => {
100- nock ( mock . _baseURL ) . post ( / p a c t $ / ) . reply ( 500 )
101- expect ( mock . writePact ( ) ) . to . eventually . be . rejected
102- done ( )
113+ describe ( 'when consumer and provider details are not provided' , ( ) => {
114+ const mock = new MockService ( null , null , 1234 )
115+ it ( 'should not write the consumer and provider details into the pact' , ( done ) => {
116+ nock ( mock . _baseURL )
117+ . post ( / p a c t $ / , {
118+ pactfile_write_mode : 'overwrite' ,
119+ consumer : undefined ,
120+ provider : undefined
121+ } ) . reply ( 200 )
122+ expect ( mock . writePact ( ) ) . to . eventually . be . fulfilled . notify ( done )
123+ } )
103124 } )
104125 } )
105-
106126} )
0 commit comments