Skip to content

Commit

Permalink
feat: try to pass in fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
shobbsd committed May 16, 2024
1 parent 0c32155 commit 3ca8782
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/reportToSlack/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions src/reportToSlack/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const createSlackReport = (slackUrl: string) => {
export const createSlackReport = (
slackUrl: string,
fetchPassIn: typeof fetch
) => {
return async (message: string, additionalInfo: Record<string, unknown>) => {
const res = await fetch(slackUrl, {
const res = await fetchPassIn(slackUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down

0 comments on commit 3ca8782

Please sign in to comment.