diff --git a/src/scheduler/workers/unpublish/dayBefore/addDayBeforePostReminderAudit.ts b/src/scheduler/workers/unpublish/dayBefore/addDayBeforePostReminderAudit.ts index 783d26466..1005ba8a1 100644 --- a/src/scheduler/workers/unpublish/dayBefore/addDayBeforePostReminderAudit.ts +++ b/src/scheduler/workers/unpublish/dayBefore/addDayBeforePostReminderAudit.ts @@ -1,6 +1,6 @@ import { prisma } from "scheduler/prismaClient"; -import { AuditCreateInput, ListEventJsonData } from "server/models/types"; -import { AuditEvent } from "@prisma/client"; +import type { AuditCreateInput, ListEventJsonData } from "server/models/types"; +import type { AuditEvent } from "@prisma/client"; export async function addUnpublishPostReminderAudit(eventData: ListEventJsonData, auditEvent: AuditEvent) { const data: AuditCreateInput = { diff --git a/src/scheduler/workers/unpublish/delete/index.ts b/src/scheduler/workers/unpublish/delete/index.ts index 20107a0f5..c4bb903e1 100644 --- a/src/scheduler/workers/unpublish/delete/index.ts +++ b/src/scheduler/workers/unpublish/delete/index.ts @@ -17,6 +17,7 @@ export default async function deleteItemsAfterAYear() { await prisma.$transaction([ prisma.audit.createMany({ + // Data added to Audit table for list item since it's been removed therefore does not have any items in the Event table to connect to data: itemsUnpublishedByAR.map((item) => ({ auditEvent: "DELETED", type: "listItem", diff --git a/src/server/services/__mocks__/notifications-node-client.ts b/src/server/services/__mocks__/notifications-node-client.ts index 505c3b4d9..415c0d253 100644 --- a/src/server/services/__mocks__/notifications-node-client.ts +++ b/src/server/services/__mocks__/notifications-node-client.ts @@ -1,4 +1,4 @@ -const sendEmail = jest.fn().mockResolvedValue({ statusText: "Created" }); +const sendEmail = jest.fn().mockResolvedValue({ id: "Created" }); export const NotifyClient = jest.fn().mockReturnValue({ sendEmail, diff --git a/src/server/services/__tests__/govuk-notify.test.ts b/src/server/services/__tests__/govuk-notify.test.ts index d37fb85fb..d713c13f5 100644 --- a/src/server/services/__tests__/govuk-notify.test.ts +++ b/src/server/services/__tests__/govuk-notify.test.ts @@ -62,7 +62,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const emailAddress = "testemail@gov.uk"; @@ -109,7 +109,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const contactName = "Ada Lovelace"; @@ -156,7 +156,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const contactName = "Ada Lovelace"; @@ -204,7 +204,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const contactName = "Ada Lovelace"; @@ -252,7 +252,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const emailAddress = "testemail@gov.uk"; @@ -268,7 +268,7 @@ describe("GOVUK Notify service:", () => { annualReviewDate ); - expect(result).toBe(true); + expect(result.id).toBeTruthy(); expect(notifyClient.sendEmail).toHaveBeenCalledWith( mockNotify.templates.annualReviewNotices.postOneMonth, "testemail@gov.uk", @@ -288,7 +288,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const emailAddress = "testemail@gov.uk"; @@ -304,7 +304,7 @@ describe("GOVUK Notify service:", () => { annualReviewDate ); - expect(result).toBe(true); + expect(result.id).toBeTruthy(); expect(notifyClient.sendEmail).toHaveBeenCalledWith( mockNotify.templates.annualReviewNotices.postOneWeek, "testemail@gov.uk", @@ -324,7 +324,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const emailAddress = "testemail@gov.uk"; @@ -340,7 +340,7 @@ describe("GOVUK Notify service:", () => { annualReviewDate ); - expect(result).toBe(true); + expect(result.id).toBeTruthy(); expect(notifyClient.sendEmail).toHaveBeenCalledWith( mockNotify.templates.annualReviewNotices.postOneDay, "testemail@gov.uk", @@ -360,7 +360,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const emailAddress = "testemail@gov.uk"; @@ -370,7 +370,7 @@ describe("GOVUK Notify service:", () => { const { result } = await sendAnnualReviewPostEmail("START", emailAddress, typePlural, country, annualReviewDate); - expect(result).toBe(true); + expect(result.id).toBeTruthy(); expect(notifyClient.sendEmail).toHaveBeenCalledWith( mockNotify.templates.annualReviewNotices.postStart, "testemail@gov.uk", @@ -414,7 +414,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); const emailAddress = "testemail@gov.uk"; @@ -433,7 +433,7 @@ describe("GOVUK Notify service:", () => { changeLink ); - expect(result).toBe(true); + expect(result.id).toBeTruthy(); expect(notifyClient.sendEmail).toHaveBeenCalledWith( mockNotify.templates.annualReviewNotices.providerStart, "testemail@gov.uk", @@ -500,7 +500,7 @@ describe("GOVUK Notify service:", () => { const notifyClient = getNotifyClient(); jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce({ - statusText: "Created", + id: "Created", }); await sendManualActionNotificationToPost(1, trigger); @@ -514,13 +514,13 @@ describe("GOVUK Notify service:", () => { test("returns resolved value when at least one email succeeds", async () => { const notifyClient = getNotifyClient(); const successfulSend = { - statusText: "Created", + id: "Created", }; const rejectedSend = "Failed to send email"; jest.spyOn(notifyClient, "sendEmail").mockResolvedValueOnce(successfulSend).mockRejectedValueOnce(rejectedSend); const settled = await sendManualActionNotificationToPost(1, "CHANGED_DETAILS"); - expect(settled).toEqual({ statusText: "Created" }); + expect(settled).toEqual({ id: "Created" }); }); }); }); diff --git a/src/server/services/govuk-notify.ts b/src/server/services/govuk-notify.ts index 60c08b1ec..eefbd5427 100644 --- a/src/server/services/govuk-notify.ts +++ b/src/server/services/govuk-notify.ts @@ -36,7 +36,7 @@ export async function sendAuthenticationEmail(email: string, authenticationLink: reference: "", }); - return (result as NotifyResult).statusText === "Created"; + return "id" in result && result.id !== undefined; } catch (error) { logger.error(`sendAuthenticationEmail Error: ${error.message}`); return false; @@ -61,7 +61,7 @@ export async function sendApplicationConfirmationEmail( reference: "", }); - return (result as NotifyResult).statusText === "Created"; + return "id" in result && result.id !== undefined; } catch (error) { logger.error(`sendApplicationConfirmationEmail Error: ${error.message}`); return false; @@ -88,7 +88,7 @@ export async function sendDataPublishedEmail( reference: "", }); - return (result as NotifyResult).statusText === "Created"; + return "id" in result && result.id !== undefined; } catch (error) { logger.error(`sendDataPublishedEmail Error: ${error.message}`); return false; @@ -121,7 +121,7 @@ export async function sendEditDetailsEmail( reference: "", }); - return { result: (result as NotifyResult).statusText === "Created" }; + return { result: "id" in result && result.id !== undefined }; } catch (error) { const message = `sendEditDetailsEmail: Unable to send change request email: ${error.message}`; logger.error(message); diff --git a/src/shared/getNotifyClient.ts b/src/shared/getNotifyClient.ts index 058168fcc..8d288771b 100644 --- a/src/shared/getNotifyClient.ts +++ b/src/shared/getNotifyClient.ts @@ -21,7 +21,7 @@ export function getNotifyClient() { class FakeNotifyClient { sendEmail() { - return { statusText: "Created" }; + return { id: "Created" }; } } diff --git a/src/shared/types.ts b/src/shared/types.ts index 0a5ed2df1..dd1f1dce6 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -99,10 +99,6 @@ export interface ListUpdateInput extends PrismaClient.Prisma.ListUpdateInput { jsonData: ListJsonData; } -export interface NotifyResult { - statusText: string; -} - export interface Event extends PrismaClient.Event { jsonData: EventJsonData; }