|
3 | 3 | expect, |
4 | 4 | it, |
5 | 5 | describe, |
6 | | - jest |
| 6 | + jest, |
| 7 | + beforeEach |
7 | 8 | } from "@jest/globals" |
8 | 9 | import { |
9 | 10 | DEFAULT_DATE, |
@@ -175,3 +176,67 @@ describe("testPrescription2Intercept", () => { |
175 | 176 | expectGetItemCommand(TASK_VALUES[3].prescriptionID, TASK_VALUES[3].id) |
176 | 177 | }) |
177 | 178 | }) |
| 179 | + |
| 180 | +describe("testPrescription3Intercept", () => { |
| 181 | + beforeEach(() => { |
| 182 | + jest.useFakeTimers().setSystemTime(DEFAULT_DATE) |
| 183 | + jest.resetAllMocks() |
| 184 | + // Set TEST_PRESCRIPTIONS_3 only for these tests |
| 185 | + process.env.TEST_PRESCRIPTIONS_3 = ["abc", TASK_VALUES[2].prescriptionID, "def"].join(",") |
| 186 | + // Clear the module cache so it re-reads the env var |
| 187 | + jest.resetModules() |
| 188 | + }) |
| 189 | + |
| 190 | + afterEach(() => { |
| 191 | + // Clean up after each test to avoid affecting other test suites |
| 192 | + delete process.env.TEST_PRESCRIPTIONS_3 |
| 193 | + // Clear module cache again to ensure clean state for other tests |
| 194 | + jest.resetModules() |
| 195 | + }) |
| 196 | + |
| 197 | + it("Return 400 when test prescription 3 is submitted", async () => { |
| 198 | + const body = generateBody(3) |
| 199 | + // Only include entries 0, 1, and 2. Entry 2 contains TASK_VALUES[2] which matches TEST_PRESCRIPTIONS_3 |
| 200 | + const event: APIGatewayProxyEvent = generateMockEvent(body) |
| 201 | + |
| 202 | + const {handler, logger} = await import("../src/updatePrescriptionStatus") |
| 203 | + const loggerInfo = jest.spyOn(logger, "info") |
| 204 | + const response: APIGatewayProxyResult = await handler(event, {}) |
| 205 | + |
| 206 | + expect(response.statusCode).toEqual(400) |
| 207 | + expect(loggerInfo).toHaveBeenCalledWith( |
| 208 | + "Forcing error for INT test prescription. Simulating failure to write to database.") |
| 209 | + }) |
| 210 | +}) |
| 211 | + |
| 212 | +describe("testPrescription4Intercept", () => { |
| 213 | + beforeEach(() => { |
| 214 | + jest.useFakeTimers().setSystemTime(DEFAULT_DATE) |
| 215 | + jest.resetAllMocks() |
| 216 | + // Set TEST_PRESCRIPTIONS_4 only for these tests |
| 217 | + process.env.TEST_PRESCRIPTIONS_4 = ["abc", TASK_VALUES[2].prescriptionID, "def"].join(",") |
| 218 | + // Clear the module cache so it re-reads the env var |
| 219 | + jest.resetModules() |
| 220 | + }) |
| 221 | + |
| 222 | + afterEach(() => { |
| 223 | + // Clean up after each test to avoid affecting other test suites |
| 224 | + delete process.env.TEST_PRESCRIPTIONS_4 |
| 225 | + // Clear module cache again to ensure clean state for other tests |
| 226 | + jest.resetModules() |
| 227 | + }) |
| 228 | + |
| 229 | + it("Return 400 when test prescription 4 is submitted", async () => { |
| 230 | + const body = generateBody(3) |
| 231 | + // Only include entries 0, 1, and 2. Entry 2 contains TASK_VALUES[2] which matches TEST_PRESCRIPTIONS_4 |
| 232 | + const event: APIGatewayProxyEvent = generateMockEvent(body) |
| 233 | + |
| 234 | + const {handler, logger} = await import("../src/updatePrescriptionStatus") |
| 235 | + const loggerInfo = jest.spyOn(logger, "info") |
| 236 | + const response: APIGatewayProxyResult = await handler(event, {}) |
| 237 | + |
| 238 | + expect(response.statusCode).toEqual(429) |
| 239 | + expect(loggerInfo).toHaveBeenCalledWith( |
| 240 | + "Forcing error for INT test prescription. Simulating PSU capacity failure.") |
| 241 | + }) |
| 242 | +}) |
0 commit comments