diff --git a/src/reportToSlack/index.test.ts b/src/reportToSlack/index.test.ts index 5d296dc..e68cd8a 100644 --- a/src/reportToSlack/index.test.ts +++ b/src/reportToSlack/index.test.ts @@ -13,7 +13,7 @@ describe("createSlackReport", () => { }); global.fetch = mockFetch; - const reportToSlack = createSlackReport(slackUrl); + const reportToSlack = createSlackReport(slackUrl, mockFetch); await reportToSlack(message, additionalInfo); expect(mockFetch).toHaveBeenCalledWith(slackUrl, { @@ -63,7 +63,7 @@ describe("createSlackReport", () => { }); global.fetch = mockFetch; - const reportToSlack = createSlackReport(slackUrl); + const reportToSlack = createSlackReport(slackUrl, mockFetch); await expect(reportToSlack(message, additionalInfo)).rejects.toThrow( "Failed to send report to Slack: 500 Internal Server Error" diff --git a/src/reportToSlack/index.ts b/src/reportToSlack/index.ts index 816811e..d9089ff 100644 --- a/src/reportToSlack/index.ts +++ b/src/reportToSlack/index.ts @@ -1,6 +1,9 @@ -export const createSlackReport = (slackUrl: string) => { +export const createSlackReport = ( + slackUrl: string, + fetchPassIn: typeof fetch +) => { return async (message: string, additionalInfo: Record) => { - const res = await fetch(slackUrl, { + const res = await fetchPassIn(slackUrl, { method: "POST", headers: { "Content-Type": "application/json",