https://pact.io logo
#pact-jvm
Title
# pact-jvm
o

Oscar Calderin

05/17/2022, 10:18 AM
Hi guys, I have this contract
Copy code
.body(PactDslJsonArray.arrayMinLike(1)
    .stringType("transactionHash")
    .stringType("originWallet")
    .stringType("destinationWallet")
    .decimalType("amount", 1.0)
    .datetime("creationDate")
    .stringType("method")
    .stringType("status")
    .decimalType("fee")
).toPact();
when I execute my consumer tests they are passing, but then when I'm running my provider tests I'm getting this error: body: $.0.creationDate Expected 1652738400000 to match a datetime of 'yyyy-MM-dd'T'HHmmss': Unable to parse the date: 1652738400000
f

Fábio Rodrigues

05/17/2022, 10:41 AM
it's the format of the date. a datetime should be in that format and it's not
the dateformat it's expect it's something like this: 2022-05-16, 230000
o

Oscar Calderin

05/17/2022, 10:44 AM
yes, the provider is returning a timestamp for the field creationDate and I'm using datetime("creationDate") in PactDslJsonArray, but it is not working
f

Fábio Rodrigues

05/17/2022, 10:44 AM
if it's a timestamp it is a int
not a datetime
also that timestamp is in what nanoseconds?
o

Oscar Calderin

05/17/2022, 10:45 AM
let me try with an int
but I think it should fail because this field is declared as a Date in the Dto
f

Fábio Rodrigues

05/17/2022, 10:48 AM
the thing is that a timestamp is a number (number of units of time since a specific instant)
and a date requires localization and other concepts
what does the provider gives
a timestamp or a datetime string with correct localization ?
o

Oscar Calderin

05/17/2022, 10:51 AM
a datetime string with correct localization
f

Fábio Rodrigues

05/17/2022, 10:51 AM
then your provider has a bug
because it's sending a timestamp
on that field
or you have a wrong expectation
o

Oscar Calderin

05/17/2022, 11:02 AM
I think I have a wrong expectation because the field is a Date, when I check in the database it is also stored as a Date, but then when I receive the response it looks like they are transforming this Date to a timestamp and that is what I'm receiving
f

Fábio Rodrigues

05/17/2022, 11:03 AM
then contract testing is doing it's job on dealing with expectations
💯 2
🙂
4 Views