-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f1a2d6
commit e71d117
Showing
4 changed files
with
83 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / coverage-reportlambda/adminActions/submitNOSO.test.ts > handler > should create a onemac package copy
Check failure on line 72 in lib/lambda/adminActions/submitNOSO.test.ts GitHub Actions / testlambda/adminActions/submitNOSO.test.ts > handler > should create a onemac package copy
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters