2
2
3
3
const expect = require ( 'chai' ) . expect ;
4
4
const path = require ( 'path' ) ;
5
- const { Pact } = require ( '@pact-foundation/pact' ) ;
5
+ const { Pact, Matchers } = require ( '@pact-foundation/pact' ) ;
6
6
const { getMeDogs, getMeDog } = require ( '../index' ) ;
7
7
const LOG_LEVEL = process . env . LOG_LEVEL || 'TRACE' ;
8
8
@@ -14,10 +14,9 @@ describe('The Dog API', () => {
14
14
port : port ,
15
15
log : path . resolve ( process . cwd ( ) , 'logs' , 'mockserver-integration.log' ) ,
16
16
dir : path . resolve ( process . cwd ( ) , 'pacts' ) ,
17
- spec : 2 ,
17
+ spec : 3 ,
18
18
consumer : 'MyConsumer' ,
19
19
provider : 'MyProvider' ,
20
- pactfileWriteMode : 'merge' ,
21
20
logLevel : LOG_LEVEL ,
22
21
} ) ;
23
22
@@ -40,76 +39,45 @@ describe('The Dog API', () => {
40
39
afterEach ( ( ) => provider . verify ( ) ) ;
41
40
42
41
describe ( 'get /dogs' , ( ) => {
43
- before ( ( done ) => {
42
+ before ( ( ) => {
44
43
const interaction = {
45
44
state : 'i have a list of dogs' ,
46
45
uponReceiving : 'a request for all dogs' ,
47
46
withRequest : {
48
47
method : 'GET' ,
49
48
path : '/dogs' ,
50
49
headers : {
51
- Accept : 'application/json' ,
50
+ Accept :
51
+ 'application/problem+json, application/json, text/plain, */*' ,
52
+ // Accept: [
53
+ // 'application/problem+json',
54
+ // 'application/json',
55
+ // 'text/plain',
56
+ // '*/*',
57
+ // ],
52
58
} ,
53
59
} ,
54
60
willRespondWith : {
55
61
status : 200 ,
56
62
headers : {
57
- 'Content-Type' : 'application/json' ,
63
+ 'Content-Type' : Matchers . term ( {
64
+ generate : 'application/json' ,
65
+ matcher : 'application/json.*' ,
66
+ } ) ,
58
67
} ,
59
68
body : EXPECTED_BODY ,
60
69
} ,
61
70
} ;
62
- provider . addInteraction ( interaction ) . then ( ( ) => {
63
- done ( ) ;
64
- } ) ;
71
+ return provider . addInteraction ( interaction ) ;
65
72
} ) ;
66
73
67
- it ( 'returns the correct response' , ( done ) => {
74
+ it ( 'returns the correct response' , async ( ) => {
68
75
const urlAndPort = {
69
76
url : url ,
70
77
port : port ,
71
78
} ;
72
- getMeDogs ( urlAndPort ) . then ( ( response ) => {
73
- expect ( response . data ) . to . eql ( EXPECTED_BODY ) ;
74
- done ( ) ;
75
- } , done ) ;
76
- } ) ;
77
- } ) ;
78
-
79
- describe ( 'get /dog/1' , ( ) => {
80
- before ( ( done ) => {
81
- const interaction = {
82
- state : 'i have a list of dogs' ,
83
- uponReceiving : 'a request for a single dog' ,
84
- withRequest : {
85
- method : 'GET' ,
86
- path : '/dogs/1' ,
87
- headers : {
88
- Accept : 'application/json' ,
89
- } ,
90
- } ,
91
- willRespondWith : {
92
- status : 200 ,
93
- headers : {
94
- 'Content-Type' : 'application/json' ,
95
- } ,
96
- body : EXPECTED_BODY ,
97
- } ,
98
- } ;
99
- provider . addInteraction ( interaction ) . then ( ( ) => {
100
- done ( ) ;
101
- } ) ;
102
- } ) ;
103
-
104
- it ( 'returns the correct response' , ( done ) => {
105
- const urlAndPort = {
106
- url : url ,
107
- port : port ,
108
- } ;
109
- getMeDog ( urlAndPort ) . then ( ( response ) => {
110
- expect ( response . data ) . to . eql ( EXPECTED_BODY ) ;
111
- done ( ) ;
112
- } , done ) ;
79
+ const response = await getMeDogs ( urlAndPort ) ;
80
+ expect ( response . data ) . to . eql ( EXPECTED_BODY ) ;
113
81
} ) ;
114
82
} ) ;
115
83
} ) ;
0 commit comments