'How to write the JEST Unit test for the require('passport-openidconnect').Strategy node module
I am having the file with OIDC implementation like below.
const passport = require('passport');
const passportOidc = require('passport-openidconnect').Strategy;
module.exports.oktaOidcVerify = (req, res, next) => {
try {
const oidcStrategy = new passportOidc(
oidcOptions,
async (
issuer,
profile,
context,
idToken,
accessToken,
refreshToken,
done
) => {
try {
if (!profile.id) {
return done(
new Error('Profile not found'),
null
);
} else {
return done(null, profile, {
accessToken,
refreshToken
});
}
} catch (err) {
}
}
);
passport.use('oidc', oidcStrategy);
passport.serializeUser((user, next) => {
next(null, user);
});
passport.deserializeUser((obj, next) => {
next(null, obj);
});
next();
} catch (error) {
}
};
In my express server.js file, I am adding as the middleware like below
app.use(passport.initialize());
app.use(oktaOidcVerify);
Is there a way to write JEST Unit Test case for only the "oktaOidcVerify" function by passing the sample request?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
