Skip to content

Commit

Permalink
fix: use example in datetime matcher instead of generator if provided.
Browse files Browse the repository at this point in the history
…Fixes #620
  • Loading branch information
mefellows committed Mar 3, 2021
1 parent 336812b commit c0ca78b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
21 changes: 11 additions & 10 deletions src/v3/matchers.spec.ts
Expand Up @@ -325,16 +325,17 @@ describe("V3 Matchers", () => {
})

describe("#datetime", () => {
it("returns a JSON representation of a datetime matcher", () => {
let result = MatchersV3.datetime(
"yyyy-MM-dd'T'HH:mm:ss.SSSX",
"2016-02-11T09:46:56.023Z"
)
expect(result).to.deep.equal({
"pact:generator:type": "DateTime",
"pact:matcher:type": "timestamp",
format: "yyyy-MM-dd'T'HH:mm:ss.SSSX",
value: "2016-02-11T09:46:56.023Z",
describe("when an example is given", () => {
it("returns a JSON representation of a datetime matcher", () => {
let result = MatchersV3.datetime(
"yyyy-MM-dd'T'HH:mm:ss.SSSX",
"2016-02-11T09:46:56.023Z"
)
expect(result).to.deep.equal({
"pact:matcher:type": "timestamp",
format: "yyyy-MM-dd'T'HH:mm:ss.SSSX",
value: "2016-02-11T09:46:56.023Z",
})
})
})

Expand Down
17 changes: 9 additions & 8 deletions src/v3/matchers.ts
@@ -1,4 +1,5 @@
import * as R from "ramda"
import { isNil, pickBy, times } from "ramda"

const PactNative = require("../native/index.node")

export namespace MatchersV3 {
Expand Down Expand Up @@ -49,7 +50,7 @@ export namespace MatchersV3 {
return {
min: 1,
"pact:matcher:type": "type",
value: R.times(() => template, count),
value: times(() => template, count),
}
}

Expand All @@ -75,7 +76,7 @@ export namespace MatchersV3 {
return {
min,
"pact:matcher:type": "type",
value: R.times(() => template, elements),
value: times(() => template, elements),
}
}

Expand Down Expand Up @@ -108,7 +109,7 @@ export namespace MatchersV3 {
return {
max,
"pact:matcher:type": "type",
value: R.times(() => template, elements),
value: times(() => template, elements),
}
}

Expand Down Expand Up @@ -152,7 +153,7 @@ export namespace MatchersV3 {
min,
max,
"pact:matcher:type": "type",
value: R.times(() => template, elements),
value: times(() => template, elements),
}
}

Expand Down Expand Up @@ -297,12 +298,12 @@ export namespace MatchersV3 {
* @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): DateTimeMatcher {
return {
"pact:generator:type": "DateTime",
return pickBy((v) => !isNil(v), {
"pact:generator:type": example ? undefined : "DateTime",
"pact:matcher:type": "timestamp",
format,
value: example || PactNative.generate_datetime_string(format),
}
})
}

/**
Expand Down

0 comments on commit c0ca78b

Please sign in to comment.