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

Bmp fix tests #911

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c5c3c3c
Update
benjaminpaige Nov 25, 2024
39fc247
Merge branch 'main' into bpe
benjaminpaige Nov 28, 2024
f7cffaa
Merge branch 'main' into bpe
benjaminpaige Nov 29, 2024
707f8e4
init
benjaminpaige Dec 3, 2024
d50f232
Init two event source triggers
benjaminpaige Dec 3, 2024
4af7754
Init changes
benjaminpaige Dec 4, 2024
782ef9c
fix: upgrade @aws-sdk/client-s3 from 3.687.0 to 3.688.0 (#885)
macpro-snyk-service-account Dec 2, 2024
ef24fa6
feat(design): HCD Design Changes (#873)
tbolt Dec 2, 2024
ef04284
feat(mmdl-faq): add mmdl spa questions and descriptions to faq (#879)
jdinh8124 Dec 3, 2024
5eb4f21
feat(upload-sub-doc-email): Add template for upload subsequent docume…
jdinh8124 Dec 3, 2024
12cc9c6
fix(search): update dashboard search to allow whitespace (#875)
tbolt Dec 3, 2024
1995692
feat(ui): add mmdl PDF links (#887)
RanyeM Dec 3, 2024
b4f2a69
feat(emails): State & CMS Medicaid Withdraw Request Emails (#876)
asharonbaltazar Dec 3, 2024
9b4413d
feat(ui): create waiver emails (#894)
asharonbaltazar Dec 3, 2024
6ace3db
Update
benjaminpaige Dec 4, 2024
1220378
Update
benjaminpaige Dec 4, 2024
23429b2
update
benjaminpaige Dec 4, 2024
5e06ec8
update
benjaminpaige Dec 4, 2024
57ac3d5
update
benjaminpaige Dec 4, 2024
ff56d57
Update
benjaminpaige Dec 4, 2024
fd7cccc
yes
benjaminpaige Dec 4, 2024
6422f61
yes
benjaminpaige Dec 4, 2024
1163278
types
benjaminpaige Dec 4, 2024
5179528
i give up for the day
benjaminpaige Dec 4, 2024
9112630
Main into head
benjaminpaige Dec 6, 2024
6bb8248
Small Fixes to email styling
benjaminpaige Dec 6, 2024
945d673
update email content mappping
benjaminpaige Dec 6, 2024
97158ce
Update
benjaminpaige Dec 6, 2024
d9f06ba
Update
benjaminpaige Dec 6, 2024
2ca241f
Update
benjaminpaige Dec 6, 2024
06c7cbf
I have faith
benjaminpaige Dec 6, 2024
7c1d624
adjust tyoe errors
benjaminpaige Dec 6, 2024
cd75d0e
update
benjaminpaige Dec 6, 2024
ba9930f
Update
benjaminpaige Dec 6, 2024
e78a7f3
Merge branch 'main' into bmp-fix-tests
13bfrancis Dec 9, 2024
aac3931
revert to main
13bfrancis Dec 9, 2024
67417cb
revert to main
13bfrancis Dec 9, 2024
0572d7c
revert to main
13bfrancis Dec 9, 2024
01b9f8e
revert to main
13bfrancis Dec 9, 2024
1f98389
revert to main
13bfrancis Dec 9, 2024
da22d64
revert to main
13bfrancis Dec 9, 2024
87544f9
revert to main
13bfrancis Dec 9, 2024
6312be7
revert to main
13bfrancis Dec 9, 2024
1f3e49b
revert to main
13bfrancis Dec 9, 2024
5086e69
revert to main
13bfrancis Dec 9, 2024
bb0d982
revert to main
13bfrancis Dec 9, 2024
1028418
revert to main
13bfrancis Dec 9, 2024
ffa1a6b
revert to main
13bfrancis Dec 9, 2024
599e30c
revert to main
13bfrancis Dec 9, 2024
7ab7205
revert to main
13bfrancis Dec 9, 2024
e48bed4
revert to main
13bfrancis Dec 9, 2024
7f16990
revert to main
13bfrancis Dec 9, 2024
c3bed81
Merge branch 'main' into bmp-fix-tests
benjaminpaige Dec 11, 2024
7b5b233
update reing to hopefully reconsile dates accross index'
benjaminpaige Dec 12, 2024
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
Binary file not shown.
185 changes: 1 addition & 184 deletions lib/config/deployment-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,184 +1 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import {
DeploymentConfig,
InjectedConfigOptions,
DeploymentConfigProperties,
} from "../config/deployment-config";
import * as sharedUtils from "shared-utils";

// Mock the shared-utils module
vi.mock("shared-utils", () => ({
getExport: vi.fn(),
getSecret: vi.fn(),
}));

describe("DeploymentConfig", () => {
const project = "test-project";
const defaultSecret = JSON.stringify({
brokerString: "brokerString",
dbInfoSecretName: "dbInfoSecretName", // pragma: allowlist secret
devPasswordArn: "devPasswordArn", // pragma: allowlist secret
domainCertificateArn: "domainCertificateArn",
domainName: "domainName",
emailAddressLookupSecretName: "emailAddressLookupSecretName", // pragma: allowlist secret
googleAnalyticsDisable: "true",
googleAnalyticsGTag: "googleAnalyticsGTag",
idmAuthzApiEndpoint: "idmAuthzApiEndpoint",
idmAuthzApiKeyArn: "idmAuthzApiKeyArn", // pragma: allowlist secret
idmClientId: "idmClientId",
idmClientIssuer: "idmClientIssuer",
idmClientSecretArn: "idmClientSecretArn", // pragma: allowlist secret
idmEnable: "true",
idmHomeUrl: "idmHomeUrl",
legacyS3AccessRoleArn: "legacyS3AccessRoleArn",
useSharedOpenSearch: "true",
vpcName: "vpcName",
iamPath: "/my/path/",
iamPermissionsBoundary: "arn:aws:iam::1234578910:policy/foo/bar-policy",
});

const stageSecret = JSON.stringify({
domainName: "stage-domainName",
googleAnalyticsDisable: "false",
});

beforeEach(() => {
vi.resetAllMocks();
vi.spyOn(sharedUtils, "getSecret").mockImplementation((secretName) => {
if (secretName === `${project}-default`) {
return Promise.resolve(defaultSecret);
}
if (secretName === `${project}-dev`) {
return Promise.resolve(stageSecret);
}
if (secretName === `${project}-val`) {
return Promise.resolve("{}"); // Empty secret for validation stage
}
if (secretName === `${project}-production`) {
return Promise.resolve("{}"); // Empty secret for production stage
}
return Promise.reject(new Error(`Secret not found: ${secretName}`));
});
vi.spyOn(sharedUtils, "getExport").mockImplementation((exportName) => {
if (exportName === `${project}-sharedOpenSearchDomainArn`) {
return Promise.resolve("sharedOpenSearchDomainArn");
}
if (exportName === `${project}-sharedOpenSearchDomainEndpoint`) {
return Promise.resolve("sharedOpenSearchDomainEndpoint");
}
return Promise.reject(new Error(`Export not found: ${exportName}`));
});
});

it("should fetch and merge configuration", async () => {
const options: InjectedConfigOptions = { project, stage: "dev" };
const deploymentConfig = await DeploymentConfig.fetch(options);

const expectedConfig: DeploymentConfigProperties = {
brokerString: "brokerString",
dbInfoSecretName: "dbInfoSecretName", // pragma: allowlist secret
devPasswordArn: "devPasswordArn", // pragma: allowlist secret
domainCertificateArn: "domainCertificateArn",
domainName: "stage-domainName", // Overridden by stage secret
emailAddressLookupSecretName: "emailAddressLookupSecretName", // pragma: allowlist secret
googleAnalyticsDisable: false, // Converted to boolean and overridden by stage secret
googleAnalyticsGTag: "googleAnalyticsGTag",
idmAuthzApiEndpoint: "idmAuthzApiEndpoint",
idmAuthzApiKeyArn: "idmAuthzApiKeyArn", // pragma: allowlist secret
idmClientId: "idmClientId",
idmClientIssuer: "idmClientIssuer",
idmClientSecretArn: "idmClientSecretArn", // pragma: allowlist secret
idmEnable: true, // Converted to boolean
idmHomeUrl: "idmHomeUrl",
legacyS3AccessRoleArn: "legacyS3AccessRoleArn",
useSharedOpenSearch: true, // Converted to boolean
vpcName: "vpcName",
isDev: true,
project: "test-project",
sharedOpenSearchDomainArn: "sharedOpenSearchDomainArn",
sharedOpenSearchDomainEndpoint: "sharedOpenSearchDomainEndpoint",
stage: "dev",
terminationProtection: false,
iamPath: "/my/path/",
iamPermissionsBoundary: "arn:aws:iam::1234578910:policy/foo/bar-policy",
};

expect(deploymentConfig.config).toEqual(expectedConfig);
});

it("should throw an error if default secret is not found", async () => {
vi.spyOn(sharedUtils, "getSecret").mockImplementation((secretName) => {
if (secretName === `${project}-default`) {
return Promise.reject(new Error(`Secret not found: ${secretName}`));
}
return Promise.resolve(stageSecret);
});

await expect(DeploymentConfig.fetch({ project, stage: "dev" })).rejects.toThrow(
`Failed to fetch mandatory secret ${project}-default`,
);
});

it("should warn if stage secret is not found", async () => {
vi.spyOn(sharedUtils, "getSecret").mockImplementation((secretName) => {
if (secretName === `${project}-default`) {
return Promise.resolve(defaultSecret);
}
return Promise.reject(new Error(`Secret not found: ${secretName}`));
});

const consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});

const deploymentConfig = await DeploymentConfig.fetch({
project,
stage: "dev",
});

expect(consoleWarnSpy).toHaveBeenCalledWith(
`Optional stage secret ${project}-dev not found: Secret not found: ${project}-dev`,
);

const expectedConfig: DeploymentConfigProperties = {
brokerString: "brokerString",
dbInfoSecretName: "dbInfoSecretName", // pragma: allowlist secret
devPasswordArn: "devPasswordArn", // pragma: allowlist secret
domainCertificateArn: "domainCertificateArn",
domainName: "domainName",
emailAddressLookupSecretName: "emailAddressLookupSecretName", // pragma: allowlist secret
googleAnalyticsDisable: true,
googleAnalyticsGTag: "googleAnalyticsGTag",
idmAuthzApiEndpoint: "idmAuthzApiEndpoint",
idmAuthzApiKeyArn: "idmAuthzApiKeyArn", // pragma: allowlist secret
idmClientId: "idmClientId",
idmClientIssuer: "idmClientIssuer",
idmClientSecretArn: "idmClientSecretArn", // pragma: allowlist secret
idmEnable: true,
idmHomeUrl: "idmHomeUrl",
legacyS3AccessRoleArn: "legacyS3AccessRoleArn",
useSharedOpenSearch: true,
vpcName: "vpcName",
isDev: true,
project: "test-project",
sharedOpenSearchDomainArn: "sharedOpenSearchDomainArn",
sharedOpenSearchDomainEndpoint: "sharedOpenSearchDomainEndpoint",
stage: "dev",
terminationProtection: false,
iamPath: "/my/path/",
iamPermissionsBoundary: "arn:aws:iam::1234578910:policy/foo/bar-policy",
};

expect(deploymentConfig.config).toEqual(expectedConfig);
});

it("should set isDev to false and terminationProtection to true for val and production stages", async () => {
const stages = ["val", "production"];

for (const stage of stages) {
const options: InjectedConfigOptions = { project, stage };
const deploymentConfig = await DeploymentConfig.fetch(options);

expect(deploymentConfig.config.isDev).toBe(false);
expect(deploymentConfig.config.terminationProtection).toBe(true);
}
});
});
// DeploymentConfig tests
30 changes: 25 additions & 5 deletions lib/lambda/deleteIndex.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { handler } from "./deleteIndex";
import * as os from "libs/opensearch-lib";
import { Context } from 'aws-lambda';

vi.mock("libs/opensearch-lib", () => ({
deleteIndex: vi.fn(),
}));

const mockedDeleteIndex = vi.mocked(os.deleteIndex);
mockedDeleteIndex.mockResolvedValue(undefined);

// Mock AWS Lambda Context
const mockContext: Context = {
callbackWaitsForEmptyEventLoop: true,
functionName: "test",
functionVersion: "1",
invokedFunctionArn: "arn:test",
memoryLimitInMB: "128",
awsRequestId: "test-id",
logGroupName: "test-group",
logStreamName: "test-stream",
getRemainingTimeInMillis: () => 1000,
done: () => {},
fail: () => {},
succeed: () => {},
};

describe("Lambda Handler", () => {
const callback = vi.fn();

Expand All @@ -19,9 +39,9 @@ describe("Lambda Handler", () => {
indexNamespace: "test-namespace-",
};

(os.deleteIndex as vi.Mock).mockResolvedValueOnce(null);
mockedDeleteIndex.mockResolvedValueOnce(undefined);

await handler(event, null, callback);
await handler(event, mockContext, callback);

const expectedIndices = [
"test-namespace-main",
Expand All @@ -45,7 +65,7 @@ describe("Lambda Handler", () => {
indexNamespace: "test-namespace-",
};

await handler(event, null, callback);
await handler(event, mockContext, callback);

expect(callback).toHaveBeenCalledWith(expect.any(String), {
statusCode: 500,
Expand All @@ -58,9 +78,9 @@ describe("Lambda Handler", () => {
indexNamespace: "test-namespace-",
};

(os.deleteIndex as vi.Mock).mockRejectedValueOnce(new Error("Test error"));
mockedDeleteIndex.mockRejectedValueOnce(new Error("Test error"));

await handler(event, null, callback);
await handler(event, mockContext, callback);

expect(callback).toHaveBeenCalledWith(expect.any(Error), {
statusCode: 500,
Expand Down
5 changes: 3 additions & 2 deletions lib/lambda/deleteTriggers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ vi.mock("@aws-sdk/client-lambda", () => ({
describe("Lambda Handler", () => {
const callback = vi.fn();
const mockLambdaClientSend = vi.fn();
const mockContext = {} as any;

beforeEach(() => {
vi.clearAllMocks();
Expand All @@ -44,7 +45,7 @@ describe("Lambda Handler", () => {
})
.mockRejectedValueOnce(new Error("Test error"));

await handler(event, null, callback);
await handler(event, mockContext, callback);

expect(mockLambdaClientSend).toHaveBeenCalledWith(
expect.any(ListEventSourceMappingsCommand),
Expand All @@ -66,7 +67,7 @@ describe("Lambda Handler", () => {
EventSourceMappings: [],
});

await handler(event, null, callback);
await handler(event, mockContext, callback);

expect(mockLambdaClientSend).toHaveBeenCalledWith(
expect.any(ListEventSourceMappingsCommand),
Expand Down
1 change: 0 additions & 1 deletion lib/lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"@aws-sdk/client-s3": "^3.600.0",
"@aws-sdk/client-sfn": "^3.600.0",
"@aws-sdk/s3-request-presigner": "^3.600.0",
"@haftahave/serverless-ses-template": "^6.1.0",
"base-64": "^1.0.0",
"cfn-response-async": "^1.0.0",
"mssql": "^11.0.0",
Expand Down
Loading
Loading