Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
naorpeled committed Feb 3, 2023
1 parent c2fd3b1 commit ec07a57
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions __tests__/middleware.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,22 @@ api9.use(middleware3);
/*** DEFINE TEST ROUTES ***/
/******************************************************************************/

api.get('/', function(req, res) {
api.get("/", function(req, res) {
res.status(200).json({
testMiddleware: req.testMiddleware,
})
});
api.post('/', function(req, res) {
api.post("/", function(req, res) {
res.status(200).json({
testMiddleware2: req.testMiddleware2,
})
});
api.any("/", function(req, res) {
res.status(200).json({
testMiddleware: req.testMiddleware,
testMiddleware2: req.testMiddleware2,
})
});

api.get("/test", function (req, res) {
res.status(200).json({
Expand Down Expand Up @@ -368,6 +374,21 @@ describe("Middleware Tests:", function () {
});
})

it('should return testMiddleware: 123 when calling the root route with PATCH', async function () {
let _event = Object.assign({}, event, {path: "/", httpMethod: "PATCH"});
let result = await new Promise((r) =>
api.run(_event, {}, (e, res) => {
r(res);
})
);
expect(result).toEqual({
multiValueHeaders: { "content-type": ["application/json"] },
statusCode: 200,
body: '{"testMiddleware":"123","testMiddleware2":"456"}',
isBase64Encoded: false,
});
})

it("Set Values in res object", async function () {
let _event = Object.assign({}, event, {});
let result = await new Promise((r) =>
Expand Down

0 comments on commit ec07a57

Please sign in to comment.