Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex3165 committed Mar 16, 2017
1 parent 6a06626 commit 73f5071
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
29 changes: 8 additions & 21 deletions source/platforms/_tests/GitHub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,21 @@ const mockGitHubWithGetForPath = (expectedPath): GitHub => {
}

/** Returns JSON from the fixtured dir */
export const requestWithFixturedJSON = async (path: string): Promise<any> => {
const json = JSON.parse(readFileSync(`${fixtures}/${path}`, {}).toString())
return () => {
return {
json: () => Promise.resolve(json)
}
}
}
export const requestWithFixturedJSON = async (path: string): Promise<() => Promise<any>> => () => (
Promise.resolve(JSON.parse(readFileSync(`${fixtures}/${path}`, {}).toString()))
)

/** Returns arbitrary text value from a request */
export const requestWithFixturedContent = async (path: string): Promise<any> => {
const content = readFileSync(`${fixtures}/${path}`, {}).toString()
return () => {
return {
text: () => Promise.resolve(content)
}
}
}
export const requestWithFixturedContent = async (path: string): Promise<() => Promise<string>> => () => (
Promise.resolve(readFileSync(`${fixtures}/${path}`, {}).toString())
)

describe("with fixtured data", () => {
it("returns the correct github data", async () => {
const mockSource = new FakeCI({})
const api = new GitHubAPI(mockSource)
const github = new GitHub(api)
api.getPullRequestInfo = await requestWithFixturedJSON("github_pr.json")
api.getPullRequestCommits = await requestWithFixturedJSON("github_commits.json")

const info = await github.getReviewInfo()
expect(info.title).toEqual("Adds support for showing the metadata and trending Artists to a Gene VC")
Expand All @@ -65,10 +54,8 @@ describe("with fixtured data", () => {
const api = new GitHubAPI(new FakeCI({}))
github = new GitHub(api)

const res = await requestWithFixturedContent("github_diff.diff")
api.getPullRequestDiff = res().text
const jsonFixtures = await requestWithFixturedJSON("github_commits.json")
api.getPullRequestCommits = jsonFixtures().json
api.getPullRequestDiff = await requestWithFixturedContent("github_diff.diff")
api.getPullRequestCommits = await requestWithFixturedJSON("github_commits.json")
})

it("sets the modified/created/deleted", async () => {
Expand Down
8 changes: 3 additions & 5 deletions source/platforms/github/_tests/_GitHubAPI.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GitHubAPI } from "../GitHubAPI"
import { FakeCI } from "../../../ci_source/providers/Fake"
import { requestWithFixturedJSON, requestWithFixturedContent } from "../../_tests/GitHub.test"
import { requestWithFixturedJSON } from "../../_tests/GitHub.test"

const fetchJSON = (api, params): Promise<any> => {
return Promise.resolve({
Expand All @@ -22,10 +22,8 @@ it("fileContents expects to grab PR JSON and pull out a file API call", async ()
const mockSource = new FakeCI({})
const api = new GitHubAPI(mockSource, "token")

const requestFixture = await requestWithFixturedJSON("github_pr.json")
api.getPullRequestInfo = requestFixture().json
const fileContentFixture = await requestWithFixturedJSON("static_file.json")
api.getFileContents = fileContentFixture().json
api.getPullRequestInfo = await requestWithFixturedJSON("github_pr.json")
api.getFileContents = await requestWithFixturedJSON("static_file.json")

const info = await api.fileContents("my_path.md")
expect(info).toEqual("The All-Defector is a purported glitch in the Dilemma Prison that appears to prisoners as themselves. This gogol always defects, hence the name.")//tslint:disable-line:max-line-length
Expand Down

0 comments on commit 73f5071

Please sign in to comment.