Hello, I'm the backend colleague :slightly_smiling...
# pact-swift
a
Hello, I'm the backend colleague šŸ™‚. As you answered to this issue, on backend and Android side we are using v3 spec, We are studiying migrating the apple lib to the new one that supports v3, but what we didn`t locate in its documentation is if we could use expressions like the noted in the issue.
Copy code
"today +1 day @ 6 o'clock pm"
If it is possible to use this kind of expression, could you, please, give us some examples of its usage? Thanks a lot!
m
If youā€™re wanting to put that expression into the pact file, I donā€™t know if that is possible. @uglyog I donā€™t believe thatā€™s possible in Pact JVM. Can you do that?
m
No. I just tried this out and
PactSwift
passes the
expression
into the DateTime example generator. But
pact-rust
only spits out the
type
and
format
- just like the spec v3 says. The way I can see this making sense is to have the ā€œexpressionā€ (or really just a provided
Date
object) used for the consumer tests. But goes against best practices where Pact would be used to test values instead of validating structure and types.
Thereā€™s a branch now that exposes a `ExampleGenerator.DateTime(date: Date, format: String)`that will use the provided date converted to
String
using the provided format for the consumer test. Instead of the existing
ExampleGenerator.RandomDateTime(format: String)
that returns a formatted date for consumer tests. But I donā€™t think thereā€™s a declarative way of defining
Date
objects though in Swift where you could just say ā€œsome day in the future added by 3 hours and 4 millisecondsā€. Youā€™ll need to use
Calendar
and create the
Date
object by adding date components.
Iā€™d be very confused if I saw a:
Copy code
{ 
  "startDate": "some words describing a date" // instead of exemplary "2023-02-13" 
}
so then I canā€™t use
Decodable
on to convert into
Date
objectā€¦ šŸ˜…
Tracking this feature request in pact rust-core at https://github.com/pact-foundation/pact-reference/issues/180
šŸ‘ 2
@Marcelino @Ardiel PactSwift should be supporting the datetime expressions now on branch
feature/generator/datetime-expression
(link: https://github.com/surpher/PactSwift/tree/feature/generator/datetime-expression) Have it a spin and let me know if it works as expected. If it does Iā€™ll release a new version.
Example usage:
Copy code
.willRespondWith(
	status: 201,
	body: [
		"start": ExampleGenerator.DateTimeExpression(expression: "@ next hour", format: dateFormat)
	]
)
m
Hi @Marko (IttyBittyApps / pact-swift) Iā€™ll give it a try ASAP. Thank you very much!
m
@Marcelino if you donā€™t mind leave a comment on the PR for this if it fits the requirements. PR: https://github.com/surpher/PactSwift/pull/84 Iā€™ll then prepare a new version to release.
m
Sure @Marko (IttyBittyApps / pact-swift) Iā€™m still testing
m
DateTimeExpression
now available in
PactSwift v0.12.0
m
Thank you very much @Marko (IttyBittyApps / pact-swift)
m
No worries. Thanks for your PR. I completely missed that rather obvious one šŸ¤·ā€ā™‚ļø
šŸ‘ 1