-
Notifications
You must be signed in to change notification settings - Fork 599
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: flexibleChecksumsInputMiddleware.spec.ts
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/middleware-flexible-checksums/src/flexibleChecksumsInputMiddleware.spec.ts
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,50 @@ | ||
import { PreviouslyResolved } from "./configuration"; | ||
import { ResponseChecksumValidation } from "./constants"; | ||
import { flexibleChecksumsInputMiddleware } from "./flexibleChecksumsInputMiddleware"; | ||
|
||
describe(flexibleChecksumsInputMiddleware.name, () => { | ||
const mockNext = jest.fn(); | ||
const mockMiddlewareConfig = { | ||
requestValidationModeMember: "requestValidationModeMember", | ||
}; | ||
const mockConfig = { | ||
responseChecksumValidation: () => Promise.resolve(ResponseChecksumValidation.WHEN_SUPPORTED), | ||
} as PreviouslyResolved; | ||
|
||
afterEach(() => { | ||
expect(mockNext).toHaveBeenCalledTimes(1); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe("sets input.requestValidationModeMember", () => { | ||
it("when requestValidationModeMember is defined and responseChecksumValidation is supported", async () => { | ||
const handler = flexibleChecksumsInputMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, {}); | ||
await handler({ input: {} }); | ||
expect(mockNext).toHaveBeenCalledWith({ input: { requestValidationModeMember: "ENABLED" } }); | ||
}); | ||
}); | ||
|
||
describe("leaves input.requestValidationModeMember", () => { | ||
const mockArgs = { input: {} }; | ||
|
||
it("when requestValidationModeMember is not defined", async () => { | ||
const mockMiddlewareConfig = {}; | ||
|
||
const handler = flexibleChecksumsInputMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, {}); | ||
await handler(mockArgs); | ||
|
||
expect(mockNext).toHaveBeenCalledWith(mockArgs); | ||
}); | ||
|
||
it("when responseChecksumValidation is required", async () => { | ||
const mockConfig = { | ||
responseChecksumValidation: () => Promise.resolve(ResponseChecksumValidation.WHEN_REQUIRED), | ||
} as PreviouslyResolved; | ||
|
||
const handler = flexibleChecksumsInputMiddleware(mockConfig, mockMiddlewareConfig)(mockNext, {}); | ||
await handler(mockArgs); | ||
|
||
expect(mockNext).toHaveBeenCalledWith(mockArgs); | ||
}); | ||
}); | ||
}); |