https://pact.io logo
#pact-swift
Title
# pact-swift
a

Ardiel

02/09/2022, 7:29 AM
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

Matt (pactflow.io / pact-js / pact-go)

02/11/2022, 2:23 AM
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

Marko (IttyBittyApps / pact-swift)

02/13/2022, 3:27 AM
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

Marcelino

03/07/2022, 8:00 AM
Hi @Marko (IttyBittyApps / pact-swift) I’ll give it a try ASAP. Thank you very much!
m

Marko (IttyBittyApps / pact-swift)

03/08/2022, 2:00 AM
@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

Marcelino

03/08/2022, 10:46 AM
Sure @Marko (IttyBittyApps / pact-swift) I’m still testing
m

Marko (IttyBittyApps / pact-swift)

03/09/2022, 10:35 PM
DateTimeExpression
now available in
PactSwift v0.12.0
m

Marcelino

03/10/2022, 11:43 AM
Thank you very much @Marko (IttyBittyApps / pact-swift)
m

Marko (IttyBittyApps / pact-swift)

03/10/2022, 12:45 PM
No worries. Thanks for your PR. I completely missed that rather obvious one 🤷‍♂️
👍 1
5 Views