Skip to content

Commit

Permalink
fix: date/time matchers were being skipped due to defect in upstream …
Browse files Browse the repository at this point in the history
…matching lib
  • Loading branch information
Ronald Holshausen committed May 27, 2020
1 parent 68f8d30 commit dcc3a7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/v3/e2e/test/consumer.spec.js
Expand Up @@ -13,7 +13,7 @@ describe("Pact V3", () => {
eachLike,
atLeastLike,
integer,
timestamp,
datetime,
boolean,
string,
regex,
Expand Down Expand Up @@ -51,7 +51,7 @@ describe("Pact V3", () => {
// API we don't care about
const animalBodyExpectation = {
id: integer(1),
available_from: timestamp("yyyy-MM-dd'T'HH:mm:ss.SSSX"),
available_from: datetime("yyyy-MM-dd'T'HH:mm:ss.SSSX"),
first_name: string("Billy"),
last_name: string("Goat"),
animal: string("goat"),
Expand Down
3 changes: 3 additions & 0 deletions native/src/lib.rs
Expand Up @@ -497,6 +497,9 @@ declare_types! {
Err(err) => panic!(err)
}
}
debug!("Response = {}", last.response);
debug!("Response matching rules = {:?}", last.response.matching_rules);
debug!("Response generators = {:?}", last.response.generators);
Ok(())
} else if pact.interactions.is_empty() {
Err("You need to define a new interaction with the uponReceiving method before you can define a new response with the willRespondWith method")
Expand Down
12 changes: 12 additions & 0 deletions src/v3/matchers.ts
Expand Up @@ -255,10 +255,20 @@ export function equal(value: any) {
* @param example Example value to use. If omitted a value using the current system date and time will be generated.
*/
export function timestamp(format: string, example?: string) {
return datetime(format, example)
}

/**
* String value that must match the provided datetime format string.
* @param format Datetime format string. See [Java SimpleDateFormat](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html)
* @param example Example value to use. If omitted a value using the current system date and time will be generated.
*/
export function datetime(format: string, example?: string) {
return {
"pact:generator:type": "DateTime",
"pact:matcher:type": "timestamp",
format,
timestamp: format, // This is needed due to a defect in upstream matching lib. Should be fixed in 0.6.2
value: example || PactNative.generate_datetime_string(format),
}
}
Expand All @@ -273,6 +283,7 @@ export function time(format: string, example?: string) {
"pact:generator:type": "Time",
"pact:matcher:type": "time",
format,
time: format, // This is needed due to a defect in upstream matching lib. Should be fixed in 0.6.2
value: example || PactNative.generate_datetime_string(format),
}
}
Expand All @@ -287,6 +298,7 @@ export function date(format: any, example?: string) {
format,
"pact:generator:type": "Date",
"pact:matcher:type": "date",
date: format, // This is needed due to a defect in upstream matching lib. Should be fixed in 0.6.2
value: example || PactNative.generate_datetime_string(format),
}
}
Expand Down

0 comments on commit dcc3a7f

Please sign in to comment.