From 36dfb4f70b383d1bd59476ea37f219f2c3679e04 Mon Sep 17 00:00:00 2001
From: mefellows <mefellows@users.noreply.github.com>
Date: Fri, 19 Jan 2024 13:41:32 +1100
Subject: [PATCH] fix: support multiple states with same name

Allows different parameters for the same state name

Fixes #848
---
 package-lock.json          | 14 +++++++-------
 package.json               |  2 +-
 src/messageConsumerPact.ts |  4 +---
 src/v3/pact.ts             | 13 +++++--------
 src/v4/http/index.ts       |  4 +---
 src/v4/message/index.ts    |  4 +---
 6 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 51e983f70..b1532855e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,7 +9,7 @@
       "version": "12.1.2",
       "license": "MIT",
       "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",
@@ -2015,9 +2015,9 @@
       }
     },
     "node_modules/@pact-foundation/pact-core": {
-      "version": "14.0.1",
-      "resolved": "https://registry.npmjs.org/@pact-foundation/pact-core/-/pact-core-14.0.1.tgz",
-      "integrity": "sha512-I/OAH9F0chVqGoer/RF/UrFYqjf8ssj8aQ7mLTc+ItfNDyV15XqH/8lam4EQgcgBSuN2gy8Y58Vs2/+ssFWhlw==",
+      "version": "14.1.0",
+      "resolved": "https://registry.npmjs.org/@pact-foundation/pact-core/-/pact-core-14.1.0.tgz",
+      "integrity": "sha512-C6SGuwVxESMlfu2tRM0zfiR0Rvz1D4P6pccnVZtcM4TrMXDVQ7LOI+fLmilsb+SgyzWSM4B+AfUKVB7Uqg+WDA==",
       "cpu": [
         "x64",
         "ia32",
@@ -12884,9 +12884,9 @@
       }
     },
     "@pact-foundation/pact-core": {
-      "version": "14.0.1",
-      "resolved": "https://registry.npmjs.org/@pact-foundation/pact-core/-/pact-core-14.0.1.tgz",
-      "integrity": "sha512-I/OAH9F0chVqGoer/RF/UrFYqjf8ssj8aQ7mLTc+ItfNDyV15XqH/8lam4EQgcgBSuN2gy8Y58Vs2/+ssFWhlw==",
+      "version": "14.1.0",
+      "resolved": "https://registry.npmjs.org/@pact-foundation/pact-core/-/pact-core-14.1.0.tgz",
+      "integrity": "sha512-C6SGuwVxESMlfu2tRM0zfiR0Rvz1D4P6pccnVZtcM4TrMXDVQ7LOI+fLmilsb+SgyzWSM4B+AfUKVB7Uqg+WDA==",
       "requires": {
         "chalk": "4.1.2",
         "check-types": "7.3.0",
diff --git a/package.json b/package.json
index 47a1ed158..ba11b1bdf 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/src/messageConsumerPact.ts b/src/messageConsumerPact.ts
index 7ef9cf2c1..0f3efad3f 100644
--- a/src/messageConsumerPact.ts
+++ b/src/messageConsumerPact.ts
@@ -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;
diff --git a/src/v3/pact.ts b/src/v3/pact.ts
index 9cdb9a23c..5956f468d 100644
--- a/src/v3/pact.ts
+++ b/src/v3/pact.ts
@@ -1,4 +1,4 @@
-import { forEachObjIndexed, equals } from 'ramda';
+import { equals } from 'ramda';
 import {
   makeConsumerPact,
   ConsumerPact,
@@ -97,13 +97,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);
       }
diff --git a/src/v4/http/index.ts b/src/v4/http/index.ts
index ccee60a0b..f62508015 100644
--- a/src/v4/http/index.ts
+++ b/src/v4/http/index.ts
@@ -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);
     }
diff --git a/src/v4/message/index.ts b/src/v4/message/index.ts
index 6ffbcc712..6d5666dca 100644
--- a/src/v4/message/index.ts
+++ b/src/v4/message/index.ts
@@ -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);
     }