From e06a5c95c5e1bf1d5334f91589b024a80842412b Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 7 Jan 2025 13:02:50 -0500 Subject: [PATCH 1/7] feat(test)proces email test --- lib/lambda/processEmails.test.ts | 153 ++++++++++++++++++++ lib/lambda/processEmails.text.ts | 223 ----------------------------- lib/lambda/processEmails.ts | 2 +- lib/libs/email/getAllStateUsers.ts | 7 +- lib/vitest.setup.ts | 3 + mocks/data/items.ts | 23 ++- mocks/data/secrets.ts | 20 +++ mocks/handlers/aws/cognito.ts | 12 +- mocks/handlers/aws/email.ts | 35 +++++ mocks/handlers/aws/index.ts | 3 +- 10 files changed, 248 insertions(+), 233 deletions(-) create mode 100644 lib/lambda/processEmails.test.ts delete mode 100644 lib/lambda/processEmails.text.ts create mode 100644 mocks/handlers/aws/email.ts diff --git a/lib/lambda/processEmails.test.ts b/lib/lambda/processEmails.test.ts new file mode 100644 index 0000000000..e2f6fe5a1d --- /dev/null +++ b/lib/lambda/processEmails.test.ts @@ -0,0 +1,153 @@ +import { describe, it, expect, vi } from "vitest"; +import { Context } from "aws-lambda"; +import { SESClient } from "@aws-sdk/client-ses"; +import { sendEmail, validateEmailTemplate, handler } from "./processEmails"; +import { KafkaRecord, KafkaEvent } from "node_modules/shared-types"; + +describe("process emails Handler", () => { + it("should return 200 with a proper email", async () => { + const params = { + Source: "sender@example.com", + Destination: { ToAddresses: ["recipient@example.com"] }, + Message: { + Subject: { Data: "Mocked Email", Charset: "UTF-8" }, + Body: { Text: { Data: "This is a mocked email body.", Charset: "UTF-8" } }, + }, + }; + const test = await sendEmail(params, "us-east-1"); + expect(test.status).toStrictEqual(200); + }); + it("should throw an error", async () => { + const params = { + Source: "sender@example.com", + Destination: { ToAddresses: ["recipient@example.com"] }, + Message: { + Subject: { Data: "Mocked Email", Charset: "UTF-8" }, + Body: { Text: { Data: "This is a mocked email body.", Charset: "UTF-8" } }, + }, + }; + await expect(sendEmail(params, "test")).rejects.toThrowError(); + }); + it("should validate the email template and throw an error", async () => { + const template = { + to: "Person", + from: "Other Guy", + body: "body", + }; + expect(() => validateEmailTemplate(template)).toThrowError(); + }); + it("should make a handler", async () => { + const callback = vi.fn(); + const secSPY = vi.spyOn(SESClient.prototype, "send"); + const mockEvent: KafkaEvent = { + records: { + "mock-topic": [ + { + key: Buffer.from("VA").toString("base64"), + value: Buffer.from( + JSON.stringify({ + origin: "mako", + event: "new-medicaid-submission", + authority: "medicaid spa", + }), + ).toString("base64"), + headers: {}, + timestamp: 1732645041557, + offset: "0", + partition: 0, + topic: "mock-topic", + } as unknown as KafkaRecord, + ], + }, + eventSource: "", + bootstrapServers: "", + }; + + await handler(mockEvent, {} as Context, callback); + expect(secSPY).toHaveBeenCalledTimes(2); + // console.log(result); + }); + it("should not be mako therefor not do an event", async () => { + const callback = vi.fn(); + const mockEvent: KafkaEvent = { + records: { + "mock-topic": [ + { + key: Buffer.from("VA").toString("base64"), + value: Buffer.from( + JSON.stringify({ + origin: "not mako", + event: "new-medicaid-submission", + authority: "medicaid spa", + }), + ).toString("base64"), + headers: {}, + timestamp: 1732645041557, + offset: "0", + partition: 0, + topic: "mock-topic", + } as unknown as KafkaRecord, + ], + }, + eventSource: "", + bootstrapServers: "", + }; + const secSPY = vi.spyOn(SESClient.prototype, "send"); + + await handler(mockEvent, {} as Context, callback); + expect(secSPY).toHaveBeenCalledTimes(0); + }); + it("should be missing a value, so nothing sent", async () => { + const callback = vi.fn(); + const mockEvent: KafkaEvent = { + records: { + "mock-topic": [ + { + key: Buffer.from("VA").toString("base64"), + headers: {}, + timestamp: 1732645041557, + offset: "0", + partition: 0, + topic: "mock-topic", + } as unknown as KafkaRecord, + ], + }, + eventSource: "", + bootstrapServers: "", + }; + const secSPY = vi.spyOn(SESClient.prototype, "send"); + + await handler(mockEvent, {} as Context, callback); + expect(secSPY).toHaveBeenCalledTimes(0); + }); + it("should be missing an environment variable", async () => { + const callback = vi.fn(); + delete process.env.osDomain; + const mockEvent: KafkaEvent = { + records: { + "mock-topic": [ + { + key: Buffer.from("VA").toString("base64"), + value: Buffer.from( + JSON.stringify({ + origin: "mako", + event: "new-medicaid-submission", + authority: "medicaid spa", + }), + ).toString("base64"), + headers: {}, + timestamp: 1732645041557, + offset: "0", + partition: 0, + topic: "mock-topic", + } as unknown as KafkaRecord, + ], + }, + eventSource: "", + bootstrapServers: "", + }; + await expect(handler(mockEvent, {} as Context, callback)).rejects.toThrowError( + "Missing required environment variables: osDomain", + ); + }); +}); diff --git a/lib/lambda/processEmails.text.ts b/lib/lambda/processEmails.text.ts deleted file mode 100644 index baa5c4fdd4..0000000000 --- a/lib/lambda/processEmails.text.ts +++ /dev/null @@ -1,223 +0,0 @@ -import { - createEmailParams, - handler as processEmailsHandler, - processRecord, - sendEmail, -} from "./processEmails"; -import { KafkaEvent, KafkaRecord } from "shared-types"; -import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses"; -import { getAllStateUsers } from "libs/email"; -import { getSecret } from "shared-utils"; -import * as os from "libs/opensearch-lib"; -import { Context } from "aws-lambda"; -import { vi, Mock, beforeAll, afterAll, beforeEach, afterEach, describe, it, expect } from "vitest"; -import { EmailAddresses } from "shared-types"; - -// Add this near the top of your test file, after the imports -const mockEmailAddresses: EmailAddresses = { - osgEmail: ["osg@example.com"], - dpoEmail: ["dpo@example.com"], - dmcoEmail: ["dmco@example.com"], - dhcbsooEmail: ["dhcbsoo@example.com"], - chipInbox: ["chip.inbox@example.com"], - chipCcList: ["chip.cc1@example.com", "chip.cc2@example.com"], - sourceEmail: "source@example.com", - srtEmails: ["srt1@example.com", "srt2@example.com"], - cpocEmail: ["cpoc@example.com"], -}; - -vi.mock("@aws-sdk/client-ses"); -beforeAll(() => { - vi.clearAllMocks(); - - // Mock environment variables - vi.stubEnv("region", "us-east-1"); - vi.stubEnv("stage", "test"); - vi.stubEnv("indexNamespace", "test-index"); - vi.stubEnv("osDomain", "https://mock-opensearch-domain.com"); - vi.stubEnv("applicationEndpointUrl", "https://mock-app-endpoint.com"); //pragma: allowlist secret - vi.stubEnv("emailAddressLookupSecretName", "mock-email-secret"); //pragma: allowlist secret - vi.stubEnv("EMAIL_ATTEMPTS_TABLE", "mock-email-attempts-table"); - vi.stubEnv("MAX_RETRY_ATTEMPTS", "3"); - vi.stubEnv("userPoolId", "mock-user-pool-id"); //pragma: allowlist secret - - // Mock the getSecret function - (getSecret as Mock).mockResolvedValue(JSON.stringify(mockEmailAddresses)); - - // Add any other mocks or setup needed for your tests -}); -afterAll(() => { - // Clear stubbed environment variables after each test - vi.unstubAllEnvs(); -}); -describe("createEmailParams", () => { - const emailDetails = { - to: ["recipient@example.com"], - from: "sender@example.com", - subject: "Test Email", - html: "Test", - text: "Test", - }; - beforeEach(() => { - vi.clearAllMocks(); - - vi.stubEnv("region", "us-east-1"); - vi.stubEnv("emailAddressLookupSecretName", "mock-email-secret"); //pragma: allowlist secret - vi.stubEnv("applicationEndpointUrl", "https://mock-app-endpoint.com"); - vi.stubEnv("openSearchDomainEndpoint", "https://mock-opensearch-domain.com"); - // Mock environment variables - vi.stubEnv("indexNamespace", "https://mock-opensearch-endpoint.com"); - (getSecret as Mock).mockResolvedValue(JSON.stringify(mockEmailAddresses)); - - // Add any other environment variables your code expects - }); - - afterEach(() => { - // Clear stubbed environment variables after each test - vi.unstubAllEnvs(); - }); - - it("should create email parameters correctly", () => { - const params = createEmailParams(emailDetails, emailDetails.from, "topicName"); - expect(params).toEqual({ - Destination: { - ToAddresses: emailDetails.to, - }, - Message: { - Body: { - Html: { - Charset: "UTF-8", - Data: emailDetails.html, - }, - Text: { - Charset: "UTF-8", - Data: emailDetails.text, - }, - }, - Subject: { - Charset: "UTF-8", - Data: emailDetails.subject, - }, - }, - Source: emailDetails.from, - }); - }); -}); - -describe("sendEmail", () => { - const mockSesClient = new SESClient(); - const emailDetails = { - to: ["recipient@example.com"], - from: "sender@example.com", - subject: "Test Email", - html: "Test", - text: "Test", - }; - - beforeEach(() => { - vi.clearAllMocks(); - }); - - it("should send email successfully", async () => { - (mockSesClient.send as Mock).mockResolvedValue({}); - const params = createEmailParams(emailDetails, emailDetails.from, "topicName"); - - await sendEmail(params, "topicName"); - expect(mockSesClient.send).toHaveBeenCalledWith(expect.any(SendEmailCommand)); - }); - - it("should throw an error when there is an issue sending an email", async () => { - (mockSesClient.send as Mock).mockRejectedValue(new Error("Error sending email")); - const params = createEmailParams(emailDetails, emailDetails.from, "topicName"); - - await expect(sendEmail(params, "topicName")).rejects.toThrow("Error sending email"); - }); -}); - -describe("processEmails", () => { - vi.mock("@aws-sdk/client-ses"); - vi.mock("./../libs/email"); - vi.mock("shared-utils"); - vi.mock("../libs/opensearch-lib"); - const mockKafkaEvent: KafkaEvent = { - eventSource: "aws:kafka", - bootstrapServers: - "b-1.master-msk.zf7e0q.c7.kafka.us-east-1.amazonaws.com:9094,b-2.master-msk.zf7e0q.c7.kafka.us-east-1.amazonaws.com:9094,b-3.master-msk.zf7e0q.c7.kafka.us-east-1.amazonaws.com:9094", - records: { - "topic-partition": [ - { - key: "key", - value: "value", - timestamp: 1234567890, - topic: "topic", - partition: 0, - offset: 0, - timestampType: "CREATE_TIME", - headers: {}, - }, - ], - }, - }; - - const mockContext = {} as Context; // Create a mock Context object - const mockThirdArgument = () => {}; // Add the appropriate third argument here - - beforeEach(() => { - vi.clearAllMocks(); - - // Mock environment variables - vi.stubEnv("OPENSEARCH_ENDPOINT", "https://mock-opensearch-endpoint.com"); - vi.stubEnv("INDEX_NAMESPACE", "mock-index-namespace"); - (getSecret as Mock).mockResolvedValue(JSON.stringify(mockEmailAddresses)); - - // Add any other environment variables your code expects - }); - - afterEach(() => { - // Clear stubbed environment variables after each test - vi.unstubAllEnvs(); - }); - - it("should process Kafka event successfully", async () => { - (getAllStateUsers as Mock).mockResolvedValue([]); - (getSecret as Mock).mockResolvedValue("{}"); - (os.getItem as Mock).mockResolvedValue({}); - - await processEmailsHandler(mockKafkaEvent, mockContext, mockThirdArgument); - expect(getAllStateUsers).toHaveBeenCalled(); - expect(getSecret).toHaveBeenCalled(); - expect(os.getItem).toHaveBeenCalled(); - }); - - it("should handle tombstone event", async () => { - const tombstoneRecord: KafkaRecord = { - key: "base64-encoded-key", - value: "", - topic: "example-topic", - partition: 0, - offset: 0, - timestamp: Date.now(), - timestampType: "CREATE_TIME", - headers: {}, - }; - - await processRecord(tombstoneRecord, { - emailAddressLookupSecretName: "emailAddressLookupSecretName", //pragma: allowlist secret - applicationEndpointUrl: "applicationEndpointUrl", //pragma: allowlist secret - osDomain: "osDomain", - indexNamespace: "indexNamespace", - region: "region", - DLQ_URL: "DLQ_URL", - userPoolId: "userPoolId", - }); - expect(getAllStateUsers).not.toHaveBeenCalled(); - }); - - it("should throw an error when there is an issue processing email event", async () => { - (getAllStateUsers as Mock).mockRejectedValue(new Error("Error fetching users")); - - await expect( - processEmailsHandler(mockKafkaEvent, mockContext, mockThirdArgument), - ).rejects.toThrow(); - }); -}); diff --git a/lib/lambda/processEmails.ts b/lib/lambda/processEmails.ts index d3542cae39..e6ee16d07d 100644 --- a/lib/lambda/processEmails.ts +++ b/lib/lambda/processEmails.ts @@ -134,7 +134,7 @@ export async function processRecord(kafkaRecord: KafkaRecord, config: ProcessEma } } -function validateEmailTemplate(template: any) { +export function validateEmailTemplate(template: any) { const requiredFields = ["to", "subject", "body"]; const missingFields = requiredFields.filter((field) => !template[field]); diff --git a/lib/libs/email/getAllStateUsers.ts b/lib/libs/email/getAllStateUsers.ts index 8b2c4a619b..a943dff881 100644 --- a/lib/libs/email/getAllStateUsers.ts +++ b/lib/libs/email/getAllStateUsers.ts @@ -12,7 +12,9 @@ export type StateUser = { formattedEmailAddress: string; }; -const cognitoClient = new CognitoIdentityProviderClient(); +const cognitoClient = new CognitoIdentityProviderClient({ + region: "us-east-1", +}); export const getAllStateUsers = async ({ userPoolId, @@ -26,14 +28,12 @@ export const getAllStateUsers = async ({ UserPoolId: userPoolId, Limit: 60, }; - const command = new ListUsersCommand(params); const response: ListUsersCommandOutput = await cognitoClient.send(command); if (!response.Users || response.Users.length === 0) { return []; } - const filteredStateUsers = response.Users.filter((user) => { const stateAttribute = user.Attributes?.find((attr) => attr.Name === "custom:state"); return stateAttribute?.Value?.split(",").includes(state); @@ -42,7 +42,6 @@ export const getAllStateUsers = async ({ acc[attr.Name as any] = attr.Value; return acc; }, {} as Record); - return { firstName: attributes?.["given_name"], lastName: attributes?.["family_name"], diff --git a/lib/vitest.setup.ts b/lib/vitest.setup.ts index 0253f06766..5d50768624 100644 --- a/lib/vitest.setup.ts +++ b/lib/vitest.setup.ts @@ -80,6 +80,9 @@ beforeEach(() => { process.env.idmClientIssuer = USER_POOL_CLIENT_DOMAIN; process.env.osDomain = OPENSEARCH_DOMAIN; process.env.indexNamespace = OPENSEARCH_INDEX_NAMESPACE; + process.env.emailAddressLookupSecretName = "mock-email-secret"; + process.env.DLQ_URL = "https://sqs.us-east-1.amazonaws.com/123/test"; + process.env.configurationSetName = "SES"; }); afterEach(() => { diff --git a/mocks/data/items.ts b/mocks/data/items.ts index d302cfdac3..7db383eee6 100644 --- a/mocks/data/items.ts +++ b/mocks/data/items.ts @@ -8,7 +8,7 @@ export const EXISTING_ITEM_APPROVED_AMEND_ID = "MD-0000.R00.01"; export const EXISTING_ITEM_APPROVED_RENEW_ID = "MD-0000.R01.00"; export const EXISTING_ITEM_ID = "MD-00-0000"; export const NOT_FOUND_ITEM_ID = "MD-0004.R00.00"; -export const NOT_EXISTING_ITEM_ID = "MD-11-0000" +export const NOT_EXISTING_ITEM_ID = "MD-11-0000"; export const TEST_ITEM_ID = "MD-0005.R01.00"; export const EXISTING_ITEM_TEMPORARY_EXTENSION_ID = "MD-0005.R01.TE00"; export const HI_TEST_ITEM_ID = "HI-0000.R00.00"; @@ -32,6 +32,27 @@ const items: Record = { actionType: "New", }, }, + ["VA"]: { + _id: EXISTING_ITEM_ID, + found: true, + _source: { + leadAnalystEmail: "michael.chen@cms.hhs.gov", + leadAnalystName: "Michael Chen", + reviewTeam: [ + { + email: "john.doe@medicaid.gov", + name: "John Doe", + }, + { + email: "emily.rodriguez@medicaid.gov", + name: "Emily Rodriguez", + }, + ], + id: EXISTING_ITEM_ID, + seatoolStatus: SEATOOL_STATUS.APPROVED, + actionType: "New", + }, + }, [EXISTING_ITEM_APPROVED_NEW_ID]: { _id: EXISTING_ITEM_APPROVED_NEW_ID, found: true, diff --git a/mocks/data/secrets.ts b/mocks/data/secrets.ts index 1889504ad4..8b222242b1 100644 --- a/mocks/data/secrets.ts +++ b/mocks/data/secrets.ts @@ -5,6 +5,7 @@ export const TEST_SECRET_TO_DELETE_ID = "test-secret-to-delete"; // pragma: allo export const TEST_SECRET_NO_VALUE_ID = "test-secret-no-value"; // pragma: allowlist secret export const TEST_SECRET_ERROR_ID = "Throw Get Secret Error"; // pragma: allowlist secret export const TEST_PW_ARN = "test-arn-create-update-user"; // pragma: allowlist secret +export const TEST_EMAIL_ID = "mock-email-secret"; const secrets: Record = { [TEST_SECRET_ID]: { @@ -39,6 +40,25 @@ const secrets: Record = { VersionId: "1.0", VersionStages: ["prod"], }, + [TEST_EMAIL_ID]: { + ARN: `arn://${TEST_EMAIL_ID}`, + CreatedDate: new Date("2023-01-01T12:00:00Z").getTime(), + Name: TEST_EMAIL_ID, + SecretString: + "{" + + '"osgEmail": ["osg@example.com"],' + + '"dpoEmail": ["dpo@example.com"],' + + '"dmcoEmail": ["dmco@example.com"],' + + '"dhcbsooEmail": ["dhcbsoo@example.com"],' + + '"chipInbox": ["chip.inbox@example.com"],' + + '"chipCcList": ["chip.cc1@example.com", "chip.cc2@example.com"],' + + '"sourceEmail": "source@example.com",' + + '"srtEmails": ["srt1@example.com", "srt2@example.com"],' + + '"cpocEmail": ["cpoc@example.com"]' + + "}", + VersionId: "1.0", + VersionStages: ["prod"], + }, }; export default secrets; diff --git a/mocks/handlers/aws/cognito.ts b/mocks/handlers/aws/cognito.ts index 4cd07fb707..e830dfc187 100644 --- a/mocks/handlers/aws/cognito.ts +++ b/mocks/handlers/aws/cognito.ts @@ -343,10 +343,16 @@ export const identityProviderServiceHandler = http.post< } if (target == "AWSCognitoIdentityProviderService.ListUsers") { - const { Filter } = (await request.json()) as IdpListUsersRequestBody; - const username = - Filter.replace("sub = ", "").replaceAll('"', "") || process.env.MOCK_USER_USERNAME; + let username: string = ""; + try { + const { Filter } = (await request.json()) as IdpListUsersRequestBody; + username = Filter.replace("sub = ", "").replaceAll('"', ""); + } catch { + if (process.env.MOCK_USER_USERNAME) { + username = process.env.MOCK_USER_USERNAME; + } + } if (username) { const user = findUserByUsername(username); if (user) { diff --git a/mocks/handlers/aws/email.ts b/mocks/handlers/aws/email.ts new file mode 100644 index 0000000000..11b8afa1ad --- /dev/null +++ b/mocks/handlers/aws/email.ts @@ -0,0 +1,35 @@ +import { http, HttpResponse, PathParams } from "msw"; + +export const emailHandlers = [ + http.post("f", async (request) => { + // Extract the body from the request + if (request.request.url === "https://email.us-east-1.amazonaws.com/") { + return HttpResponse.xml(` + + + mocked-message-id-12345 + + + mocked-request-id-67890 + + + `); + } + return new HttpResponse(null, { status: 500 }); + }), + http.post("https://sqs.us-east-1.amazonaws.com/", async (request) => { + return new HttpResponse(null, { status: 200 }); + }), + http.post("https://email.us-east-1.amazonaws.com/", async (request) => { + return HttpResponse.xml(` + + + mocked-message-id-12345 + + + mocked-request-id-67890 + + + `); + }), +]; diff --git a/mocks/handlers/aws/index.ts b/mocks/handlers/aws/index.ts index 7856eff9c6..9b4f5cfb7c 100644 --- a/mocks/handlers/aws/index.ts +++ b/mocks/handlers/aws/index.ts @@ -4,7 +4,7 @@ import { credentialHandlers } from "./credentials"; import { lambdaHandlers } from "./lambda"; import { secretsManagerHandlers } from "./secretsManager"; import { stepFunctionHandlers } from "./stepFunctions"; - +import { emailHandlers } from "./email"; export const awsHandlers = [ ...cloudFormationHandlers, ...cognitoHandlers, @@ -12,6 +12,7 @@ export const awsHandlers = [ ...lambdaHandlers, ...secretsManagerHandlers, ...stepFunctionHandlers, + ...emailHandlers, ]; export { errorCloudFormationHandler } from "./cloudFormation"; From d1a8cf2d825339bac949d3a0a53deba0137eed89 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 7 Jan 2025 13:32:42 -0500 Subject: [PATCH 2/7] Removed console.log --- lib/lambda/processEmails.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/lambda/processEmails.test.ts b/lib/lambda/processEmails.test.ts index e2f6fe5a1d..4676964c2c 100644 --- a/lib/lambda/processEmails.test.ts +++ b/lib/lambda/processEmails.test.ts @@ -65,7 +65,6 @@ describe("process emails Handler", () => { await handler(mockEvent, {} as Context, callback); expect(secSPY).toHaveBeenCalledTimes(2); - // console.log(result); }); it("should not be mako therefor not do an event", async () => { const callback = vi.fn(); From eda0745952e2ded1fa80f7b7715070655dc3b822 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 7 Jan 2025 13:33:25 -0500 Subject: [PATCH 3/7] linter correction --- mocks/handlers/aws/email.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mocks/handlers/aws/email.ts b/mocks/handlers/aws/email.ts index 11b8afa1ad..5ec43f75f8 100644 --- a/mocks/handlers/aws/email.ts +++ b/mocks/handlers/aws/email.ts @@ -17,10 +17,10 @@ export const emailHandlers = [ } return new HttpResponse(null, { status: 500 }); }), - http.post("https://sqs.us-east-1.amazonaws.com/", async (request) => { + http.post("https://sqs.us-east-1.amazonaws.com/", async () => { return new HttpResponse(null, { status: 200 }); }), - http.post("https://email.us-east-1.amazonaws.com/", async (request) => { + http.post("https://email.us-east-1.amazonaws.com/", async () => { return HttpResponse.xml(` From 3b7c5aa016e116a872282e814f349c00005378d4 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 7 Jan 2025 13:36:38 -0500 Subject: [PATCH 4/7] removed a ine --- lib/libs/email/getAllStateUsers.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/libs/email/getAllStateUsers.ts b/lib/libs/email/getAllStateUsers.ts index a943dff881..e5c855668b 100644 --- a/lib/libs/email/getAllStateUsers.ts +++ b/lib/libs/email/getAllStateUsers.ts @@ -12,9 +12,7 @@ export type StateUser = { formattedEmailAddress: string; }; -const cognitoClient = new CognitoIdentityProviderClient({ - region: "us-east-1", -}); +const cognitoClient = new CognitoIdentityProviderClient({}); export const getAllStateUsers = async ({ userPoolId, From 6a0d541bbd5e4ad47956941a530e349e24a36f4d Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 7 Jan 2025 13:37:34 -0500 Subject: [PATCH 5/7] remove brackets --- lib/libs/email/getAllStateUsers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libs/email/getAllStateUsers.ts b/lib/libs/email/getAllStateUsers.ts index e5c855668b..c871e591ca 100644 --- a/lib/libs/email/getAllStateUsers.ts +++ b/lib/libs/email/getAllStateUsers.ts @@ -12,7 +12,7 @@ export type StateUser = { formattedEmailAddress: string; }; -const cognitoClient = new CognitoIdentityProviderClient({}); +const cognitoClient = new CognitoIdentityProviderClient(); export const getAllStateUsers = async ({ userPoolId, From 8bc1c4c162f74ccc95cfd806c5bf4c83268ecead Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 7 Jan 2025 13:38:02 -0500 Subject: [PATCH 6/7] add region --- lib/libs/email/getAllStateUsers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/libs/email/getAllStateUsers.ts b/lib/libs/email/getAllStateUsers.ts index c871e591ca..a943dff881 100644 --- a/lib/libs/email/getAllStateUsers.ts +++ b/lib/libs/email/getAllStateUsers.ts @@ -12,7 +12,9 @@ export type StateUser = { formattedEmailAddress: string; }; -const cognitoClient = new CognitoIdentityProviderClient(); +const cognitoClient = new CognitoIdentityProviderClient({ + region: "us-east-1", +}); export const getAllStateUsers = async ({ userPoolId, From 699c91b797b5cb6e67f0ceef231153e36447976e Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 8 Jan 2025 11:30:57 -0500 Subject: [PATCH 7/7] Address change reqeust --- lib/libs/email/getAllStateUsers.ts | 2 +- lib/vitest.setup.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libs/email/getAllStateUsers.ts b/lib/libs/email/getAllStateUsers.ts index a943dff881..b481fb5341 100644 --- a/lib/libs/email/getAllStateUsers.ts +++ b/lib/libs/email/getAllStateUsers.ts @@ -13,7 +13,7 @@ export type StateUser = { }; const cognitoClient = new CognitoIdentityProviderClient({ - region: "us-east-1", + region: process.env.region, }); export const getAllStateUsers = async ({ diff --git a/lib/vitest.setup.ts b/lib/vitest.setup.ts index 5d50768624..3b94b69953 100644 --- a/lib/vitest.setup.ts +++ b/lib/vitest.setup.ts @@ -80,7 +80,7 @@ beforeEach(() => { process.env.idmClientIssuer = USER_POOL_CLIENT_DOMAIN; process.env.osDomain = OPENSEARCH_DOMAIN; process.env.indexNamespace = OPENSEARCH_INDEX_NAMESPACE; - process.env.emailAddressLookupSecretName = "mock-email-secret"; + process.env.emailAddressLookupSecretName = "mock-email-secret"; // pragma: allowlist secret process.env.DLQ_URL = "https://sqs.us-east-1.amazonaws.com/123/test"; process.env.configurationSetName = "SES"; });