diff --git a/.github/workflows/pr-coverage-annotation.yml b/.github/workflows/pr-coverage-annotation.yml index 75c29cc79..ca90f9562 100644 --- a/.github/workflows/pr-coverage-annotation.yml +++ b/.github/workflows/pr-coverage-annotation.yml @@ -42,8 +42,11 @@ jobs: uses: davelosert/vitest-coverage-report-action@v2 with: json-summary-compare-path: main-coverage/coverage-summary.json + file-coverage-mode: all - name: Report Coverage (only PR) if: steps.get-main-coverage.conclusion == 'failure' || steps.get-main-coverage.conclusion == 'skipped' uses: davelosert/vitest-coverage-report-action@v2 + with: + file-coverage-mode: all outputs: actualResult: ${{ steps.test.conclusion }} diff --git a/lib/lambda/processEmailsHandler.test.ts b/lib/lambda/processEmailsHandler.test.ts index c8e92d4c0..f8345ec18 100644 --- a/lib/lambda/processEmailsHandler.test.ts +++ b/lib/lambda/processEmailsHandler.test.ts @@ -11,6 +11,8 @@ import { WITHDRAW_RAI_ITEM_C, NOT_FOUND_ITEM_ID, WITHDRAW_EMAIL_SENT, + WITHDRAW_RAI_ITEM_D, + WITHDRAW_RAI_ITEM_E, } from "mocks"; const nms = "new-medicaid-submission"; const ncs = "new-chip-submission"; @@ -20,7 +22,6 @@ const contractingInitial = "contracting-initial"; const capitatedInitial = "capitated-initial"; const withdrawRai = "withdraw-rai"; const respondToRai = "respond-to-rai"; -const appk = "app-k"; const uploadSubsequentDocuments = "upload-subsequent-documents"; describe("process emails Handler", () => { @@ -127,12 +128,6 @@ describe("process emails Handler", () => { withdrawPackage, SIMPLE_ID, ], - [ - `should send an email for ${appk} with ${Authority["1915c"]}`, - Authority["1915c"], - appk, - SIMPLE_ID, - ], [ `should send an email for ${contractingInitial} with ${Authority.MED_SPA}`, Authority.MED_SPA, @@ -175,18 +170,6 @@ describe("process emails Handler", () => { capitatedInitial, SIMPLE_ID, ], - [ - `should send an email for ${appk} with ${Authority["1915c"]}`, - Authority["1915c"], - appk, - SIMPLE_ID, - ], - [ - `should send an email for ${appk} with ${Authority["1915b"]}`, - Authority["1915b"], - appk, - SIMPLE_ID, - ], [ `should send an email for ${withdrawRai} with ${Authority["1915b"]}`, Authority["1915b"], @@ -199,6 +182,18 @@ describe("process emails Handler", () => { withdrawRai, WITHDRAW_RAI_ITEM_C, ], + [ + `should send an email for ${withdrawRai} with ${Authority["CHIP_SPA"]}`, + Authority["CHIP_SPA"], + withdrawRai, + WITHDRAW_RAI_ITEM_D, + ], + [ + `should send an email for ${withdrawRai} with ${Authority["MED_SPA"]}`, + Authority["MED_SPA"], + withdrawRai, + WITHDRAW_RAI_ITEM_E, + ], [ `should send an email for ${uploadSubsequentDocuments} with ${Authority.CHIP_SPA}`, Authority.CHIP_SPA, @@ -244,15 +239,13 @@ describe("process emails Handler", () => { describe("process emails Handler failures", () => { it.each([ [ - `should send an email for ${withdrawRai} with ${Authority["1915b"]} and fail due to not finding it`, + `should send an email for ${withdrawRai} with ${Authority["1915b"]}`, Authority["1915b"], - withdrawRai, SIMPLE_ID, ], [ - `should send an email for ${withdrawRai} with ${Authority["1915c"]} and fail due to not finding it`, + `should send an email for ${withdrawRai} with ${Authority["1915c"]}`, Authority["1915c"], - withdrawRai, SIMPLE_ID, ], ])("%s", async (_, auth, eventType, id = SIMPLE_ID) => { @@ -283,7 +276,6 @@ describe("process emails Handler failures", () => { await expect(() => handler(mockEvent, {} as Context, callback)).rejects.toThrow(); }); }); - const seatoolData = (authority: string) => ({ ACTION_OFFICERS: [ { diff --git a/lib/lambda/search.test.ts b/lib/lambda/search.test.ts index 5368697e6..7f0edefa1 100644 --- a/lib/lambda/search.test.ts +++ b/lib/lambda/search.test.ts @@ -29,7 +29,7 @@ describe("getSearchData Handler", () => { const body = JSON.parse(res.body); expect(body).toBeTruthy(); expect(body?.hits?.hits).toBeTruthy(); - expect(body?.hits?.hits?.length).toEqual(22); + expect(body?.hits?.hits?.length).toEqual(24); }); it("should handle errors during processing", async () => { diff --git a/lib/libs/email/content/email-components.tsx b/lib/libs/email/content/email-components.tsx index 903fbdf57..428eb9029 100644 --- a/lib/libs/email/content/email-components.tsx +++ b/lib/libs/email/content/email-components.tsx @@ -3,7 +3,6 @@ import { ReactNode } from "react"; import { Attachment, AttachmentKey, - AttachmentTitle, CommonEmailVariables, EmailAddresses, Events, @@ -27,10 +26,9 @@ interface AttachmentGroup { } const areAllAttachmentsEmpty = ( - attachments: Partial>, + attachments: Partial>, ): boolean => { - if (!attachments) return true; - return Object.values(attachments).every((att) => !att || att.files?.length === 0); + return Object.values(attachments).every((att) => !att || !att.files || att.files.length === 0); }; const Divider = () =>
; @@ -288,32 +286,16 @@ const BasicFooter = () => ( export interface WithdrawRAIProps { variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }; - relatedEvent: Events["RespondToRai"]; } -const WithdrawRAI: React.FC = ({ variables, relatedEvent }) => { - if (!relatedEvent) { - return ( -
- - The OneMAC Submission Portal received a request to withdraw the Formal RAI Response. You - are receiving this email notification as the Formal RAI was withdrawn by{" "} - {variables.submitterName} {variables.submitterEmail}. - - - Note: The original RAI response details could not be retrieved. - -
- ); - } - +const WithdrawRAI: React.FC = ({ variables }) => { return (
- - The OneMAC Submission Portal received a request to withdraw the Formal RAI Response{" "} - {relatedEvent.id}. You are receiving this email notification as the Formal RAI for{" "} - {relatedEvent.id} was withdrawn by {variables.submitterName} {variables.submitterEmail}. - + + The OneMAC Submission Portal received a request to withdraw the Formal RAI Response. You are + are receiving this email notification as the Formal RAI for {variables.id} was withdrawn by{" "} + {variables.submitterName} {variables.submitterEmail}. +
); }; @@ -384,4 +366,5 @@ export { EmailFooter, getCpocEmail, getSrtEmails, + areAllAttachmentsEmpty, }; diff --git a/lib/libs/email/content/withdrawRai/emailComponents.test.tsx b/lib/libs/email/content/withdrawRai/emailComponents.test.tsx new file mode 100644 index 000000000..69d2c074e --- /dev/null +++ b/lib/libs/email/content/withdrawRai/emailComponents.test.tsx @@ -0,0 +1,67 @@ +import { render, screen } from "@testing-library/react"; +import { expect, test, vi } from "vitest"; +import { + EMAIL_CONFIG, + areAllAttachmentsEmpty, + Textarea, + DetailsHeading, + getCpocEmail, +} from "../email-components"; + +// 🟢 Test EMAIL_CONFIG +test("EMAIL_CONFIG contains correct email addresses", () => { + expect(EMAIL_CONFIG.DEV_EMAIL).toBe("mako.stateuser+dev-to@gmail.com"); + expect(EMAIL_CONFIG.CHIP_EMAIL).toBe("CHIPSPASubmissionMailBox@cms.hhs.gov"); + expect(EMAIL_CONFIG.SPA_EMAIL).toBe("spa@cms.hhs.gov"); + expect(EMAIL_CONFIG.SPAM_EMAIL).toBe("SPAM@cms.hhs.gov"); +}); + +// 🟢 Test areAllAttachmentsEmpty +test("areAllAttachmentsEmpty returns true for empty attachments", () => { + expect(areAllAttachmentsEmpty({})).toBe(true); + expect(areAllAttachmentsEmpty({ title1: undefined })).toBe(true); // + expect(areAllAttachmentsEmpty({ title2: { label: "Test", files: [] } })).toBe(true); +}); + +test("areAllAttachmentsEmpty returns false when at least one attachment contains files", () => { + expect( + areAllAttachmentsEmpty({ + title1: { + label: "Test", + files: [ + { + key: "12345", + filename: "file1.pdf", + title: "Document Title", + bucket: "my-bucket", + uploadDate: 1700000000, + }, + ], + }, + }), + ).toBe(false); +}); + +// 🟢 Test Textarea Component +test("renders Textarea component with children", () => { + render(); + expect(screen.getByText("This is a test")).toBeTruthy(); +}); + +// 🟢 Test DetailsHeading Component +test("renders DetailsHeading with correct text", () => { + render(); + expect(screen.getByText("Details:")).toBeTruthy(); +}); + +// 🟢 Test getCpocEmail +test("returns an empty array and logs error when an exception occurs in getCpocEmail", () => { + const consoleErrorMock = vi.spyOn(console, "error").mockImplementation(() => {}); + + const result = getCpocEmail(undefined); + + expect(result).toEqual([]); + expect(console.error).toHaveBeenCalled(); + + consoleErrorMock.mockRestore(); +}); diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/AppKCMS.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/AppKCMS.tsx deleted file mode 100644 index b03926e93..000000000 --- a/lib/libs/email/content/withdrawRai/emailTemplates/AppKCMS.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { CommonEmailVariables, EmailAddresses, Events } from "shared-types"; -import { Attachments, PackageDetails, BasicFooter } from "../../email-components"; -import { BaseEmailTemplate } from "../../email-templates"; - -export const AppKCMSEmail = ({ - variables, - relatedEvent, -}: { - variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }; - relatedEvent: Events["RespondToRai"]; -}) => { - const previewText = `Withdraw Formal RAI Response for Waiver Package ${relatedEvent.id}`; - const heading = `The OneMAC Submission Portal received a request to withdraw the Formal RAI Response. You are receiving this email notification as the Formal RAI for ${relatedEvent.id} was withdrawn by ${variables.submitterName} ${variables.submitterEmail}.`; - return ( - } - > - - - - ); -}; diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/AppKState.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/AppKState.tsx deleted file mode 100644 index 231639efc..000000000 --- a/lib/libs/email/content/withdrawRai/emailTemplates/AppKState.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { - PackageDetails, - BasicFooter, - MailboxNotice, - FollowUpNotice, - WithdrawRAI, -} from "../../email-components"; -import { BaseEmailTemplate } from "../../email-templates"; -import { CommonEmailVariables, EmailAddresses, Events } from "shared-types"; - -export const AppKStateEmail = ({ - variables, - relatedEvent, -}: { - variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }; - relatedEvent: Events["RespondToRai"]; -}) => { - const previewText = `Withdraw Formal RAI Response for Waiver Package ${relatedEvent.id}`; - const heading = `The OneMAC Submission Portal received a request to withdraw the Formal RAI Response. You are receiving this email notification as the Formal RAI for ${relatedEvent.id} was withdrawn by ${variables.submitterName} ${variables.submitterEmail}.`; - return ( - } - > - - - - - - ); -}; diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/ChipSPACMS.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/ChipSPACMS.tsx new file mode 100644 index 000000000..082b25b0f --- /dev/null +++ b/lib/libs/email/content/withdrawRai/emailTemplates/ChipSPACMS.tsx @@ -0,0 +1,28 @@ +import { CommonEmailVariables, Events } from "shared-types"; +import { Attachments, BasicFooter, Divider, PackageDetails } from "../../email-components"; +import { BaseEmailTemplate } from "../../email-templates"; + +export const ChipSpaCMSEmail = ({ + variables, +}: { + variables: Events["WithdrawRai"] & CommonEmailVariables; +}) => ( + } + > + + + + +); diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/ChipSPAState.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/ChipSPAState.tsx new file mode 100644 index 000000000..1bcab475d --- /dev/null +++ b/lib/libs/email/content/withdrawRai/emailTemplates/ChipSPAState.tsx @@ -0,0 +1,28 @@ +import { CommonEmailVariables, Events } from "shared-types"; +import { FollowUpNotice, BasicFooter, Divider, PackageDetails } from "../../email-components"; +import { BaseEmailTemplate } from "../../email-templates"; + +export const ChipSpaStateEmail = ({ + variables, +}: { + variables: Events["WithdrawRai"] & CommonEmailVariables; +}) => ( + } + > + + + + +); diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/MedSPACMS.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/MedSPACMS.tsx new file mode 100644 index 000000000..8548f6940 --- /dev/null +++ b/lib/libs/email/content/withdrawRai/emailTemplates/MedSPACMS.tsx @@ -0,0 +1,28 @@ +import { CommonEmailVariables, Events } from "shared-types"; +import { Attachments, PackageDetails, BasicFooter, Divider } from "../../email-components"; +import { BaseEmailTemplate } from "../../email-templates"; + +export const MedSpaCMSEmail = ({ + variables, +}: { + variables: Events["WithdrawRai"] & CommonEmailVariables; +}) => ( + } + > + + + + +); diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/MedSpaState.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/MedSpaState.tsx new file mode 100644 index 000000000..a381bc268 --- /dev/null +++ b/lib/libs/email/content/withdrawRai/emailTemplates/MedSpaState.tsx @@ -0,0 +1,28 @@ +import { CommonEmailVariables, Events } from "shared-types"; +import { PackageDetails, FollowUpNotice, BasicFooter, Divider } from "../../email-components"; +import { BaseEmailTemplate } from "../../email-templates"; + +export const MedSpaStateEmail = ({ + variables, +}: { + variables: Events["WithdrawRai"] & CommonEmailVariables; +}) => ( + } + > + + + + +); diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/Waiver1915bState.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/Waiver1915bState.tsx deleted file mode 100644 index d2f41403c..000000000 --- a/lib/libs/email/content/withdrawRai/emailTemplates/Waiver1915bState.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { CommonEmailVariables, EmailAddresses, Events } from "shared-types"; -import { WithdrawRAI, PackageDetails, FollowUpNotice, MailboxNotice } from "../../email-components"; -import { BaseEmailTemplate } from "../../email-templates"; - -export const Waiver1915bStateEmail = ({ - variables, - relatedEvent, -}: { - variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }; - relatedEvent: Events["RespondToRai"]; -}) => { - const previewText = `Waiver ${relatedEvent.id} Withdrawn`; - const heading = "This response confirms you have withdrawn a Waiver from CMS for review"; - return ( - } - > - - - - - ); -}; diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/WaiverCMS.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/WaiverCMS.tsx new file mode 100644 index 000000000..882448cc4 --- /dev/null +++ b/lib/libs/email/content/withdrawRai/emailTemplates/WaiverCMS.tsx @@ -0,0 +1,28 @@ +import { CommonEmailVariables, Events, EmailAddresses } from "shared-types"; +import { WithdrawRAI, Attachments, PackageDetails, BasicFooter } from "../../email-components"; +import { BaseEmailTemplate } from "../../email-templates"; + +export const WaiverCMSEmail = ({ + variables, +}: { + variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }; +}) => ( + } + > + + + + +); diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/Waiver1915bCMS.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/WaiverState.tsx similarity index 61% rename from lib/libs/email/content/withdrawRai/emailTemplates/Waiver1915bCMS.tsx rename to lib/libs/email/content/withdrawRai/emailTemplates/WaiverState.tsx index 18e049e21..30837dc50 100644 --- a/lib/libs/email/content/withdrawRai/emailTemplates/Waiver1915bCMS.tsx +++ b/lib/libs/email/content/withdrawRai/emailTemplates/WaiverState.tsx @@ -1,25 +1,26 @@ import { CommonEmailVariables, Events, EmailAddresses } from "shared-types"; -import { WithdrawRAI, PackageDetails, BasicFooter } from "../../email-components"; +import { + WithdrawRAI, + FollowUpNotice, + BasicFooter, + PackageDetails, + MailboxNotice, +} from "../../email-components"; import { BaseEmailTemplate } from "../../email-templates"; -export const Waiver1915bCMSEmail = ({ +export const WaiverStateEmail = ({ variables, - relatedEvent, }: { variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }; - relatedEvent: Events["RespondToRai"]; }) => { - const previewText = `Waiver Package ${relatedEvent.id} withdrawn`; - const heading = `Withdraw Formal RAI Response for Waiver Package ${relatedEvent.id}`; - return ( } > - + + + ); }; diff --git a/lib/libs/email/content/withdrawRai/emailTemplates/index.tsx b/lib/libs/email/content/withdrawRai/emailTemplates/index.tsx index 669a42403..0d4a60b3b 100644 --- a/lib/libs/email/content/withdrawRai/emailTemplates/index.tsx +++ b/lib/libs/email/content/withdrawRai/emailTemplates/index.tsx @@ -1,4 +1,6 @@ -export { AppKCMSEmail } from "./AppKCMS"; -export { AppKStateEmail } from "./AppKState"; -export { Waiver1915bCMSEmail } from "./Waiver1915bCMS"; -export { Waiver1915bStateEmail } from "./Waiver1915bState"; +export { WaiverCMSEmail } from "./WaiverCMS"; +export { WaiverStateEmail } from "./WaiverState"; +export { MedSpaCMSEmail } from "./MedSPACMS"; +export { MedSpaStateEmail } from "./MedSpaState"; +export { ChipSpaCMSEmail } from "./ChipSPACMS"; +export { ChipSpaStateEmail } from "./ChipSPAState"; diff --git a/lib/libs/email/content/withdrawRai/index.tsx b/lib/libs/email/content/withdrawRai/index.tsx index a8e34e6a4..35a28e2cb 100644 --- a/lib/libs/email/content/withdrawRai/index.tsx +++ b/lib/libs/email/content/withdrawRai/index.tsx @@ -1,151 +1,114 @@ import { CommonEmailVariables, EmailAddresses, Events, Authority } from "shared-types"; -import { AuthoritiesWithUserTypesTemplate, getLatestMatchingEvent } from "../.."; -import { Waiver1915bCMSEmail, Waiver1915bStateEmail, AppKCMSEmail } from "./emailTemplates"; +import { AuthoritiesWithUserTypesTemplate } from "../.."; +import { + MedSpaCMSEmail, + MedSpaStateEmail, + ChipSpaCMSEmail, + ChipSpaStateEmail, + WaiverCMSEmail, + WaiverStateEmail, +} from "./emailTemplates"; import { render } from "@react-email/render"; -import { EmailProcessingError } from "libs/email/errors"; - -const getWithdrawRaiEvent = async (id: string) => { - const event = await getLatestMatchingEvent(id, "withdraw-rai"); - - if (!event) { - return null; - } - - return event; -}; export const withdrawRai: AuthoritiesWithUserTypesTemplate = { + [Authority.MED_SPA]: { + cms: async ( + variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }, + ) => { + return { + to: variables.emails.osgEmail, + cc: variables.emails.dpoEmail, + subject: `Withdraw Formal RAI Response for SPA Package ${variables.id}`, + body: await render(), + }; + }, + state: async ( + variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }, + ) => { + return { + to: [`${variables.submitterName} <${variables.submitterEmail}>`], + subject: `Withdraw Formal RAI Response for SPA Package ${variables.id}`, + body: await render(), + }; + }, + }, + [Authority.CHIP_SPA]: { + cms: async ( + variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }, + ) => { + return { + to: [...variables.emails.cpocEmail, ...variables.emails.srtEmails], + cc: variables.emails.chipCcList, + subject: `Withdraw Formal RAI Response for CHIP SPA Package ${variables.id}`, + body: await render(), + }; + }, + state: async ( + variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }, + ) => { + return { + to: [ + ...variables.emails.cpocEmail, + ...variables.emails.srtEmails, + `${variables.submitterName} <${variables.submitterEmail}>`, + ], + cc: variables.emails.chipCcList, + subject: `Withdraw Formal RAI Response for CHIP SPA Package ${variables.id}`, + body: await render(), + }; + }, + }, [Authority["1915b"]]: { cms: async ( variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }, ) => { - try { - const relatedEvent = (await getLatestMatchingEvent( - variables.id, - "respond-to-rai", - )) as unknown as Events["RespondToRai"]; - if (!relatedEvent) { - throw new EmailProcessingError( - `Failed to find original RAI response event for withdrawal (ID: ${variables.id})`, - { - id: variables.id, - actionType: "RespondToRai", - emailType: "withdrawRai", - severity: "ERROR", - }, - ); - } - return { - to: [ - ...variables.emails.dmcoEmail, - ...variables.emails.osgEmail, - ...variables.emails.cpocEmail, - ...variables.emails.srtEmails, - ], - subject: `Withdraw Formal RAI Response for Waiver Package ${variables.id}`, - body: await render( - , - ), - }; - } catch (error) { - console.error(error); - throw error; - } + return { + to: [ + ...variables.emails.dmcoEmail, + ...variables.emails.osgEmail, + ...variables.emails.cpocEmail, + ...variables.emails.srtEmails, + ], + subject: `Withdraw Formal RAI Response for Waiver Package ${variables.id}`, + body: await render(), + }; }, state: async ( variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }, ) => { - try { - const relatedEvent = (await getLatestMatchingEvent( - variables.id, - "respond-to-rai", - )) as unknown as Events["RespondToRai"]; - if (!relatedEvent) { - throw new EmailProcessingError( - `Failed to find original RAI response event for withdrawal (ID: ${variables.id})`, - { - id: variables.id, - actionType: "RespondToRai", - emailType: "withdrawRai", - severity: "ERROR", - }, - ); - } - return { - to: variables.allStateUsersEmails || [], - subject: `Withdraw Formal RAI Response for Waiver Package ${variables.id}`, - body: await render( - , - ), - }; - } catch (error) { - console.error(error); - throw error; - } + return { + to: variables.allStateUsersEmails?.length + ? variables.allStateUsersEmails + : [`${variables.submitterName} <${variables.submitterEmail}>`], + subject: `Withdraw Formal RAI Response for Waiver Package ${variables.id}`, + body: await render(), + }; }, }, [Authority["1915c"]]: { cms: async ( variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }, ) => { - try { - const relatedEvent = (await getLatestMatchingEvent( - variables.id, - "respond-to-rai", - )) as unknown as Events["RespondToRai"]; - if (!relatedEvent) { - throw new EmailProcessingError( - `Failed to find original RAI response event for withdrawal (ID: ${variables.id})`, - { - id: variables.id, - actionType: "RespondToRai", - emailType: "withdrawRai", - severity: "ERROR", - }, - ); - } - return { - to: [ - ...variables.emails.osgEmail, - ...variables.emails.dhcbsooEmail, - ...variables.emails.cpocEmail, - ...variables.emails.srtEmails, - ], - subject: `Withdraw Formal RAI Response for Waiver Package ${relatedEvent.id}`, - body: await render(), - }; - } catch (error) { - console.error(error); - throw error; - } + return { + to: [ + ...variables.emails.osgEmail, + ...variables.emails.cpocEmail, + ...variables.emails.srtEmails, + ], + subject: `Withdraw Formal RAI Response for Waiver Package ${variables.id}`, + body: await render(), + }; }, state: async ( variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses }, ) => { - try { - const relatedEvent = await getWithdrawRaiEvent(variables.id); - if (!relatedEvent) { - throw new EmailProcessingError( - `Failed to find original RAI response event for withdrawal (ID: ${variables.id})`, - { - id: variables.id, - actionType: "RespondToRai", - emailType: "withdrawRai", - severity: "ERROR", - }, - ); - } - return { - to: variables.allStateUsersEmails || [], - subject: `Withdraw Formal RAI Response for Waiver Package ${relatedEvent.id}`, - body: await render( - , - ), - }; - } catch (error) { - console.error(error); - throw error; - } + return { + to: variables.allStateUsersEmails?.length + ? variables.allStateUsersEmails + : [`${variables.submitterName} <${variables.submitterEmail}>`], + subject: `Waiver Package ${variables.id} Withdraw Request`, + body: await render(), + }; }, }, }; diff --git a/lib/packages/shared-types/events/capitated-renewal.ts b/lib/packages/shared-types/events/capitated-renewal.ts index ecad383ac..0fffe6e7f 100644 --- a/lib/packages/shared-types/events/capitated-renewal.ts +++ b/lib/packages/shared-types/events/capitated-renewal.ts @@ -13,14 +13,6 @@ export const baseSchema = z.object({ }), proposedEffectiveDate: z.number(), attachments: z.object({ - bCapIndependentAssessment: z.object({ - label: z - .string() - .default( - "1915(b) Comprehensive (Capitated) Waiver Independent Assessment (first two renewals only)", - ), - files: attachmentArraySchemaOptional(), - }), bCapWaiverApplication: z.object({ label: z.string().default("1915(b) Comprehensive (Capitated) Waiver Application Pre-print"), files: attachmentArraySchema(), @@ -31,6 +23,14 @@ export const baseSchema = z.object({ .default("1915(b) Comprehensive (Capitated) Waiver Cost Effectiveness Spreadsheets"), files: attachmentArraySchema(), }), + bCapIndependentAssessment: z.object({ + label: z + .string() + .default( + "1915(b) Comprehensive (Capitated) Waiver Independent Assessment (first two renewals only)", + ), + files: attachmentArraySchemaOptional(), + }), tribalConsultation: z.object({ label: z.string().default("Tribal Consultation"), files: attachmentArraySchemaOptional(), diff --git a/mocks/data/items.ts b/mocks/data/items.ts index 042d5783a..c230b4be4 100644 --- a/mocks/data/items.ts +++ b/mocks/data/items.ts @@ -40,6 +40,8 @@ export const SUBMISSION_ERROR_ITEM_ID = "Throw Submission Error"; export const GET_ERROR_ITEM_ID = "Throw Get Item Error"; export const WITHDRAW_RAI_ITEM_B = "VA-2234.R11.02"; export const WITHDRAW_RAI_ITEM_C = "VA-2234.R11.03"; +export const WITHDRAW_RAI_ITEM_D = "VA-12-2020"; +export const WITHDRAW_RAI_ITEM_E = "MD-13-2020"; const items: Record = { [EXISTING_ITEM_ID]: { @@ -950,6 +952,76 @@ const items: Record = { ], }, }, + [WITHDRAW_RAI_ITEM_D]: { + _id: WITHDRAW_RAI_ITEM_D, + found: true, + _source: { + id: WITHDRAW_RAI_ITEM_D, + seatoolStatus: SEATOOL_STATUS.PENDING_RAI, + stateStatus: statusToDisplayToStateUser[SEATOOL_STATUS.PENDING_RAI], + cmsStatus: statusToDisplayToCmsUser[SEATOOL_STATUS.PENDING_RAI], + actionType: "respond-to-rai", + raiRequestedDate: "2024-01-01T00:00:00.000Z", + authority: "CHIP SPA", + state: "VA", + leadAnalystName: "lead test", + leadAnalystEmail: "Lead test email", + reviewTeam: [ + { + name: "Test", + email: "testemail", + }, + ], + origin: "OneMAC", + changelog: [ + { + _id: `${WITHDRAW_RAI_ITEM_D}-001`, + _source: { + id: `${WITHDRAW_RAI_ITEM_D}-0001`, + submitterName: "Testmctex", + submitterEmail: "fakeemail;", + event: "respond-to-rai", + packageId: WITHDRAW_RAI_ITEM_C, + }, + }, + ], + }, + }, + [WITHDRAW_RAI_ITEM_E]: { + _id: WITHDRAW_RAI_ITEM_E, + found: true, + _source: { + id: WITHDRAW_RAI_ITEM_E, + seatoolStatus: SEATOOL_STATUS.PENDING_RAI, + stateStatus: statusToDisplayToStateUser[SEATOOL_STATUS.PENDING_RAI], + cmsStatus: statusToDisplayToCmsUser[SEATOOL_STATUS.PENDING_RAI], + actionType: "respond-to-rai", + raiRequestedDate: "2024-01-01T00:00:00.000Z", + authority: "Medicaid SPA", + state: "VA", + leadAnalystName: "lead test", + leadAnalystEmail: "Lead test email", + reviewTeam: [ + { + name: "Test", + email: "testemail", + }, + ], + origin: "OneMAC", + changelog: [ + { + _id: `${WITHDRAW_RAI_ITEM_E}-001`, + _source: { + id: `${WITHDRAW_RAI_ITEM_E}-0001`, + submitterName: "Testmctex", + submitterEmail: "fakeemail;", + event: "respond-to-rai", + packageId: WITHDRAW_RAI_ITEM_C, + }, + }, + ], + }, + }, [EXISTING_ITEM_APPROVED_APPK_ITEM_ID]: { _id: EXISTING_ITEM_APPROVED_APPK_ITEM_ID, found: true, diff --git a/mocks/data/submit/changelog.ts b/mocks/data/submit/changelog.ts index 5626abb6b..a3e114d57 100644 --- a/mocks/data/submit/changelog.ts +++ b/mocks/data/submit/changelog.ts @@ -47,9 +47,9 @@ export const capitatedRenewal = { authority: "1915(c)", proposedEffectiveDate: 1700000000, attachments: { - ...attachments.bCapIndependentAssessment, ...attachments.bCapWaiverApplication, ...attachments.bCapCostSpreadsheets, + ...attachments.bCapIndependentAssessment, ...attachments.tribalConsultation, ...attachments.other, },