https://pact.io logo
#pact-js
Title
# pact-js
f

Francislainy Campos

02/10/2022, 8:37 PM
Hi, I have this contract done in Javascript:
Copy code
{
  "consumer": {
    "name": "Ed UI"
  },
  "provider": {
    "name": "Viaduct"
  },
  "interactions": [
    {
      "description": "A POST request to encode a JSON body of claims from the user",
      "providerState": "viaductService encodes a JSON body of claims and returns a JWT string in response",
      "request": {
        "method": "POST",
        "path": "/edcore/viaduct-service/jwt",
        "body": {
          "resourceId": "l_fc3ae9ed-62ac-4b94-8094-8dd29bc208a7_c57760a9-447b-42aa-81df-830134425157",
          "teacherAssessmentId": "93a91981-c6f7-435f-ab1e-80588ecff2ee",
          "expiryUnixEpochSeconds": 26757854170066,
          "sub": "UniqueUserId"
        }
      },
      "response": {
        "status": 200,
        "body": "eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla",
        "matchingRules": {
          "$.body": {
            "match": "type"
          }
        }
      }
    },
  ],
  "metadata": {
    "pactSpecification": {
      "version": "2.0.0"
    }
  }
}
However, our provider tests (Java) fail with
Expected body 'eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla' to match 'eyJhbGciOiJIUzI1NiJ9.eyJzd.bla' using equality but did not match
. Not sure where the issue could be coming from. Initially I thought it might be related to the headers blocking the matchers as per https://stackoverflow.com/a/61924547/6654475, but even manually deleting the headers from the contract still give us the same issue, so maybe version related perhaps?
<pact.version>4.3.2</pact.version>
Thank you. CC @uglyog
u

uglyog

02/10/2022, 9:54 PM
Can you raise an issue for this, it looks like a bug
Oh, I think the issue is the response is missing a content type header
So it is treating it as text, and not using the type matcher
f

Francislainy Campos

02/11/2022, 5:04 AM
Sorry, I have this but still:
Copy code
"request": {
  "method": "POST",
  "path": "/edcore/viaduct-service/jwt",
  "headers": {
    "Content-Type": "application/json",
    "accept": "application/json"
  },
  "body": {
    "resourceId": "l_fc3ae9ed-62ac-4b94-8094-8dd29bc208a7_c57760a9-447b-42aa-81df-830134425157",
    "teacherAssessmentId": "93a91981-c6f7-435f-ab1e-80588ecff2ee",
    "expiryUnixEpochSeconds": 26757854170066,
    "sub": "UniqueUserId"
  }
},
"response": {
  "status": 200,
  "headers": {
    "Content-Type": "application/json"
  },
  "body": "eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJWaWFkdWN0U2Vydm.blabla",
  "matchingRules": {
    "$.body": {
      "match": "type"
    }
  }
}
u

uglyog

02/11/2022, 5:05 AM
Let me see if I can reproduce it
Works fine for me. I can see
Copy code
16:33:29.216 [DEBUG] [au.com.dius.pact.core.matchers.JsonBodyMatcher] compareValues: Matcher defined for path [$]
16:33:29.216 [DEBUG] [au.com.dius.pact.core.matchers.MatcherExecutor] comparing type of "eyJhbGciOiJIUzI1NiJ9.eyJzd.bla" to "eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla" at [$]
That is with version 4.1.34, let me try 4.3.x
👍 1
4.3.5 works fine for me. I can't reproduce this. I did have to change the response to
Copy code
"body": "\"eyJhbGciOiJIUzI1NiJ9.eyJU2VydmljZ.blabla\"",
But I did not get your error. Can you confirm the version of Pact-JVM?
f

Francislainy Campos

02/11/2022, 6:20 AM
Copy code
<pact.version>4.3.2</pact.version>
message has been deleted
We may try to change the backend to return a json with the {} , but I think we may have got into a limitation for pact here, so it may be interesting to know if that’s really the case.
2 Views