@kilterset/auth0-actions-testing
Version:
Test and develop Auth0 Actions or Okta CIC Actions locally.
55 lines • 2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.authenticationMock = authenticationMock;
function authenticationMock(_flow, { userId }) {
let numCallsToSetPrimaryUser = 0;
const state = {
primaryUserId: userId,
challenge: false,
enrollment: false,
newlyRecordedMethods: [],
};
const build = (api) => ({
challengeWith: (factor, options) => {
var _a;
const additionalFactors = (_a = options === null || options === void 0 ? void 0 : options.additionalFactors) !== null && _a !== void 0 ? _a : [];
state.challenge = {
allOptions: [factor, ...additionalFactors],
default: factor,
};
},
challengeWithAny(factors) {
state.challenge = {
allOptions: factors,
default: undefined,
};
},
enrollWith: (factor, options) => {
var _a;
const additionalFactors = (_a = options === null || options === void 0 ? void 0 : options.additionalFactors) !== null && _a !== void 0 ? _a : [];
state.enrollment = {
allOptions: [factor, ...additionalFactors],
default: factor,
};
},
enrollWithAny(factors) {
state.enrollment = {
allOptions: factors,
default: undefined,
};
},
setPrimaryUser: (primaryUserId) => {
numCallsToSetPrimaryUser++;
if (numCallsToSetPrimaryUser > 1) {
throw new Error("`authentication.setPrimaryUser` can only be set once per transaction");
}
state.primaryUserId = primaryUserId;
},
recordMethod: (providerUrl) => {
state.newlyRecordedMethods.push(providerUrl);
return api;
},
});
return { state, build };
}
//# sourceMappingURL=authentication.js.map