Skip to content

Commit

Permalink
fix: URLs were not being generated correctly when used with an array …
Browse files Browse the repository at this point in the history
…contains matcher
  • Loading branch information
Ronald Holshausen committed Jan 12, 2021
1 parent 3f1bbfa commit 4fccb8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/v3/matchers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,5 +468,23 @@ describe("V3 Matchers", () => {
})
})
})

describe("when no base URL is provided", () => {
it("returns regex matcher and a MockServerURL generator", () => {
let result = MatchersV3.url([
"users",
MatchersV3.regex("\\d+", "1234"),
"posts",
"latest",
])
expect(result).to.deep.equal({
"pact:matcher:type": "regex",
"pact:generator:type": "MockServerURL",
regex: ".*(\\/users\\/\\d+\\/posts\\/latest)$",
value: "http://localhost:8080/users/1234/posts/latest",
example: "http://localhost:8080/users/1234/posts/latest"
})
})
})
})
})
4 changes: 4 additions & 0 deletions src/v3/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export namespace MatchersV3 {

interface RegexMatcher extends Matcher {
regex: string
example?: string
}

/**
Expand Down Expand Up @@ -382,12 +383,15 @@ export namespace MatchersV3 {
}
}

// Temporary fix for inconsistancies between matchers and generators. Matchers use "value" attribute for
// example values, while generators use "example"
if (basePath == null) {
return {
"pact:matcher:type": "regex",
"pact:generator:type": "MockServerURL",
regex: regex + ")$",
value: example,
example
}
} else {
return {
Expand Down

0 comments on commit 4fccb8d

Please sign in to comment.