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

queryMatchingDatetime creates invalid genetator #1612

Closed
BorealFeast opened this issue Sep 23, 2022 · 2 comments
Closed

queryMatchingDatetime creates invalid genetator #1612

BorealFeast opened this issue Sep 23, 2022 · 2 comments

Comments

@BorealFeast
Copy link

BorealFeast commented Sep 23, 2022

When using queryMatchingDatetime it creates a pact file that is invalid for the provider to use.

On the provider side, the error au.com.dius.pact.core.model.InvalidPathExpression: Path expression "startDateTime" does not start with a root marker "$" is being thrown.

Consumer is using au.com.dius.pact.consumer:junit5:4.3.14 and Provider is using au.com.dius.pact.provider:junit5spring:4.3.14.

//Consumer
@Pact(provider = "myProvider", consumer = "myConsumer")
    public V4Pact getRequest(PactBuilder builder) {
        return builder.usingLegacyDsl()
                      .uponReceiving("a request")
                      .path("/api/myrequest")
                      .method("POST")
                      .queryMatchingDatetime("startDateTime", "yyyy-MM-dd'T'hh:mm:ss'Z'")
                      .body(new PactDslJsonBody()
                                    .array("foo")
                                    .stringValue("bar"))
                      .willRespondWith()
                      .body(new PactDslJsonArray()
                                    .object()
                                    .stringType("foo", "bar")
                                    .closeObject()).status(200)
                      .toPact(V4Pact.class);    }

which generates a pact with the following request:

"request": {
        "body": {
          "content": {
            "foo": [
              "bar"
            ]
          },
          "contentType": "application/json; charset=UTF-8",
          "encoded": false
        },
        "generators": {
          "body": {
            "startDateTime": {
              "format": "yyyy-MM-dd'T'hh:mm:ss'Z'",
              "type": "DateTime"
            }
          },
{...}
        "matchingRules": {
          "query": {
            "startDateTime": {
              "combine": "AND",
              "matchers": [
                {
                  "match": "timestamp",
                  "timestamp": "yyyy-MM-dd'T'hh:mm:ss'Z'"
                }
              ]
            }
          }
        },
        "method": "POST",
        "path": "/api/myRequest",
        "query": {
          "startDateTime": [
            "2000-01-31T01:00:00Z"
          ]
        }

If I change request.generators.body to be named instead request.generators.query, it passes on the provider side (but same if I remove the whole generator block, so I don't know if that was a valid move.)

@rholshausen
Copy link
Contributor

Fix released with version 4.3.16

@BorealFeast
Copy link
Author

I confirm this is now working.

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

2 participants