Skip to content

Commit

Permalink
Fix prompt testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanKramer authored and Aupajo committed Nov 26, 2024
1 parent 90ee238 commit 239b23f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
6 changes: 6 additions & 0 deletions examples/Login/render-prompt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Shows how to test the rendering of a prompt.
*/
exports.onExecutePostLogin = async (event, api) => {
api.prompt.render("test-prompt-id");
};
22 changes: 22 additions & 0 deletions examples/Login/render-prompt.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const test = require("node:test");
const { strictEqual } = require("node:assert");
const { onExecutePostLogin } = require("./render-prompt");
const { nodeTestRunner } = require("@kilterset/auth0-actions-testing");

test("rendering a prompt", async (t) => {
const { auth0 } = await nodeTestRunner.actionTestSetup(t);

await t.test("renders a prompt", async () => {
const action = auth0.mock.actions.postLogin();

await action.simulate(onExecutePostLogin);

const { rendered } = action.prompt;

strictEqual(
rendered.promptId,
"test-prompt-id",
"Expected prompt ID to be `test-prompt-id`"
);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kilterset/auth0-actions-testing",
"version": "0.3.3",
"version": "0.3.4",
"description": "Test and develop Auth0 Actions or Okta CIC Actions locally.",
"repository": "https://github.com/kilterset/auth0-actions-testing",
"homepage": "https://github.com/kilterset/auth0-actions-testing#readme",
Expand Down
4 changes: 3 additions & 1 deletion src/mock/api/post-login.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Auth0, { Factor, MultifactorEnableOptions } from "../../types";
import Auth0, { MultifactorEnableOptions, PromptState } from "../../types";
import { cache as mockCache } from "./cache";
import { user as mockUser } from "../user";
import { request as mockRequest } from "../request";
Expand Down Expand Up @@ -69,6 +69,7 @@ export interface PostLoginState {
idToken: {
claims: Record<string, unknown>;
};
prompt: { rendered: PromptState | null };
multifactor: {
enabled:
| false
Expand Down Expand Up @@ -123,6 +124,7 @@ export function postLogin({
cache: apiCache,
idToken: idToken.state,
multifactor: multifactor.state,
prompt: prompt.state,
samlResponse: samlResponse.state,
validation: validation.state,
get redirect() {
Expand Down
7 changes: 1 addition & 6 deletions src/mock/api/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { MultifactorEnableOptions } from "../../types";

interface PromptState {
promptId: string;
promptOptions?: { [key: string]: unknown };
}
import { PromptState } from "../../types";

export function promptMock(flow: string) {
const state: { rendered: PromptState | null } = {
Expand Down
1 change: 1 addition & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./connection";
export * from "./factor";
export * from "./identity";
export * from "./organization";
export * from "./prompt";
export * from "./request";
export * from "./risk-assessment";
export * from "./session";
Expand Down
4 changes: 4 additions & 0 deletions src/types/prompt.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface PromptState {
promptId: string;
promptOptions?: { [key: string]: unknown };
}

0 comments on commit 239b23f

Please sign in to comment.