Skip to content

Commit

Permalink
fix: Don't use fee to calculate exemption statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 2, 2023
1 parent 605e2f0 commit 2f33404
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
36 changes: 30 additions & 6 deletions api.planx.uk/modules/webhooks/sendNotification/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.fee.exemption.resubmission": ["true"],
},
},
},
Expand Down Expand Up @@ -205,24 +215,38 @@ 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" })
.set({ Authorization: process.env.HASURA_PLANX_API_KEY })
.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);
Expand Down
15 changes: 10 additions & 5 deletions api.planx.uk/modules/webhooks/sendNotification/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,12 +50,15 @@ 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.fee.exemption.resubmission",
]);

return feePayable;
return { disability, resubmission };
};

0 comments on commit 2f33404

Please sign in to comment.