Skip to content

Commit

Permalink
fix: added provider gitlab tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankatliarchuk committed Oct 1, 2022
1 parent 6c49cfe commit dafdb02
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions source/ci_source/providers/GitLabCI.ts
Expand Up @@ -23,6 +23,7 @@ export class GitLabCI implements CISource {
}

get repoSlug(): string {
// return this.env.CI_MERGE_REQUEST_PROJECT_PATH || this.env.CI_PROJECT_PATH
return this.env.CI_PROJECT_PATH
}

Expand Down
44 changes: 44 additions & 0 deletions source/ci_source/providers/_tests/_gitlab.test.ts
@@ -0,0 +1,44 @@
import { GitLabCI } from "../GitLabCI"
import { getCISourceForEnv } from "../../get_ci_source"

const correctEnv = {
GITLAB_CI: "true",
CI_MERGE_REQUEST_IID: "27117",
CI_PROJECT_PATH: "gitlab-org/gitlab-foss",
// DANGER_GITLAB_API_TOKEN: "gitlab_dummy_a829-07bd7559eecb"
}

describe("being found when looking for CI", () => {
it("finds GitLab with the right ENV", () => {
const ci = getCISourceForEnv(correctEnv)
expect(ci).toBeInstanceOf(GitLabCI)
})
})

describe(".isCI", () => {
it("validates when all GitLab environment vars are set", async () => {
const result = new GitLabCI(correctEnv)
expect(result.isCI).toBeTruthy()
})

it("does not validate without env", async () => {
const result = new GitLabCI({})
expect(result.isCI).toBeFalsy()
})
})

// missed

describe(".pullRequestID", () => {
it("pulls it out of the env", () => {
const result = new GitLabCI(correctEnv)
expect(result.pullRequestID).toEqual("27117")
})
})

describe(".repoSlug", () => {
it("derives it from the PR Url", () => {
const result = new GitLabCI(correctEnv)
expect(result.repoSlug).toEqual("gitlab-org/gitlab-foss")
})
})

0 comments on commit dafdb02

Please sign in to comment.