Skip to content

Commit

Permalink
Merge main into head
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpaige committed Jan 3, 2025
2 parents 54b9588 + b2f4214 commit 3a7fddd
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 5,666 deletions.
4 changes: 2 additions & 2 deletions bin/cli/src/lib/write-ui-env-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export async function writeUiEnvFile(stage, local = false) {
VITE_COGNITO_USER_POOL_CLIENT_ID: deploymentOutput.userPoolClientId,
VITE_COGNITO_USER_POOL_CLIENT_DOMAIN: deploymentOutput.userPoolClientDomain,
VITE_COGNITO_REDIRECT_SIGNIN: local
? `"http://localhost:5000/"`
: deploymentOutput.applicationEndpointUrl,
? `"http://localhost:5000/dashboard"`
: `${deploymentOutput.applicationEndpointUrl}dashboard`,
VITE_COGNITO_REDIRECT_SIGNOUT: local
? `"http://localhost:5000/"`
: deploymentOutput.applicationEndpointUrl,
Expand Down
22 changes: 11 additions & 11 deletions lib/lambda/getAttachmentUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe.skip("Lambda Handler", () => {
});

it("should return 404 if no package is found", async () => {
(getPackage as Mock).mockResolvedValueOnce(null);
vi.mocked(getPackage).mockResolvedValueOnce(null);

const event = {
body: JSON.stringify({
Expand All @@ -94,10 +94,10 @@ describe.skip("Lambda Handler", () => {
});

it("should return 404 if state access is not permitted", async () => {
(getPackage as Mock).mockResolvedValueOnce({
vi.mocked(getPackage).mockResolvedValueOnce({
_source: { state: "test-state" },
});
(getStateFilter as Mock).mockResolvedValueOnce({
vi.mocked(getStateFilter).mockResolvedValueOnce({
terms: { state: ["other-state"] },
});

Expand All @@ -119,13 +119,13 @@ describe.skip("Lambda Handler", () => {
});

it("should return 500 if attachment details are not found", async () => {
(getPackage as Mock).mockResolvedValueOnce({
vi.mocked(getPackage).mockResolvedValueOnce({
_source: { state: "test-state" },
});
(getStateFilter as Mock).mockResolvedValueOnce({
vi.mocked(getStateFilter).mockResolvedValueOnce({
terms: { state: ["test-state"] },
});
(getPackageChangelog as Mock).mockResolvedValueOnce({
vi.mocked(getPackageChangelog).mockResolvedValueOnce({
hits: {
hits: [
{
Expand Down Expand Up @@ -155,13 +155,13 @@ describe.skip("Lambda Handler", () => {
});

it("should return 200 with the presigned URL if all checks pass", async () => {
(getPackage as Mock).mockResolvedValueOnce({
vi.mocked(getPackage).mockResolvedValueOnce({
_source: { state: "test-state" },
});
(getStateFilter as Mock).mockResolvedValueOnce({
vi.mocked(getStateFilter).mockResolvedValueOnce({
terms: { state: ["test-state"] },
});
(getPackageChangelog as Mock).mockResolvedValueOnce({
vi.mocked(getPackageChangelog).mockResolvedValueOnce({
hits: {
hits: [
{
Expand All @@ -172,7 +172,7 @@ describe.skip("Lambda Handler", () => {
],
},
});
(getSignedUrl as Mock).mockResolvedValueOnce("test-presigned-url");
vi.mocked(getSignedUrl).mockResolvedValueOnce("test-presigned-url");

const event = {
body: JSON.stringify({
Expand All @@ -192,7 +192,7 @@ describe.skip("Lambda Handler", () => {
});

it("should handle errors during processing", async () => {
(getPackage as Mock).mockRejectedValueOnce(new Error("Test error"));
vi.mocked(getPackage).mockRejectedValueOnce(new Error("Test error"));

const event = {
body: JSON.stringify({
Expand Down
51 changes: 27 additions & 24 deletions lib/lambda/setupIndex.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// my-lib.test.ts
import { describe, it, expect, vi, beforeEach } from "vitest";
import { handler } from "./setupIndex"; // The code that calls createIndex, updateFieldMapping
import { Context } from "aws-lambda";
import { handler } from "./setupIndex";

// 1) Define mocks first
const mockCreateIndex = vi.fn();
const mockUpdateFieldMapping = vi.fn();
const mockFns = vi.hoisted(() => ({
createIndex: vi.fn(),
updateFieldMapping: vi.fn(),
}));

vi.mock("../libs/opensearch-lib", () => mockFns);

describe.skip("handler", () => {
// TODO: fix this test - it shows an error: SyntaxError: Unexpected token ')' [which is just not the case]
const mockCallback = vi.fn();
const mockEvent = {
osDomain: "test-domain",
Expand All @@ -21,20 +23,22 @@ describe.skip("handler", () => {
});

it("should create and update indices without errors", async () => {
await handler(mockEvent, {} as Context, mockCallback);

// 3. Use the mocked functions in the expectations:
expect(mockCreateIndex).toHaveBeenCalledTimes(7);
expect(mockCreateIndex).toHaveBeenCalledWith("test-domain", "test-namespace-main");
expect(mockCreateIndex).toHaveBeenCalledWith("test-domain", "test-namespace-changelog");
expect(mockCreateIndex).toHaveBeenCalledWith("test-domain", "test-namespace-types");
expect(mockCreateIndex).toHaveBeenCalledWith("test-domain", "test-namespace-subtypes");
expect(mockCreateIndex).toHaveBeenCalledWith("test-domain", "test-namespace-cpocs");
expect(mockCreateIndex).toHaveBeenCalledWith("test-domain", "test-namespace-insights");
expect(mockCreateIndex).toHaveBeenCalledWith("test-domain", "test-namespace-legacyinsights");

expect(mockUpdateFieldMapping).toHaveBeenCalledTimes(1);
expect(mockUpdateFieldMapping).toHaveBeenCalledWith("test-domain", "test-namespace-main", {
await handler(mockEvent, expect.anything(), mockCallback);

expect(mockFns.createIndex).toHaveBeenCalledTimes(7);
expect(mockFns.createIndex).toHaveBeenCalledWith("test-domain", "test-namespace-main");
expect(mockFns.createIndex).toHaveBeenCalledWith("test-domain", "test-namespace-changelog");
expect(mockFns.createIndex).toHaveBeenCalledWith("test-domain", "test-namespace-types");
expect(mockFns.createIndex).toHaveBeenCalledWith("test-domain", "test-namespace-subtypes");
expect(mockFns.createIndex).toHaveBeenCalledWith("test-domain", "test-namespace-cpocs");
expect(mockFns.createIndex).toHaveBeenCalledWith("test-domain", "test-namespace-insights");
expect(mockFns.createIndex).toHaveBeenCalledWith(
"test-domain",
"test-namespace-legacyinsights",
);

expect(mockFns.updateFieldMapping).toHaveBeenCalledTimes(1);
expect(mockFns.updateFieldMapping).toHaveBeenCalledWith("test-domain", "test-namespace-main", {
approvedEffectiveDate: { type: "date" },
changedDate: { type: "date" },
finalDispositionDate: { type: "date" },
Expand All @@ -47,13 +51,12 @@ describe.skip("handler", () => {
});

it("should handle errors and return status 500", async () => {
// Make the first call to mockCreateIndex reject:
mockCreateIndex.mockRejectedValueOnce(new Error("Test error"));
mockFns.createIndex.mockRejectedValueOnce(new Error("Test error"));

await handler(mockEvent, {} as Context, mockCallback);
await handler(mockEvent, expect.anything(), mockCallback);

expect(mockCreateIndex).toHaveBeenCalledTimes(1);
expect(mockUpdateFieldMapping).not.toHaveBeenCalled();
expect(mockFns.createIndex).toHaveBeenCalledTimes(1);
expect(mockFns.updateFieldMapping).not.toHaveBeenCalled();
expect(mockCallback).toHaveBeenCalledWith(expect.any(Error), {
statusCode: 500,
});
Expand Down
Loading

0 comments on commit 3a7fddd

Please sign in to comment.