pact-foundation / pact-stub-server

Standalone pact stub server
MIT License
75 stars 19 forks source link

Does not match timestamp pattern in request body #35

Closed tsayen closed 3 years ago

tsayen commented 4 years ago

Hi, first of all, thank you for the great work you do. I'm using this server to stub an external service during tests. I use PactJVM to generate the pacts. In request specification, I have a parameter of type timestamp:

pactDsl
  .uponReceiving(...)
  ...
  .body(newJsonBody(body -> body
    .timestamp("date", "YYYY-MM-dd'T'HH:mm:ss.SSSZZ")

The request is matched during consumer test with value 2018-12-08T12:05:00.000+01:00, and the relevant part of the pact looks like that:

"$.date": {
              "matchers": [
                {
                  "match": "timestamp",
                  "timestamp": "YYYY-MM-dd'T'HH:mm:ss.SSSZZ"
                }
              ],
              "combine": "AND"
           },

But, when I launch standalone server with this pact and send a request with the same date, the request is not matched, and here is what I get in the server logs:

[DEBUG] (5) pact_matching: --> Mismatches: ... mismatch: "Expected \'\"2018-12-08T12:05:00.000+01:00\"\' to match a timestamp format of \'YYYY-MM-dd\'T\'HH:mm:ss.SSSZZ\': Error(Code(CompleteStr(\":00\"), TakeWhileMN))" }]
uglyog commented 4 years ago

I've totally overhauled the date-time matching in both Pact-JVM and Pact-Rust to use the format from Java DateTimeFormatter. You'll need to upgrade to Pact-JVM version 4.1.1 and use the format YYYY-MM-dd'T'HH:mm:ss.SSSXXX. The version 0.4.1 of the stub server will work.