From 239b23fdea3a02d4ac65f706ed146befd0012038 Mon Sep 17 00:00:00 2001 From: Nathan Kramer Date: Tue, 26 Nov 2024 14:31:09 +1100 Subject: [PATCH] Fix prompt testing --- examples/Login/render-prompt.js | 6 ++++++ examples/Login/render-prompt.test.js | 22 ++++++++++++++++++++++ package.json | 2 +- src/mock/api/post-login.ts | 4 +++- src/mock/api/prompt.ts | 7 +------ src/types/index.d.ts | 1 + src/types/prompt.d.ts | 4 ++++ 7 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 examples/Login/render-prompt.js create mode 100644 examples/Login/render-prompt.test.js create mode 100644 src/types/prompt.d.ts diff --git a/examples/Login/render-prompt.js b/examples/Login/render-prompt.js new file mode 100644 index 0000000..59fe39c --- /dev/null +++ b/examples/Login/render-prompt.js @@ -0,0 +1,6 @@ +/** + * Shows how to test the rendering of a prompt. + */ +exports.onExecutePostLogin = async (event, api) => { + api.prompt.render("test-prompt-id"); +}; diff --git a/examples/Login/render-prompt.test.js b/examples/Login/render-prompt.test.js new file mode 100644 index 0000000..847e7d0 --- /dev/null +++ b/examples/Login/render-prompt.test.js @@ -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`" + ); + }); +}); diff --git a/package.json b/package.json index 172f0eb..cf1d8d0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/mock/api/post-login.ts b/src/mock/api/post-login.ts index 153e74b..43d329a 100644 --- a/src/mock/api/post-login.ts +++ b/src/mock/api/post-login.ts @@ -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"; @@ -69,6 +69,7 @@ export interface PostLoginState { idToken: { claims: Record; }; + prompt: { rendered: PromptState | null }; multifactor: { enabled: | false @@ -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() { diff --git a/src/mock/api/prompt.ts b/src/mock/api/prompt.ts index d09ef89..d31c1ba 100644 --- a/src/mock/api/prompt.ts +++ b/src/mock/api/prompt.ts @@ -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 } = { diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 47947ae..3baac6b 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -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"; diff --git a/src/types/prompt.d.ts b/src/types/prompt.d.ts new file mode 100644 index 0000000..042736f --- /dev/null +++ b/src/types/prompt.d.ts @@ -0,0 +1,4 @@ +export interface PromptState { + promptId: string; + promptOptions?: { [key: string]: unknown }; +}