Skip to content

Commit c2fd3b1

Browse files
committed
.
1 parent e78a26b commit c2fd3b1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

__tests__/middleware.unit.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@ api9.use(middleware3);
144144
/*** DEFINE TEST ROUTES ***/
145145
/******************************************************************************/
146146

147+
api.get('/', function(req, res) {
148+
res.status(200).json({
149+
testMiddleware: req.testMiddleware,
150+
})
151+
});
152+
api.post('/', function(req, res) {
153+
res.status(200).json({
154+
testMiddleware2: req.testMiddleware2,
155+
})
156+
});
157+
147158
api.get("/test", function (req, res) {
148159
res.status(200).json({
149160
method: "get",
@@ -327,6 +338,36 @@ api9.get("/data/test", (req, res) => {
327338
describe("Middleware Tests:", function () {
328339
// this.slow(300);
329340

341+
it('should return testMiddleware: 123 when calling the root route with GET', async function () {
342+
let _event = Object.assign({}, event, {path: "/"});
343+
let result = await new Promise((r) =>
344+
api.run(_event, {}, (e, res) => {
345+
r(res);
346+
})
347+
);
348+
expect(result).toEqual({
349+
multiValueHeaders: { "content-type": ["application/json"] },
350+
statusCode: 200,
351+
body: '{"testMiddleware":"123"}',
352+
isBase64Encoded: false,
353+
});
354+
})
355+
356+
it('should return testMiddleware2: 456 when calling the root route with POST', async function () {
357+
let _event = Object.assign({}, event, {path: "/", httpMethod: "POST"});
358+
let result = await new Promise((r) =>
359+
api.run(_event, {}, (e, res) => {
360+
r(res);
361+
})
362+
);
363+
expect(result).toEqual({
364+
multiValueHeaders: { "content-type": ["application/json"] },
365+
statusCode: 200,
366+
body: '{"testMiddleware2":"456"}',
367+
isBase64Encoded: false,
368+
});
369+
})
370+
330371
it("Set Values in res object", async function () {
331372
let _event = Object.assign({}, event, {});
332373
let result = await new Promise((r) =>

0 commit comments

Comments
 (0)