Skip to content

Commit 3fe41df

Browse files
authored
Merge pull request #1592 from SUI-Components/fix-interactions-with-different-body
2 parents b1cf92f + f16f0af commit 3fe41df

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

packages/sui-test-contract/src/setup/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ export const writerFactory = providers => (path, data) => {
2525

2626
data.interactions = interactions.map(interaction => {
2727
const {request} = interaction
28-
const {path, query} = request
28+
const {path, query, body} = request
2929

3030
const definedInteraction = providers[name].find(
31-
({endpoint, query: definedQuery}) => {
31+
({endpoint, query: definedQuery, body: definedBody}) => {
3232
const matchedEndpoint = endpoint === path
3333

3434
if (query) {
3535
return matchedEndpoint && query === toQueryString(definedQuery)
3636
}
37+
if (body) {
38+
return matchedEndpoint && stringify(body) === stringify(definedBody)
39+
}
3740
return matchedEndpoint
3841
}
3942
)

packages/sui-test-contract/test/server/setupSpec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ setupContractTests({
7575
),
7676
body: galaAppleBody
7777
},
78+
{
79+
endpoint: '/apples/add/gala',
80+
description: 'A request for adding a Gala apple with a different color',
81+
state: "I've added a Gala apple with a different color",
82+
method: 'post',
83+
handler: rest.post(
84+
'http://localhost:8181/apples/add/:slug',
85+
(req, res, ctx) => res(ctx.status(200))
86+
),
87+
body: {color: 'yellow', type: 'Gala'}
88+
},
7889
{
7990
endpoint: '/apples/garden',
8091
description: 'A request for getting a garden',
@@ -167,6 +178,21 @@ describe('Contract files generated', () => {
167178
expect(response.matchingRules).to.not.exist
168179
})
169180

181+
it('should generate the contract when doing a request for adding a Gala apple with a different color', () => {
182+
const data = getContractFileData({
183+
consumer,
184+
description: 'A request for adding a Gala apple with a different color'
185+
})
186+
const {providerState, response, request} = data
187+
188+
expect(providerState).to.eql(
189+
"I've added a Gala apple with a different color"
190+
)
191+
expect(request.method).to.eql('POST')
192+
expect(request.body).to.eql({color: 'yellow', type: 'Gala'})
193+
expect(response.status).to.eql(200)
194+
})
195+
170196
it('should generate the contract when doing a not found request', () => {
171197
const data = getContractFileData({
172198
consumer,

0 commit comments

Comments
 (0)