Skip to content

Commit

Permalink
fix: support multiple states with same name
Browse files Browse the repository at this point in the history
Allows different parameters for the same state name

Fixes #848
  • Loading branch information
mefellows committed Jan 19, 2024
1 parent 03abf8a commit 78d7e32
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
]
},
"dependencies": {
"@pact-foundation/pact-core": "^14.0.1",
"@pact-foundation/pact-core": "^14.1.0",
"@types/express": "^4.17.11",
"axios": "^1.6.1",
"body-parser": "^1.20.0",
Expand Down
4 changes: 1 addition & 3 deletions src/messageConsumerPact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ export class MessageConsumerPact {
if (typeof state === 'string') {
this.message.given(state);
} else {
forEachObjIndexed((v, k) => {
this.message.givenWithParam(state.name, `${k}`, JSON.stringify(v));
}, state.params);
this.message.givenWithParams(state.name, JSON.stringify(state.params));
}

return this;
Expand Down
12 changes: 4 additions & 8 deletions src/v3/pact.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { forEachObjIndexed, equals } from 'ramda';
import {
makeConsumerPact,
ConsumerPact,
Expand Down Expand Up @@ -97,13 +96,10 @@ export class PactV3 {
this.interaction = this.pact.newInteraction(description);
this.states.forEach((s) => {
if (s.parameters) {
forEachObjIndexed((v, k) => {
this.interaction.givenWithParam(
s.description,
`${k}`,
JSON.stringify(v)
);
}, s.parameters);
this.interaction.givenWithParams(
s.description,
JSON.stringify(s.parameters)
);
} else {
this.interaction.given(s.description);
}
Expand Down
4 changes: 1 addition & 3 deletions src/v4/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export class UnconfiguredInteraction implements V4UnconfiguredInteraction {

given(state: string, parameters?: JsonMap): V4UnconfiguredInteraction {
if (parameters) {
forEachObjIndexed((v, k) => {
this.interaction.givenWithParam(state, `${k}`, JSON.stringify(v));
}, parameters);
this.interaction.givenWithParams(state, JSON.stringify(parameters));
} else {
this.interaction.given(state);
}
Expand Down
4 changes: 1 addition & 3 deletions src/v4/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export class UnconfiguredSynchronousMessage

given(state: string, parameters?: JsonMap): V4UnconfiguredSynchronousMessage {
if (parameters) {
forEachObjIndexed((v, k) => {
this.interaction.givenWithParam(state, `${k}`, JSON.stringify(v));
}, parameters);
this.interaction.givenWithParams(state, JSON.stringify(parameters));
} else {
this.interaction.given(state);
}
Expand Down

0 comments on commit 78d7e32

Please sign in to comment.