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

[Question] Allow to match array content only by type #1834

Open
huehnerlady opened this issue Oct 22, 2024 · 1 comment
Open

[Question] Allow to match array content only by type #1834

huehnerlady opened this issue Oct 22, 2024 · 1 comment

Comments

@huehnerlady
Copy link
Contributor

huehnerlady commented Oct 22, 2024

I created this project to show my problem a bit more interactive.
I have an endpoint that returns a object containing a list of objects. I do not want to compare the actual values of my pact, I just want to match the type.

My Pact looks like this:

  @Pact(consumer = "Consumer", provider = "Provider")
  fun multi(builder: PactBuilder): V4Pact {
    return builder
        .expectsToReceiveHttpInteraction("multi") { httpBuilder ->
          httpBuilder
              .withRequest { httpRequestBuilder ->
                httpRequestBuilder
                    .path("/multi")
                    .method("GET")
              }
              .willRespondWith { httpResponseBuilder ->
                httpResponseBuilder
                    .status(200)
                    .body(PactDslJsonBody()
                        .`object`("myData", PactDslJsonBody()
                            .eachLike("myData", 2)
                            .stringType("foo", "foo")
                            .`object`("bar", PactDslJsonBody()
                                .stringType("bar", "bar")
                            )
                        )
                    )
              }
        }
        .toPact()

Unfortunately it actually matches not only the size of the example list, but also the value of the fields.
Both of which is not wanted.
As the single return works fine I assume it has something to do with the .eachLike("myData", 2).
Any idea what I am doing wrong and how I can change it to get my desired outcome?

I already tried to ask in the Pact Slack workspace and Stackoverflow, but as there is no answer about what I should do differently, I assume it is a bug in the system.

Expected behaviour

  • generates test data: {"myData:[{"foo":"foo", "bar":"bar"}, {"foo":"foo", "bar":"bar"}]}
  • generates a pact that matches any size and any items for having a string field 'foo' and a string fiels 'bar'

Actual behaviour

  • generates test data: {"myData:[{"foo":"foo", "bar":"bar"}, {"foo":"foo", "bar":"bar"}]} ✔️
  • generates a pact that matches against {"myData:[{"foo":"foo", "bar":"bar"}, {"foo":"foo", "bar":"bar"}]}
    This behaviour I would expect when using stringValue
@huehnerlady huehnerlady changed the title Allow to match array with types only Allow to match array content only by type Oct 22, 2024
@huehnerlady huehnerlady changed the title Allow to match array content only by type [BUG] Allow to match array content only by type Oct 22, 2024
@huehnerlady
Copy link
Contributor Author

I got a step further with the LambdaDsl

I also found the kotlin lambda dsl in the documentation.

But when I try to use that in my case, I am running into the issue, that the example data is not filled anymore:

expected: <MultipleData(myData=[MyData(foo=foo, bar=Bar(bar=bar)), MyData(foo=foo, bar=Bar(bar=bar))])> 
but was: <MultipleData(myData=[MyData(foo=null, bar=null), MyData(foo=null, bar=null)])>

Any idea what I am doing wrong?

@huehnerlady huehnerlady changed the title [BUG] Allow to match array content only by type [Question] Allow to match array content only by type Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant