How to test kong.response.exit function with jest?

In my plugin I try to detect missing headers, one of those is the authorization header like so.

        let basic_authorization = await kong.request.getHeader("authorization");
        if (basic_authorization === undefined || basic_authorization === null) {
            console.log("statement reached: " + basic_authorization);
            return kong.response.exit(403, "Forbidden: Authentication failed");

When I run JEST this function (the log) is HIT, which is exactly what I want to test. so the response.exit code should return 403. (which it does when I test with PostMan). However the response.status in this test returns 200 and not 403.
I don’t understand how this can be?

I require the kong-pdk/plugin_test file from my node-modules, and this works, but I don’t know if the mockfile modifies something. Nontheless my function is clearly called as the console.log is hit, but it seems to completely ignore return kong.response.exit(403, “Forbidden: Authentication failed”);

const {
} = require('kong-pdk/plugin_test');

© 2019 Kong Inc.    Terms  •  Privacy  •  FAQ