From 3ca8782710022886ac19cd98a2052b9bff39f6e4 Mon Sep 17 00:00:00 2001 From: Shaquille Hobbs-Daley Date: Thu, 16 May 2024 13:25:42 +0100 Subject: [PATCH] feat: try to pass in fetch --- src/reportToSlack/index.test.ts | 4 ++-- src/reportToSlack/index.ts | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) 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",