Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bicstone committed Nov 4, 2023
1 parent 3892ea2 commit 001170c
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/pr/postComments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ describe("postComments", () => {
expect(result.error).toEqual("プルリクエストが下書きでした。")
expect(fetchSpy).toHaveBeenCalledTimes(0)
})
it("throw error if fetch failed with a status code other than 200", async () => {
fetchSpy.mockImplementation(() =>
Promise.resolve({
ok: false,
statusText: "500",
} as Response),
)

const event = getEvent(_event)
const parsedPullRequest = getParsedPullRequest(event)
const configs = getConfigs(parsedPullRequest)

try {
await postComments(configs)
} catch (e) {
expect(e).toEqual(new Error("500"))
}
expect.assertions(1)
})
},
)

Expand Down Expand Up @@ -236,6 +255,25 @@ describe("postComments", () => {
expect(result.error).toEqual("プルリクエストが下書きでした。")
expect(fetchSpy).toHaveBeenCalledTimes(0)
})
it("throw error if fetch failed with a status code other than 200", async () => {
fetchSpy.mockImplementation(() =>
Promise.resolve({
ok: false,
statusText: "500",
} as Response),
)

const event = getEvent(_event)
const parsedPullRequest = getParsedPullRequest(event)
const configs = getConfigs(parsedPullRequest)

try {
await postComments(configs)
} catch (e) {
expect(e).toEqual(new Error("500"))
}
expect.assertions(1)
})
})

describe.each(closedEvents)("closed", (_event) => {
Expand Down Expand Up @@ -285,6 +323,25 @@ describe("postComments", () => {
expect(result.error).toEqual("プルリクエストが下書きでした。")
expect(fetchSpy).toHaveBeenCalledTimes(0)
})
it("throw error if fetch failed with a status code other than 200", async () => {
fetchSpy.mockImplementation(() =>
Promise.resolve({
ok: false,
statusText: "500",
} as Response),
)

const event = getEvent(_event)
const parsedPullRequest = getParsedPullRequest(event)
const configs = getConfigs(parsedPullRequest)

try {
await postComments(configs)
} catch (e) {
expect(e).toEqual(new Error("500"))
}
expect.assertions(1)
})
})

describe.each(unexpectedEvents)("unexpected", (_event) => {
Expand Down
24 changes: 24 additions & 0 deletions src/push/postCommits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,28 @@ describe("postComments", () => {
).resolves.toStrictEqual([response1, response2])
expect(fetchSpy).toHaveBeenCalledTimes(2)
})

it("throw error if fetch failed with a status code other than 200", async () => {
fetchSpy.mockImplementation(() =>
Promise.resolve({
ok: false,
statusText: "500",
} as NodeJS.fetch.Response),
)

try {
await postComments({
parsedCommits: baseCommits,
parsedRef: baseParsedRef,
fixStatusId,
closeStatusId,
pushCommentTemplate,
apiHost,
apiKey,
})
} catch (e) {
expect(e).toEqual(new Error("500"))
}
expect.assertions(1)
})
})

0 comments on commit 001170c

Please sign in to comment.