Skip to content

Commit

Permalink
Merge pull request #216 from alex3165/improvement/github-test-2
Browse files Browse the repository at this point in the history
Add more tests for github.ts
  • Loading branch information
orta committed Apr 13, 2017
2 parents 8fba6e7 + ddb7be1 commit 9261f42
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
2 changes: 2 additions & 0 deletions source/danger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface GitCommit {
tree: any,
/** SHAs for the commit's parents */
parents?: string[],
/** Link to the commit */
url: string
}

/** An author of a commit */
Expand Down
2 changes: 2 additions & 0 deletions source/dsl/Commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface GitCommit {
tree: any,
/** SHAs for the commit's parents */
parents?: string[],
/** Link to the commit */
url: string
}

/** An author of a commit */
Expand Down
45 changes: 38 additions & 7 deletions source/platforms/_tests/_github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ jest.mock("../github/GitHubAPI", () => {
const fixtures = await requestWithFixturedJSON("github_issue.json")
return await fixtures()
}

async getPullRequestCommits() {
const fixtures = await requestWithFixturedJSON("github_commits.json")
return await fixtures()
}

async getReviews() {
const fixtures = await requestWithFixturedJSON("reviews.json")
return await fixtures()
}

async getReviewerRequests() {
const fixtures = await requestWithFixturedJSON("requested_reviewers.json")
return await fixtures()
}
}

return { GitHubAPI }
Expand All @@ -30,14 +45,15 @@ import { GitHubAPI } from "../github/GitHubAPI"
import { GitCommit } from "../../dsl/Commit"
import { FakeCI } from "../../ci_source/providers/Fake"
import * as os from "os"
import { RepoMetaData } from "../../ci_source/ci_source"

const EOL = os.EOL

describe("getPlatformDSLRepresentation", () => {
let github
let github: GitHub

beforeEach(() => {
github = new GitHub(new GitHubAPI({} as any))
github = new GitHub(new GitHubAPI({} as RepoMetaData))
})

it("should return the correct review title from getReviewInfo", async () => {
Expand All @@ -50,9 +66,24 @@ describe("getPlatformDSLRepresentation", () => {
expect(issue.labels[0].name).toEqual("bug")
})

// need to cover:
// - getPullRequestCommits
// - getReviews
// - getReviewerRequests
// to do a full DSL test
it("should get the commits of the pull request", async() => {
const expected = "https://api.github.com/repos/artsy/emission/git/commits/13da2c844def1f4262ee440bd86fb2a3b021718b"
const { commits } = await github.getPlatformDSLRepresentation()
expect(commits[0].commit.url).toEqual(expected)
})

it("should get the reviews", async() => {
const { reviews } = await github.getPlatformDSLRepresentation()
expect(reviews[0].id).toEqual(2332973)
})

it("should get the reviewer requests", async () => {
const { requested_reviewers } = await github.getPlatformDSLRepresentation()
expect(requested_reviewers[0].id).toEqual(12397828)
})

it("should get the pull request informations", async () => {
const { pr } = await github.getPlatformDSLRepresentation()
expect(pr.number).toEqual(327)
})
})
3 changes: 2 additions & 1 deletion source/platforms/github/GitHubGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function githubCommitToGitCommit(ghCommit: GitHubCommit): GitCommit {
author: ghCommit.commit.author,
committer: ghCommit.commit.committer,
message: ghCommit.commit.message,
tree: ghCommit.commit.tree
tree: ghCommit.commit.tree,
url: ghCommit.url
}
}

Expand Down
1 change: 1 addition & 0 deletions source/platforms/github/_tests/_github_git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe("the dangerfile gitDSL", async () => {
"sha": "d1b7448d7409093054efbb06ae12d1ffb002b956",
"url": "https://api.github.com/repos/artsy/emission/git/trees/d1b7448d7409093054efbb06ae12d1ffb002b956",
},
"url": "https://api.github.com/repos/artsy/emission/commits/13da2c844def1f4262ee440bd86fb2a3b021718b"
}
const gitDSL = await github.getPlatformGitRepresentation()
expect(gitDSL.commits[0]).toEqual(exampleCommit)
Expand Down

0 comments on commit 9261f42

Please sign in to comment.