Just wondering how the library handles camel case ...
# pact-jvm
f
Just wondering how the library handles camel case vs snake case, as I have a contract generated with snake case, but even though my api returns camel case, the tests still passed.
Copy code
"response": {
  "body": [
    {
      "19/08/2016": "29/10/2023",
      "card_number": "**** **** **** 1234",
      "client_id": "f0652d7b-1fb4-490d-9fbf-adc23c65b2df",
      "purchase_id": "e7cd8ac0-0df3-404f-b505-10ea2201f059",
      "value": 1234
    },
    {
      "19/08/2016": "29/10/2023",
      "card_number": "**** **** **** 1234",
      "client_id": "f0652d7b-1fb4-490d-9fbf-adc23c65b2df",
      "purchase_id": "e7cd8ac0-0df3-404f-b505-10ea2201f059",
      "value": 1234
    }
  ],
[ { “clientId”: “f0652d7b-1fb4-490d-9fbf-adc23c65b2df”, “purchaseId”: “f1598770-f7d0-43fc-ae47-62370e0aea03", “value”: 1234.00, “date”: “2023-10-29”, “cardNumber”: “1234-1234-1234” } ]
r
There must be something wrong with your test, or your API is automatically converting the attribute names.
f
This is the piece that generates this contract:
Copy code
@Pact(provider = PACT_PROVIDER, consumer = PACT_CONSUMER)
public RequestResponsePact createPact(PactDslWithProvider builder) {
    headers.put("Content-Type", "application/json");
    headers.put("Accept", "application/json");

    DslPart bodyReturned = PactDslJsonArray.arrayEachLike(2)
            .uuid("client_id", clientId)
            .uuid("purchase_id", randomUUID())
            .numberType("value", 1234)
            .date("19/08/2016", "dd/MM/YYYY", new Date())
            .stringType("card_number", "**** **** **** 1234")
            .close();

    return builder
            .given("A request to retrieve the history of transactions for a client")
            .uponReceiving("A request to retrieve the history of transactions for a client")
            .pathFromProviderState(path + "${clientId}", path + clientId)
            .method(String.valueOf(GET))
            .headers(headers)
            .willRespondWith()
            .body(bodyReturned)
            .status(200)
            .toPact();
}
The api is correct, as it returns the fields with camelcase, which is the default.
However, I was expecting Pact to fail since these are not the exact keys as specified in the contract, as there we use snake case.
r
Is this correct?
.date("19/08/2016", "dd/MM/YYYY", new Date())
The attribute key is
"19/08/2016"
and the value is the current date?
😮 1
As in, your JSON would look like:
Copy code
{
  "19/08/2016": "01/11/2023"
}
f
Wow, yes, that’s definitely wrong.
However, my tests still pass. 😂
Not sure what’s going here.
@Matt (pactflow.io / pact-js / pact-go) I think I’m getting a bit confused now. 🙂
Can you rescue me, please?
This is my project.
My api returns this:
But my contract keeps passing, even if I have camel case vs snake_case, date value instead of date key, completely wrong keys, such as if I spell centId instead of clientId..