|
| 1 | +import { PreviouslyResolved } from "./configuration"; |
| 2 | +import { ResponseChecksumValidation } from "./constants"; |
| 3 | +import { flexibleChecksumsInputMiddleware } from "./flexibleChecksumsInputMiddleware"; |
| 4 | + |
| 5 | +describe(flexibleChecksumsInputMiddleware.name, () => { |
| 6 | + const mockNext = jest.fn(); |
| 7 | + const mockMiddlewareConfig = { |
| 8 | + requestValidationModeMember: "requestValidationModeMember", |
| 9 | + }; |
| 10 | + const mockConfig = { |
| 11 | + responseChecksumValidation: () => Promise.resolve(ResponseChecksumValidation.WHEN_SUPPORTED), |
| 12 | + } as PreviouslyResolved; |
| 13 | + |
| 14 | + afterEach(() => { |
| 15 | + expect(mockNext).toHaveBeenCalledTimes(1); |
| 16 | + jest.clearAllMocks(); |
| 17 | + }); |
| 18 | + |
| 19 | + describe("sets input.requestValidationModeMember", () => { |
| 20 | + it("when requestValidationModeMember is defined and responseChecksumValidation is supported", async () => { |
| 21 | + const handler = flexibleChecksumsInputMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, {}); |
| 22 | + await handler({ input: {} }); |
| 23 | + expect(mockNext).toHaveBeenCalledWith({ input: { requestValidationModeMember: "ENABLED" } }); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe("leaves input.requestValidationModeMember", () => { |
| 28 | + const mockArgs = { input: {} }; |
| 29 | + |
| 30 | + it("when requestValidationModeMember is not defined", async () => { |
| 31 | + const mockMiddlewareConfig = {}; |
| 32 | + |
| 33 | + const handler = flexibleChecksumsInputMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, {}); |
| 34 | + await handler(mockArgs); |
| 35 | + |
| 36 | + expect(mockNext).toHaveBeenCalledWith(mockArgs); |
| 37 | + }); |
| 38 | + |
| 39 | + it("when responseChecksumValidation is required", async () => { |
| 40 | + const mockConfig = { |
| 41 | + responseChecksumValidation: () => Promise.resolve(ResponseChecksumValidation.WHEN_REQUIRED), |
| 42 | + } as PreviouslyResolved; |
| 43 | + |
| 44 | + const handler = flexibleChecksumsInputMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, {}); |
| 45 | + await handler(mockArgs); |
| 46 | + |
| 47 | + expect(mockNext).toHaveBeenCalledWith(mockArgs); |
| 48 | + }); |
| 49 | + }); |
| 50 | +}); |
0 commit comments