Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(emails): Expand email sending functionality to all initial event emails #967

Open
wants to merge 86 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
e2f4b33
Update
benjaminpaige Dec 19, 2024
3db691e
merge main into head
benjaminpaige Dec 19, 2024
54cd2c2
fix test
benjaminpaige Dec 19, 2024
0db0fcf
update
benjaminpaige Dec 20, 2024
0bc5c12
fix snaps
benjaminpaige Dec 20, 2024
c10b1c0
Update
benjaminpaige Dec 20, 2024
10f4383
Updating ssnapshots
thwalker6 Dec 19, 2024
81b66a5
update vitest config to ignore emails folder, update snapshots
thwalker6 Dec 20, 2024
671a8c3
update date to a fixed number to avoid snapshot issues(hopefully)
thwalker6 Dec 20, 2024
f72bf54
remove yaml
benjaminpaige Dec 20, 2024
cad85f4
Correct upserting to the wrong index for every record.
benjaminpaige Dec 20, 2024
be30759
Update testing and sinking functionality
benjaminpaige Dec 20, 2024
296a670
Update
benjaminpaige Dec 20, 2024
d10b669
Update email mock data and event types
benjaminpaige Dec 23, 2024
4f8bb9f
update
benjaminpaige Dec 23, 2024
ce2017a
update import
benjaminpaige Dec 23, 2024
efc8cdb
update
benjaminpaige Dec 23, 2024
0ee297c
update
benjaminpaige Dec 23, 2024
1899683
update
benjaminpaige Dec 23, 2024
0ffbd95
update e2e
benjaminpaige Dec 23, 2024
388a95b
Correcting Everything
benjaminpaige Dec 24, 2024
5691310
Update
benjaminpaige Dec 26, 2024
b23f848
Update
benjaminpaige Dec 26, 2024
cae2273
Update
benjaminpaige Dec 26, 2024
5e8f348
update testing strategy
benjaminpaige Dec 26, 2024
d0855f7
fix lib tests
benjaminpaige Dec 29, 2024
c5e2775
Add emails to testing workspace
benjaminpaige Dec 29, 2024
e53493a
small update
benjaminpaige Dec 30, 2024
c9997b2
work on e2e tests
benjaminpaige Dec 30, 2024
eb7f08f
cleanup
benjaminpaige Dec 30, 2024
939033c
Update workflow
benjaminpaige Dec 30, 2024
e9365ca
more adjustments
benjaminpaige Dec 30, 2024
812737a
e2e update
benjaminpaige Dec 31, 2024
2395a4d
Update
benjaminpaige Dec 31, 2024
5a27009
update e2e
benjaminpaige Dec 31, 2024
e0c6654
update tests
benjaminpaige Dec 31, 2024
db25c7a
Update
benjaminpaige Dec 31, 2024
dbd6c84
Update
benjaminpaige Dec 31, 2024
2e583a0
Update
benjaminpaige Dec 31, 2024
741c6d0
Update
benjaminpaige Dec 31, 2024
bca9964
Update
benjaminpaige Dec 31, 2024
85f1fb6
Update
benjaminpaige Dec 31, 2024
15e0896
Update
benjaminpaige Dec 31, 2024
6f8f1f8
Update
benjaminpaige Dec 31, 2024
64c9c3a
Update
benjaminpaige Dec 31, 2024
7fca894
Update
benjaminpaige Dec 31, 2024
3a82815
update e2e testing env vars
benjaminpaige Dec 31, 2024
0b852e5
update e2e packages
benjaminpaige Dec 31, 2024
714a99d
Merge branch 'main' into emb-stable
benjaminpaige Dec 31, 2024
0323d63
update
benjaminpaige Dec 31, 2024
8c37800
update
benjaminpaige Dec 31, 2024
ed0ff66
update
benjaminpaige Dec 31, 2024
c895e9d
update
benjaminpaige Dec 31, 2024
a85c196
update
benjaminpaige Dec 31, 2024
1329c88
update
benjaminpaige Dec 31, 2024
69ec6e8
think im going crazy
benjaminpaige Dec 31, 2024
36ec17c
update
benjaminpaige Jan 2, 2025
e04c779
update
benjaminpaige Jan 2, 2025
42bbb15
update
benjaminpaige Jan 2, 2025
7a47eb3
update
benjaminpaige Jan 2, 2025
c822d90
update
benjaminpaige Jan 2, 2025
73ac603
fix: banner not showing up on package actions page (#957)
asharonbaltazar Dec 31, 2024
3384cb2
feature (ui): Add an MMDL Notification Banner on Mako Homepage (#925)
RanyeM Dec 31, 2024
12dffd1
updatesnapshots (#962)
tiffanyvu Dec 31, 2024
8e93f31
feat(withdrawal-confirmation): medicaid and chip spa state withdrawal…
jdinh8124 Dec 31, 2024
d275afe
update
benjaminpaige Jan 2, 2025
54b9588
update tomb bug
benjaminpaige Jan 2, 2025
3a7fddd
Merge main into head
benjaminpaige Jan 3, 2025
c4c1c11
update
benjaminpaige Jan 3, 2025
4102e15
Update
benjaminpaige Jan 3, 2025
b106052
Update
benjaminpaige Jan 3, 2025
df68e07
Update
benjaminpaige Jan 3, 2025
291db79
Update
benjaminpaige Jan 3, 2025
e034324
Pivot from previous email path
benjaminpaige Jan 3, 2025
6671035
Update package
benjaminpaige Jan 3, 2025
b535756
reset core function from main
benjaminpaige Jan 3, 2025
154743f
updated with main, removed unused code/mocks
benjaminpaige Jan 4, 2025
8453c5e
Merge branch 'main' into eco
benjaminpaige Jan 4, 2025
df667a6
fix email preview types and adjust remaining content properties
benjaminpaige Jan 4, 2025
c0b31cc
Updated email content and snapshot tests
benjaminpaige Jan 4, 2025
889cf07
Finalize tests and see if we can get all tests running
benjaminpaige Jan 4, 2025
2c4b662
Update
benjaminpaige Jan 4, 2025
6d9e2dd
update additional items from main
benjaminpaige Jan 6, 2025
ae944c6
revert test dir
benjaminpaige Jan 6, 2025
ffccd7b
adjust scripts and change bun back
benjaminpaige Jan 6, 2025
4ae80ae
up event emitters
benjaminpaige Jan 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/lambda/getCpocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const queryCpocs = async () => {
};
return await os.search(
process.env.osDomain,
`${process.env.indexNamespace}cpocs`,
`${process.env.indexNamespace ?? ""}cpocs`,
query,
);
};
Expand Down
1 change: 0 additions & 1 deletion lib/lambda/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export * as getPackageActions from "./getPackageActions";
export * as getSubTypes from "./getSubTypes";
export * as getTypes from "./getTypes";
export * as getUploadUrl from "./getUploadUrl";
export * as mapRole from "./mapRole";
export * as processEmails from "./processEmails";
export * as runReindex from "./runReindex";
export * as search from "./search";
Expand Down
117 changes: 0 additions & 117 deletions lib/lambda/mapRole.test.ts

This file was deleted.

28 changes: 0 additions & 28 deletions lib/lambda/mapRole.ts

This file was deleted.

207 changes: 207 additions & 0 deletions lib/lambda/processEmails.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { handler } from "./processEmails";
import { SESClient } from "@aws-sdk/client-ses";
import { SQSClient } from "@aws-sdk/client-sqs";
import * as os from "../libs/opensearch-lib";
import { EMAIL_CONFIG } from "../libs/email/content/email-components";
import { getEmailTemplates } from "../libs/email";
import type { Context } from "aws-lambda";

vi.mock("libs/email", () => ({
getEmailTemplates: vi.fn().mockResolvedValue([
async () => ({
to: ["[email protected]"],
subject: "Test Subject",
body: "<p>Test Body</p>",
}),
]),
}));

describe("processEmails handler", () => {
const mockEnv = {
emailAddressLookupSecretName: "test-secret", //pragma: allowlist secret
applicationEndpointUrl: "https://test.com",
osDomain: "test-domain",
indexNamespace: "test-",
region: "us-west-2",
DLQ_URL: "https://sqs.test.com",
userPoolId: "test-pool",
configurationSetName: "test-config",
isDev: "true",
};

const mockContext: Context = {
callbackWaitsForEmptyEventLoop: true,
functionName: "test",
functionVersion: "1",
invokedFunctionArn: "arn:test",
memoryLimitInMB: "128",
awsRequestId: "test",
logGroupName: "test",
logStreamName: "test",
getRemainingTimeInMillis: () => 1000,
done: () => {},
fail: () => {},
succeed: () => {},
};

const mockCallback = vi.fn();

beforeEach(() => {
Object.entries(mockEnv).forEach(([key, value]) => {
process.env[key] = value;
});

vi.spyOn(SESClient.prototype, "send").mockImplementation(() => Promise.resolve({} as any));
vi.spyOn(SQSClient.prototype, "send").mockImplementation(() => Promise.resolve({} as any));
vi.spyOn(os, "getItem").mockResolvedValue({
_index: "test",
_id: "test",
_score: 1,
sort: [],
_source: {
id: "test-id",
authority: "Test Authority",
email: "[email protected]",
reviewTeam: [{ name: "Test User", email: "[email protected]" }],
},
} as any);
});

afterEach(() => {
vi.clearAllMocks();
Object.keys(mockEnv).forEach((key) => {
delete process.env[key];
});
});

it.skip("should process valid Kafka records successfully", async () => {
const event = {
eventSource: "aws:kafka",
bootstrapServers: "test:9092",
records: {
"test-topic-0": [
{
key: Buffer.from("US123").toString("base64"),
value: Buffer.from(
JSON.stringify({
event: "test-event",
authority: "test-authority",
origin: "mako",
}),
).toString("base64"),
timestamp: 1234567890,
timestampType: "CREATE_TIME",
topic: "test-topic",
partition: 0,
offset: 0,
headers: [],
},
],
},
};

await handler(event as any, mockContext, mockCallback);

expect(getEmailTemplates).toHaveBeenCalledWith("test-event", "test-authority");
expect(SESClient.prototype.send).toHaveBeenCalled();
});

it("should skip processing for tombstone records", async () => {
const event = {
eventSource: "aws:kafka",
bootstrapServers: "test:9092",
records: {
"test-topic-0": [
{
key: Buffer.from("US123").toString("base64"),
value: null,
timestamp: 1234567890,
timestampType: "CREATE_TIME",
topic: "test-topic",
partition: 0,
offset: 0,
headers: [],
},
],
},
};

await handler(event as any, mockContext, mockCallback);

expect(getEmailTemplates).not.toHaveBeenCalled();
expect(SESClient.prototype.send).not.toHaveBeenCalled();
});

it.skip("should send to DLQ on permanent failure", async () => {
const mockSQSSend = vi.spyOn(SQSClient.prototype, "send");
delete process.env.emailAddressLookupSecretName;

const event = {
eventSource: "aws:kafka",
bootstrapServers: "test:9092",
records: {
"test-topic-0": [
{
key: Buffer.from("US123").toString("base64"),
value: Buffer.from(
JSON.stringify({
event: "test-event",
authority: "test-authority",
origin: "mako",
}),
).toString("base64"),
timestamp: 1234567890,
timestampType: "CREATE_TIME",
topic: "test-topic",
partition: 0,
offset: 0,
headers: [],
},
],
},
};

await expect(handler(event as any, mockContext, mockCallback)).rejects.toThrow();
expect(mockSQSSend).toHaveBeenCalled();
});

it.skip("should use DEV_EMAIL when in dev mode", async () => {
const event = {
eventSource: "aws:kafka",
bootstrapServers: "test:9092",
records: {
"test-topic-0": [
{
key: Buffer.from("US123").toString("base64"),
value: Buffer.from(
JSON.stringify({
event: "test-event",
authority: "test-authority",
origin: "mako",
}),
).toString("base64"),
timestamp: 1234567890,
timestampType: "CREATE_TIME",
topic: "test-topic",
partition: 0,
offset: 0,
headers: [],
},
],
},
};

await handler(event as any, mockContext, mockCallback);

expect(SESClient.prototype.send).toHaveBeenCalledWith(
expect.objectContaining({
input: expect.objectContaining({
Destination: expect.objectContaining({
ToAddresses: expect.arrayContaining([`State Submitter <${EMAIL_CONFIG.DEV_EMAIL}>`]),
}),
}),
}),
);
});
});
Loading
Loading