-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mock prompt API for testing rendering of forms
- Loading branch information
1 parent
96a09eb
commit 79799e6
Showing
5 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MultifactorEnableOptions } from "../../types"; | ||
|
||
interface PromptState { | ||
promptId: string; | ||
promptOptions?: { [key: string]: unknown }; | ||
} | ||
|
||
export function promptMock(flow: string) { | ||
const state: { rendered: PromptState | null } = { | ||
rendered: null, | ||
}; | ||
|
||
const build = <T>(api: T) => ({ | ||
render: (promptId: string, promptOptions?: { [key: string]: unknown }) => { | ||
state.rendered = { promptId, promptOptions }; | ||
}, | ||
}); | ||
|
||
return { state, build }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { deepStrictEqual, ok, strictEqual } from "node:assert"; | ||
import test from "node:test"; | ||
import { promptMock } from "../../mock/api/prompt"; | ||
|
||
test("prompt", async (t) => { | ||
const baseApi = Symbol("Base API"); | ||
|
||
await t.test("render", async (t) => { | ||
const { build, state } = promptMock("Another Flow"); | ||
const api = build(baseApi); | ||
|
||
strictEqual(state.rendered, null); | ||
|
||
api.render("prompt-id", { fields: { foo: "bar" } }); | ||
|
||
ok(Boolean(state.rendered), "Expected prompt to be rendered"); | ||
|
||
deepStrictEqual(state.rendered, { | ||
promptId: "prompt-id", | ||
promptOptions: { fields: { foo: "bar" } }, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters