Skip to content

Commit

Permalink
Ensures PATCH requests work, and adds a test to cover them.
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Feb 1, 2017
1 parent c5446c5 commit 139df43
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Add your own contribution below

* Internal changes for usage with Peril - orta

### 0.11.0 - 0.11.2

* Add support for [Docker Cloud](https://cloud.docker.com) - camacho
Expand Down
11 changes: 8 additions & 3 deletions source/platforms/github/GitHubAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class GitHubAPI {
})
}

get(path: string, headers: any = {}, body: any = {}, method: string = "GET"): Promise<any> {
private api(path: string, headers: any = {}, body: any = {}, method: string = "GET"): Promise<any> {
if (this.token !== undefined) {
headers["Authorization"] = `token ${this.token}`
}
Expand All @@ -148,7 +148,12 @@ export class GitHubAPI {
})
}

patch(path: string, headers: any = {}, body: any = {}, method: string = "PATCH"): Promise<any> {
return this.get(path, headers, body, method)
get(path: string, headers: any = {}, body: any = {}): Promise<any> {
return this.api(path, headers, body, "GET")

}

patch(path: string, headers: any = {}, body: any = {}): Promise<any> {
return this.api(path, headers, body, "PATCH")
}
}
26 changes: 23 additions & 3 deletions source/platforms/github/_tests/_GitHubAPI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GitHubAPI } from "../GitHubAPI"
import { FakeCI } from "../../../ci_source/providers/Fake"
import { requestWithFixturedJSON, requestWithFixturedContent } from "../../_tests/GitHub.test"

const fetch = (api, params): Promise<any> => {
const fetchJSON = (api, params): Promise<any> => {
return Promise.resolve({
json: () => Promise.resolve({
api,
Expand All @@ -11,6 +11,13 @@ const fetch = (api, params): Promise<any> => {
})
}

const fetch = (api, params): Promise<any> => {
return Promise.resolve({
api,
...params
})
}

it.skip("fileContents expects to grab PR JSON and pull out a file API call", async () => {
const mockSource = new FakeCI({})
const api = new GitHubAPI("token", mockSource)
Expand All @@ -30,10 +37,10 @@ describe("API testing", () => {
const mockSource = new FakeCI({})

api = new GitHubAPI("ABCDE", mockSource)
api.fetch = fetch
})

it("getUserInfo", async () => {
api.fetch = fetchJSON
expect(await api.getUserInfo()).toMatchObject({
api: "https://api.github.com/user",
headers: {
Expand All @@ -43,13 +50,26 @@ describe("API testing", () => {
method: "GET",
})
})

it("updateCommentWithID", async () => {
api.fetch = fetch
expect(await api.updateCommentWithID(123, "Hello!")).toMatchObject({
api: "https://api.github.com/repos/artsy/emission/issues/comments/123",
body: {"body": "Hello!"},
headers: {
Authorization: "token ABCDE",
"Content-Type": "application/json",
},
method: "PATCH",
})
})
})

describe("Peril", () => {
it("Allows setting additional headers", async () => {
const mockSource = new FakeCI({})
const api = new GitHubAPI("ABCDE", mockSource)
api.fetch = fetch
api.fetch = fetchJSON
api.additionalHeaders = { "CUSTOM": "HEADER" }

const request = await api.getUserInfo()
Expand Down

0 comments on commit 139df43

Please sign in to comment.