Skip to content

Commit

Permalink
added some testing to support the edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
OJPARKINSON committed May 30, 2022
1 parent fe1818b commit 5fe3da1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions source/ci_source/providers/_tests/_codebuild.test.ts
Expand Up @@ -51,7 +51,7 @@ describe(".isPR", () => {
expect(codebuild.isPR).toBeFalsy()
})

it.each(["CODEBUILD_BUILD_ID", "CODEBUILD_SOURCE_REPO_URL"])(`does not validate when %s is missing`, async key => {
it.each(["CODEBUILD_BUILD_ID", "CODEBUILD_SOURCE_REPO_URL"])(`does not validate when %s is missing`, async (key) => {
const copiedEnv = { ...correctEnv }
delete copiedEnv[key]
const codebuild = await setupCodeBuildSource(copiedEnv)
Expand All @@ -71,7 +71,7 @@ describe(".pullRequestID", () => {
jest.resetAllMocks()
})

it.each(["CODEBUILD_SOURCE_VERSION", "CODEBUILD_WEBHOOK_TRIGGER"])("splits it from %s", async key => {
it.each(["CODEBUILD_SOURCE_VERSION", "CODEBUILD_WEBHOOK_TRIGGER"])("splits it from %s", async (key) => {
const codebuild = await setupCodeBuildSource({ [key]: "pr/2" })
await codebuild.setup()
expect(codebuild.pullRequestID).toEqual("2")
Expand All @@ -90,6 +90,18 @@ describe(".pullRequestID", () => {
expect(getPullRequestIDForBranch).toHaveBeenCalledWith(codebuild, env, "my-branch")
})

it('allows for branch names with "/" in them', async () => {
const env = {
CODEBUILD_SOURCE_REPO_URL: "https://github.com/sharkysharks/some-repo",
CODEBUILD_WEBHOOK_TRIGGER: "branch/my-branch/with/slashes",
DANGER_GITHUB_API_TOKEN: "xxx",
}
const codebuild = await setupCodeBuildSource(env)
expect(codebuild.pullRequestID).toBe("0")
expect(getPullRequestIDForBranch).toHaveBeenCalledTimes(1)
expect(getPullRequestIDForBranch).toHaveBeenCalledWith(codebuild, env, "my-branch/with/slashes")
})

it("does not call the API if no PR number or branch name available in the env vars", async () => {
const env = {
CODEBUILD_SOURCE_REPO_URL: "https://github.com/sharkysharks/some-repo",
Expand Down

0 comments on commit 5fe3da1

Please sign in to comment.