Skip to content

Commit

Permalink
some test stuff idk
Browse files Browse the repository at this point in the history
  • Loading branch information
andieswift committed Jan 23, 2025
1 parent 9f1a2d6 commit e71d117
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 8 deletions.
74 changes: 74 additions & 0 deletions lib/lambda/adminActions/submitNOSO.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { describe, it, expect, vi, beforeEach } from "vitest";
import { handler } from "./updatePackage";
import { APIGatewayEvent } from "node_modules/shared-types";

import { EXISTING_ITEM_ID } from "mocks";

vi.mock("libs/handler-lib", () => ({
response: vi.fn((data) => data),
}));

describe("handler", () => {
beforeEach(() => {
vi.clearAllMocks();
process.env.topicName = "test-topic";
});

it("should return 400 if event body is missing", async () => {
const event = {} as APIGatewayEvent;
const result = await handler(event);
const expectedResult = { statusCode: 400, body: { message: "Event body required" } };

expect(result).toStrictEqual(expectedResult);
});

it("should return 400 if package ID is not found", async () => {
const noActionevent = {
body: JSON.stringify({ packageId: "123", changeReason: "Nunya" }),
} as APIGatewayEvent;

const resultPackage = await handler(noActionevent);
expect(resultPackage?.statusCode).toBe(400);
});

it("should return 400 if action is not found", async () => {
const noApackageEvent = {
body: JSON.stringify({ action: "123", changeReason: "Nunya" }),
} as APIGatewayEvent;

const resultAction = await handler(noApackageEvent);

expect(resultAction?.statusCode).toBe(400);
});
it("should get a package", async () => {
const noActionevent = {
body: JSON.stringify({ packageId: "123", action: "delete", changeReason: "Nunya" }),
} as APIGatewayEvent;

const result = await handler(noActionevent);

const expectedResult = {
statusCode: 404,
body: { message: "No record found for the given id" },
};
expect(result).toStrictEqual(expectedResult);
});
it("should create a onemac package copy", async () => {
const noActionevent = {
body: JSON.stringify({
packageId: EXISTING_ITEM_ID,
action: "NOSO",
}),
} as APIGatewayEvent;

const result = await handler(noActionevent);

const expectedResult = {
statusCode: 200,
body: {
message: `${EXISTING_ITEM_ID} has been submitted.`,
},
};
expect(result).toStrictEqual(expectedResult);

Check failure on line 72 in lib/lambda/adminActions/submitNOSO.test.ts

View workflow job for this annotation

GitHub Actions / coverage-report

lambda/adminActions/submitNOSO.test.ts > handler > should create a onemac package copy

AssertionError: expected { statusCode: 500, …(1) } to strictly equal { statusCode: 200, …(1) } - Expected + Received Object { "body": Object { - "message": "MD-00-0000 has been submitted.", + "message": "[ + { + \"received\": \"NOSO\", + \"code\": \"invalid_enum_value\", + \"options\": [ + \"update-values\", + \"update-id\", + \"delete\" + ], + \"path\": [ + \"action\" + ], + \"message\": \"Invalid enum value. Expected 'update-values' | 'update-id' | 'delete', received 'NOSO'\" + } + ]", }, - "statusCode": 200, + "statusCode": 500, } ❯ lambda/adminActions/submitNOSO.test.ts:72:20

Check failure on line 72 in lib/lambda/adminActions/submitNOSO.test.ts

View workflow job for this annotation

GitHub Actions / test

lambda/adminActions/submitNOSO.test.ts > handler > should create a onemac package copy

AssertionError: expected { statusCode: 500, …(1) } to strictly equal { statusCode: 200, …(1) } - Expected + Received Object { "body": Object { - "message": "MD-00-0000 has been submitted.", + "message": "[ + { + \"received\": \"NOSO\", + \"code\": \"invalid_enum_value\", + \"options\": [ + \"update-values\", + \"update-id\", + \"delete\" + ], + \"path\": [ + \"action\" + ], + \"message\": \"Invalid enum value. Expected 'update-values' | 'update-id' | 'delete', received 'NOSO'\" + } + ]", }, - "statusCode": 200, + "statusCode": 500, } ❯ lambda/adminActions/submitNOSO.test.ts:72:20
});
});
12 changes: 6 additions & 6 deletions lib/lambda/adminActions/submitNOSO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const copyAttachments = async (data: any) => {
const attachPackage = await getPackage(copyAttachmentsFromId);
const attachPackageChangelog = await getPackageChangelog(copyAttachmentsFromId);

console.log("Attach Package", attachPackage);
console.log("Attach package changelog", attachPackageChangelog);
console.log("Attach Package", JSON.stringify(attachPackage));
console.log("Attach package changelog", JSON.stringify(attachPackageChangelog));

if (!attachPackage || attachPackage.found == false) {
console.error(`Copy Attachment Package of id: ${copyAttachmentsFromId} not found`);
Expand All @@ -62,8 +62,8 @@ export const copyAttachments = async (data: any) => {
if (attachPackage && attachPackage) {
// const attachments = structuredClone(attachPackage._source.changelog);
console.log("ANDIEEEEEEE ***********");
console.log("attachment package: ", attachPackage);
console.log(" change log: ", attachPackageChangelog.hits.hits[0]._source);
console.log("attachment package: ", JSON.stringify(attachPackage));
console.log(" change log: ", JSON.stringify(attachPackageChangelog.hits.hits[0]._source));

const attachments = attachPackageChangelog.hits.hits.reduce((prev, current) => {
// check that attachments exsists
Expand All @@ -72,12 +72,12 @@ export const copyAttachments = async (data: any) => {
}, []);

console.log("actual attachments:? ", JSON.stringify(attachments));
console.log("Current package: ", currentPackage);
console.log("Current package: ", JSON.stringify(currentPackage));

// add the attachments to the last index of the currentPackage Change Log
const last = currentPackageChangelog.hits.total.value - 1;
currentPackageChangelog.hits.hits[last]._source.attachments = attachments;
console.log("Did I change it??", currentPackageChangelog.hits.hits[last]);
console.log("Did I change it??", JSON.stringify(currentPackageChangelog.hits.hits[last]));

return currentPackageChangelog.hits.hits[last];
}
Expand Down
4 changes: 2 additions & 2 deletions lib/lambda/adminActions/updatePackage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("handler", () => {

const resultPackage = await handler(noActionevent);

expect(resultPackage.statusCode).toBe(400);
expect(resultPackage?.statusCode).toBe(400);
});
it("should return 400 if action is not found", async () => {
const noApackageEvent = {
Expand All @@ -43,7 +43,7 @@ describe("handler", () => {

const resultAction = await handler(noApackageEvent);

expect(resultAction.statusCode).toBe(400);
expect(resultAction?.statusCode).toBe(400);
});
it("should get a package", async () => {
const noActionevent = {
Expand Down
1 change: 1 addition & 0 deletions react-app/src/features/package/admin-changes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const AC_Update: FC<opensearch.changelog.Document> = () => {

export const AdminChange: FC<opensearch.changelog.Document> = (props) => {
console.log(props.event);
console.log(props);
const [label, Content] = useMemo(() => {
switch (props.event) {
case "toggle-withdraw-rai": {
Expand Down

0 comments on commit e71d117

Please sign in to comment.