UNPKG

@kilterset/auth0-actions-testing

Version:

Test and develop Auth0 Actions or Okta CIC Actions locally.

105 lines 9 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_test_1 = __importDefault(require("node:test")); const authentication_1 = require("../../mock/api/authentication"); const node_assert_1 = require("node:assert"); (0, node_test_1.default)("authentication mock", (t) => __awaiter(void 0, void 0, void 0, function* () { const baseApi = Symbol("Base API"); yield t.test("challengeWith", (t) => __awaiter(void 0, void 0, void 0, function* () { yield t.test("factor", (t) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; const { build, state } = (0, authentication_1.authenticationMock)("Another Flow", { userId: "42" }); const api = build(baseApi); api.challengeWith({ type: "email" }); (0, node_assert_1.ok)(state.challenge, "Expected challenge to be set"); (0, node_assert_1.strictEqual)((_a = state.challenge.default) === null || _a === void 0 ? void 0 : _a.type, "email", "Expected default factor to be set"); (0, node_assert_1.strictEqual)((_b = state.challenge.allOptions) === null || _b === void 0 ? void 0 : _b.length, 1, "Expected additional factors to be set"); (0, node_assert_1.strictEqual)((_c = state.challenge.allOptions) === null || _c === void 0 ? void 0 : _c[0].type, "email", "Expected additional factors to be email"); })); yield t.test("additional factors", (t) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d; const { build, state } = (0, authentication_1.authenticationMock)("Another Flow", { userId: "42" }); const api = build(baseApi); api.challengeWith({ type: "otp" }, { additionalFactors: [{ type: "email" }] }); (0, node_assert_1.ok)(state.challenge, "Expected challenge to be set"); (0, node_assert_1.strictEqual)((_a = state.challenge.default) === null || _a === void 0 ? void 0 : _a.type, "otp", "Expected default factor to be set"); (0, node_assert_1.strictEqual)((_b = state.challenge.allOptions) === null || _b === void 0 ? void 0 : _b.length, 2, "Expected additional factors to be set"); (0, node_assert_1.strictEqual)((_c = state.challenge.allOptions) === null || _c === void 0 ? void 0 : _c[0].type, "otp", "Expected additional factor to be otp"); (0, node_assert_1.strictEqual)((_d = state.challenge.allOptions) === null || _d === void 0 ? void 0 : _d[1].type, "email", "Expected additional factor to be email"); })); })); yield t.test('challengeWithAny', (t) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; const { build, state } = (0, authentication_1.authenticationMock)("Another Flow", { userId: "42" }); const api = build(baseApi); api.challengeWithAny([{ type: "email" }, { type: "otp" }]); (0, node_assert_1.ok)(state.challenge, "Expected challenge to be set"); (0, node_assert_1.strictEqual)(state.challenge.default, undefined, "Expected default factor to be undefined"); (0, node_assert_1.strictEqual)((_a = state.challenge.allOptions) === null || _a === void 0 ? void 0 : _a.length, 2, "Expected additional factors to be set"); (0, node_assert_1.strictEqual)((_b = state.challenge.allOptions) === null || _b === void 0 ? void 0 : _b[0].type, "email", "Expected additional factor to be email"); (0, node_assert_1.strictEqual)((_c = state.challenge.allOptions) === null || _c === void 0 ? void 0 : _c[1].type, "otp", "Expected additional factor to be otp"); })); yield t.test("enrollWith", (t) => __awaiter(void 0, void 0, void 0, function* () { yield t.test("factor", (t) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; const { build, state } = (0, authentication_1.authenticationMock)("Another Flow", { userId: "42" }); const api = build(baseApi); api.enrollWith({ type: "email" }); (0, node_assert_1.ok)(state.enrollment, "Expected enrollment to be set"); (0, node_assert_1.strictEqual)((_a = state.enrollment.default) === null || _a === void 0 ? void 0 : _a.type, "email", "Expected default factor to be set"); (0, node_assert_1.strictEqual)((_b = state.enrollment.allOptions) === null || _b === void 0 ? void 0 : _b.length, 1, "Expected additional factors to be set"); (0, node_assert_1.strictEqual)((_c = state.enrollment.allOptions) === null || _c === void 0 ? void 0 : _c[0].type, "email", "Expected additional factors to be email"); })); yield t.test("additional factors", (t) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d; const { build, state } = (0, authentication_1.authenticationMock)("Another Flow", { userId: "42" }); const api = build(baseApi); api.enrollWith({ type: "otp" }, { additionalFactors: [{ type: "email" }] }); (0, node_assert_1.ok)(state.enrollment, "Expected enrollment to be set"); (0, node_assert_1.strictEqual)((_a = state.enrollment.default) === null || _a === void 0 ? void 0 : _a.type, "otp", "Expected default factor to be set"); (0, node_assert_1.strictEqual)((_b = state.enrollment.allOptions) === null || _b === void 0 ? void 0 : _b.length, 2, "Expected additional factors to be set"); (0, node_assert_1.strictEqual)((_c = state.enrollment.allOptions) === null || _c === void 0 ? void 0 : _c[0].type, "otp", "Expected additional factor to be otp"); (0, node_assert_1.strictEqual)((_d = state.enrollment.allOptions) === null || _d === void 0 ? void 0 : _d[1].type, "email", "Expected additional factor to be email"); })); })); yield t.test('enrollWithAny', (t) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; const { build, state } = (0, authentication_1.authenticationMock)("Another Flow", { userId: "42" }); const api = build(baseApi); api.enrollWithAny([{ type: "email" }, { type: "otp" }]); (0, node_assert_1.ok)(state.enrollment, "Expected enrollment to be set"); (0, node_assert_1.strictEqual)(state.enrollment.default, undefined, "Expected default factor to be undefined"); (0, node_assert_1.strictEqual)((_a = state.enrollment.allOptions) === null || _a === void 0 ? void 0 : _a.length, 2, "Expected additional factors to be set"); (0, node_assert_1.strictEqual)((_b = state.enrollment.allOptions) === null || _b === void 0 ? void 0 : _b[0].type, "email", "Expected additional factor to be email"); (0, node_assert_1.strictEqual)((_c = state.enrollment.allOptions) === null || _c === void 0 ? void 0 : _c[1].type, "otp", "Expected additional factor to be otp"); })); yield t.test("setPrimaryUser", (t) => __awaiter(void 0, void 0, void 0, function* () { const { build, state } = (0, authentication_1.authenticationMock)("Another Flow", { userId: "42" }); const api = build(baseApi); api.setPrimaryUser("43"); (0, node_assert_1.strictEqual)(state.primaryUserId, "43", "Expected primary user to be set"); })); yield t.test("recordMethod", (t) => __awaiter(void 0, void 0, void 0, function* () { const { build, state } = (0, authentication_1.authenticationMock)("Another Flow", { userId: "42" }); const api = build(baseApi); api.recordMethod("https://example.com"); (0, node_assert_1.strictEqual)(state.newlyRecordedMethods.length, 1, "Expected newly recorded methods to be set"); (0, node_assert_1.strictEqual)(state.newlyRecordedMethods[0], "https://example.com", "Expected newly recorded method to be set"); api.recordMethod("https://another.example.com"); (0, node_assert_1.strictEqual)(state.newlyRecordedMethods.length, 2, "Expected newly recorded methods to be set"); (0, node_assert_1.strictEqual)(state.newlyRecordedMethods[1], "https://another.example.com", "Expected newly recorded method to be set"); })); })); //# sourceMappingURL=authentication.test.js.map