Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value matching does not work in arrays #1532

Open
SunriseOYR opened this issue Apr 11, 2022 · 7 comments
Open

Value matching does not work in arrays #1532

SunriseOYR opened this issue Apr 11, 2022 · 7 comments
Labels
question Indicates that an issue, pull request, or discussion needs more information

Comments

@SunriseOYR
Copy link

SunriseOYR commented Apr 11, 2022

versions

pact-jvm-consumer-junit:4.0.10
pact-jvm-consumer-java8:4.0.10
pact-jvm-provider-gradle:4.0.10

DslPart

DslPart body = newJsonArrayMinLike(1,(dto)->{
            dto.eachLike((item)->{
                item.stringValue("marketCode", "RU");
            }).build();
        }).build();

json

{
  "provider": {
    "name": "Rule"
  },
  "consumer": {
    "name": "RUThirdOrder"
  },
  "interactions": [
    {
      "description": "RU Third Order",
      "request": {
        "method": "GET",
        "path": "/orderDatas",
        "query": {
          "pact_jvm_orderIds": [
            "RCFFR000009302"
          ]
        }
      },
      "response": {
        "status": 200,
        "headers": {
          "Content-Type": "application/json"
        },
        "body": [
          [
            {
              "marketCode": "RU"
            }
          ]
        ],
        "matchingRules": {
          "body": {
            "$": {
              "matchers": [
                {
                  "match": "type",
                  "min": 1
                }
              ],
              "combine": "AND"
            },
            "$[*]": {
              "matchers": [
                {
                  "match": "type",
                  "min": 0
                }
              ],
              "combine": "AND"
            }
          }
        }
      },
      "providerStates": [
        {
          "name": ""
        }
      ]
    }
  ],
  "metadata": {
    "pactSpecification": {
      "version": "3.0.0"
    },
    "pact-jvm": {
      "version": "4.0.10"
    }
  }
}

But now, as long as marketCode is a string, validation will be successful, I tested stringType and stringMatcher and they work fine, while stringValue and numberValue don't work

@mefellows
Copy link
Member

Well with the example you have provided that is expected behaviour. Could you please share an example of what you expect that's not working?

Are you saying that you want to match exact values?

@SunriseOYR
Copy link
Author

Well with the example you have provided that is expected behaviour. Could you please share an example of what you expect that's not working?

Are you saying that you want to match exact values?

Yes, I want to match exact values, The match is only successful when marketCode = RU

@kevinmavely
Copy link

Any update on this, I found the same issue and I am using version 4.4.3. The "stringValue" field is not being checked on the value, just on the type.

Does eachLike support checking the value when defined in the example?

  return new PactDslJsonBody()
       .eachLike("fruits")
       .stringType("id", "example-id")
       .stringType("name", "example-name")
       .stringType("description", "test description")
       .stringValue("type", "gala")
       .stringType("color", "test-color")
       .stringType("grade", "test-grade")
       .closeArray();
 }

@rholshausen
Copy link
Contributor

@kevinmavely eachLike sets up type matching on all the fields

@sergtk
Copy link

sergtk commented Apr 27, 2024

I had also issue with newJsonArrayMinLike. This is when min=0.
Probably they are related: pact-foundation/pact-specification#108

@rholshausen
Copy link
Contributor

As per the previous comment, the eachLike set of functions setup type matching on all fields. If you want to override it with a particular value, use equalTo instead of stringValue.

@rholshausen rholshausen added the question Indicates that an issue, pull request, or discussion needs more information label May 3, 2024
@sergtk
Copy link

sergtk commented May 3, 2024

I just want to make test failed, when array contain invalid element, but tests still passes.

If I call newJsonArrayMinLike(1, ...), everything works as expected. But in some cases newJsonArrayMinLike(0, ...) is needed, and this result in passing tests on invalid response bodies.

(Not sure if this this is the same issue as the thread started with)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Indicates that an issue, pull request, or discussion needs more information
Projects
None yet
Development

No branches or pull requests

5 participants