Skip to content

Commit

Permalink
Merge pull request #1143 from Enterprise-CMCS/main
Browse files Browse the repository at this point in the history
Release to val
  • Loading branch information
RanyeM authored Feb 7, 2025
2 parents 3bdd900 + 5a176c9 commit 00f6133
Show file tree
Hide file tree
Showing 19 changed files with 425 additions and 308 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/pr-coverage-annotation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
40 changes: 16 additions & 24 deletions lib/lambda/processEmailsHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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", () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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"],
Expand All @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -283,7 +276,6 @@ describe("process emails Handler failures", () => {
await expect(() => handler(mockEvent, {} as Context, callback)).rejects.toThrow();
});
});

const seatoolData = (authority: string) => ({
ACTION_OFFICERS: [
{
Expand Down
2 changes: 1 addition & 1 deletion lib/lambda/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
35 changes: 9 additions & 26 deletions lib/libs/email/content/email-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ReactNode } from "react";
import {
Attachment,
AttachmentKey,
AttachmentTitle,
CommonEmailVariables,
EmailAddresses,
Events,
Expand All @@ -27,10 +26,9 @@ interface AttachmentGroup {
}

const areAllAttachmentsEmpty = (
attachments: Partial<Record<AttachmentTitle, AttachmentGroup | null>>,
attachments: Partial<Record<string, { label: string; files?: any[] }>>,
): 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 = () => <Hr style={styles.divider} />;
Expand Down Expand Up @@ -288,32 +286,16 @@ const BasicFooter = () => (

export interface WithdrawRAIProps {
variables: Events["WithdrawRai"] & CommonEmailVariables & { emails: EmailAddresses };
relatedEvent: Events["RespondToRai"];
}

const WithdrawRAI: React.FC<WithdrawRAIProps> = ({ variables, relatedEvent }) => {
if (!relatedEvent) {
return (
<Section>
<Heading as="h2">
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}.
</Heading>
<Text style={styles.text.description}>
Note: The original RAI response details could not be retrieved.
</Text>
</Section>
);
}

const WithdrawRAI: React.FC<WithdrawRAIProps> = ({ variables }) => {
return (
<Section>
<Heading as="h2">
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}.
</Heading>
<Text>
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}.
</Text>
</Section>
);
};
Expand Down Expand Up @@ -384,4 +366,5 @@ export {
EmailFooter,
getCpocEmail,
getSrtEmails,
areAllAttachmentsEmpty,
};
67 changes: 67 additions & 0 deletions lib/libs/email/content/withdrawRai/emailComponents.test.tsx
Original file line number Diff line number Diff line change
@@ -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("[email protected]");
expect(EMAIL_CONFIG.CHIP_EMAIL).toBe("[email protected]");
expect(EMAIL_CONFIG.SPA_EMAIL).toBe("[email protected]");
expect(EMAIL_CONFIG.SPAM_EMAIL).toBe("[email protected]");
});

// 🟢 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(<Textarea>This is a test</Textarea>);
expect(screen.getByText("This is a test")).toBeTruthy();
});

// 🟢 Test DetailsHeading Component
test("renders DetailsHeading with correct text", () => {
render(<DetailsHeading />);
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();
});
33 changes: 0 additions & 33 deletions lib/libs/email/content/withdrawRai/emailTemplates/AppKCMS.tsx

This file was deleted.

41 changes: 0 additions & 41 deletions lib/libs/email/content/withdrawRai/emailTemplates/AppKState.tsx

This file was deleted.

28 changes: 28 additions & 0 deletions lib/libs/email/content/withdrawRai/emailTemplates/ChipSPACMS.tsx
Original file line number Diff line number Diff line change
@@ -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;
}) => (
<BaseEmailTemplate
previewText={`Withdraw Formal RAI Response for CHIP SPA Package ${variables.id}`}
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 ${variables.id} was withdrawn by ${variables.submitterName} ${variables.submitterEmail}.`}
applicationEndpointUrl={variables.applicationEndpointUrl}
footerContent={<BasicFooter />}
>
<Divider />
<PackageDetails
details={{
"State or Territory": variables.territory,
Name: variables.submitterName,
"Email Address": variables.submitterEmail,
"CHIP SPA Package ID": variables.id,
Summary: variables.additionalInformation,
}}
/>
<Attachments attachments={variables.attachments} />
</BaseEmailTemplate>
);
28 changes: 28 additions & 0 deletions lib/libs/email/content/withdrawRai/emailTemplates/ChipSPAState.tsx
Original file line number Diff line number Diff line change
@@ -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;
}) => (
<BaseEmailTemplate
previewText={`Withdraw Formal RAI Response for CHIP SPA Package ${variables.id}`}
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 ${variables.id} was withdrawn by ${variables.submitterName} ${variables.submitterEmail}.`}
applicationEndpointUrl={variables.applicationEndpointUrl}
footerContent={<BasicFooter />}
>
<Divider />
<PackageDetails
details={{
"State or Territory": variables.territory,
Name: variables.submitterName,
"Email Address": variables.submitterEmail,
"CHIP SPA Package ID": variables.id,
Summary: variables.additionalInformation,
}}
/>
<FollowUpNotice isChip />
</BaseEmailTemplate>
);
Loading

0 comments on commit 00f6133

Please sign in to comment.