diff --git a/api.planx.uk/modules/webhooks/sendNotification/index.test.ts b/api.planx.uk/modules/webhooks/sendNotification/index.test.ts index d6049f4eb1..1a67dcb134 100644 --- a/api.planx.uk/modules/webhooks/sendNotification/index.test.ts +++ b/api.planx.uk/modules/webhooks/sendNotification/index.test.ts @@ -15,11 +15,21 @@ const mockSessionWithFee = { }, }; -const mockSessionWithoutFee = { +const mockSessionWithDisabilityExemption = { data: { passport: { data: { - "application.fee.payable": "0", + "application.fee.exemption.disability": ["true"], + }, + }, + }, +}; + +const mockSessionWithResubmissionExemption = { + data: { + passport: { + data: { + "application.resubmission": ["true"], }, }, }, @@ -205,11 +215,11 @@ describe("Send Slack notifications endpoint", () => { }); }); - it("adds an exemption status if there's no fee for the session", async () => { + it("adds a status to the Slack message for a disability exemption", async () => { process.env.APP_ENVIRONMENT = "production"; mockAdmin.session.find = jest .fn() - .mockResolvedValue(mockSessionWithoutFee); + .mockResolvedValue(mockSessionWithDisabilityExemption); await post(ENDPOINT) .query({ type: "uniform-submission" }) @@ -217,12 +227,26 @@ describe("Send Slack notifications endpoint", () => { .send(body) .expect(200) .then((response) => { - expect(response.body.data).toMatch(/abc123/); - expect(response.body.data).toMatch(/test-council/); expect(response.body.data).toMatch(/[Exempt]/); }); }); + it("adds a status to the Slack message for a resubmission exemption", async () => { + process.env.APP_ENVIRONMENT = "production"; + mockAdmin.session.find = jest + .fn() + .mockResolvedValue(mockSessionWithResubmissionExemption); + + await post(ENDPOINT) + .query({ type: "uniform-submission" }) + .set({ Authorization: process.env.HASURA_PLANX_API_KEY }) + .send(body) + .expect(200) + .then((response) => { + expect(response.body.data).toMatch(/[Resubmission]/); + }); + }); + it("handles missing sessions", async () => { process.env.APP_ENVIRONMENT = "production"; mockAdmin.session.find = jest.fn().mockResolvedValueOnce(null); diff --git a/api.planx.uk/modules/webhooks/sendNotification/service.ts b/api.planx.uk/modules/webhooks/sendNotification/service.ts index 10aaff7755..6989159288 100644 --- a/api.planx.uk/modules/webhooks/sendNotification/service.ts +++ b/api.planx.uk/modules/webhooks/sendNotification/service.ts @@ -17,8 +17,10 @@ export const sendSlackNotification = async ( let message = getMessageForEventType(data, type); const sessionId = getSessionIdFromEvent(data, type); - const feePayable = await getFeePayableForSession(sessionId); - if (!feePayable) message += " [Exempt]"; + const { disability, resubmission } = + await getExemptionStatusesForSession(sessionId); + if (disability) message += " [Exempt]"; + if (resubmission) message += " [Resubmission]"; await slack.send(":incoming_envelope: " + message); return message; @@ -48,12 +50,13 @@ const getSessionIdFromEvent = (data: EventData, type: EventType) => "email-submission": (data as EmailEventData).session_id, })[type]; -const getFeePayableForSession = async (sessionId: string) => { +const getExemptionStatusesForSession = async (sessionId: string) => { const session = await $admin.session.find(sessionId); if (!session) throw Error(`Unable to find session with ID ${sessionId}`); const passport = new Passport(session.data.passport); - const feePayable = passport.number(["application.fee.payable"]); + const disability = passport.boolean(["application.fee.exemption.disability"]); + const resubmission = passport.boolean(["application.resubmission"]); - return feePayable; + return { disability, resubmission }; };