could someone help me understand the expected beha...
# pact-js
m
could someone help me understand the expected behavior of
MatcherV3.timestamp
? in the documentation (V3 Matching Rules) it shows that
timestamp
can be used without a second argument representing an example. however, when I try using it without an example, it throws the error
you must provide an example timestamp
the code and documentation talk about "generators" - do I need to specify that somehow? (I'll post a code snippet in thread)
Copy code
const expectedResponse = {
  fully_updated: boolean(true),
  run_sets: eachLike([
    {
      submission_timestamp: timestamp("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"),
      last_modified_timestamp: timestamp("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"),
    },
  ], { min: 1 }),
};

await cbasPact.addInteraction({
  states: [{ description: 'at least one run set exists with method_id 00000000-0000-0000-0000-000000000009' }],
  uponReceiving: 'get run set with method_id=00000000-0000-0000-0000-000000000009 and page_size=1',
  withRequest: { method: 'GET', path: '/api/batch/v1/run_sets', query: { method_id: '00000000-0000-0000-0000-000000000009', page_size: 1 } },
  willRespondWith: { status: 200, body: expectedResponse },
});
y
Hey buddy, From the docs, and the doc string, it suggests that it should generate one as you expect https://github.com/pact-foundation/pact-js/blob/9bb0d10d609559493e8fb3b1c1fd952ca8f724b2/src/v3/matchers.ts#L344 however example is required to be set (it’s not optional in the function params) and it explicitly throws an error. The example tests in the repo, all show an example being provided. So there is either a discrepancy between the docs/comments and code, and not sure currently as to which is correct.
m
ok I see. the docs must be incorrect, because the language is very clear:
String value that must match the provided datetime format string. See Java SimpleDateFormat for details on the format string. If the example value is omitted, a value will be generated using a Timestamp generator and the current system date and time.
y
the docs, match up with the comment in the code. the code implementation differs, from both the comment in the code, and the documentation. the tests confirm the behaviour of the code, and contradict (or rather don’t test the case suggested in the docs, or code comment - that omitting the example value, will generate a new one)
My next port of call would be to check the git history to see when the code was last touched, and also check with the pact-reference implementation in rust to check the source behaviour, and confirm if pact-js matches that or not.
m
See also https://github.com/pact-foundation/pact-js/issues/1076, would you be up for a PR to help address it?
I think option (1) as described here would be ideal (probably supporting (3), which might just come for free with some documentation to make it clear it’s possible)
m
thanks for the context, it's helpful!
would you be up for a PR to help address it?
potentially - I don't want to commit just yet (I've solved my immediate problem with a regex), but if I do, I'll post again in this thread, find the contributor guidelines, and take it from there. I agree option (1) would be ideal
thankyou 1