Skip to content

Commit

Permalink
chore: synchronize workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Dec 20, 2024
1 parent 7fa78d2 commit acde37b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export function DefaultText({ node, attributes }: OryNodeTextProps) {
secrets: UiText[]
}
).secrets?.map((text: UiText, index) => (
<pre data-testid={`ory/ui/node/text/lookup_secret_codes/text`} key={index}>
<pre
data-testid={`ory/ui/node/text/lookup_secret_codes/text`}
key={index}
>
<code>{text ? uiTextToFormattedMessage(text, intl) : ""}</code>
</pre>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { restartFlowUrl, initFlowUrl } from "../url"

describe("url utils", () => {
describe("restartFlowUrl", () => {
it("should return request_url if present", () => {
const flow = { request_url: "http://example.com/request" }
const fallback = "http://example.com/fallback"
expect(restartFlowUrl(flow, fallback)).toBe(flow.request_url)
})

it("should return fallback with return_to if request_url is not present", () => {
const flow = { return_to: "http://example.com/return" }
const fallback = "http://example.com/fallback"
expect(restartFlowUrl(flow, fallback)).toBe(
"http://example.com/fallback?return_to=http%3A%2F%2Fexample.com%2Freturn",
)
})

it("should return fallback if neither request_url nor return_to are present", () => {
const flow = {}
const fallback = "http://example.com/fallback"
expect(restartFlowUrl(flow, fallback)).toBe(fallback)
})
})

describe("initFlowUrl", () => {
it("should return sdkUrl with flowType and return_to if present in flow", () => {
const sdkUrl = "http://example.com"
const flowType = "login"
const flow = { return_to: "http://example.com/return" }
expect(initFlowUrl(sdkUrl, flowType, flow)).toBe(
"http://example.com/self-service/login/browser?return_to=http%3A%2F%2Fexample.com%2Freturn",
)
})

xit("should return sdkUrl with flowType and return_to if present in window location", () => {
const sdkUrl = "http://example.com"
const flowType = "login"
const flow = {}

// Not sure how to mock this.
;(window.location.href =
"http://example.com?return_to=http://example.com/return"),
expect(initFlowUrl(sdkUrl, flowType, flow)).toBe(
"http://example.com/self-service/login/browser?return_to=http%3A%2F%2Fexample.com%2Freturn",
)
})

xit("should return sdkUrl with flowType if return_to is not present", () => {
const sdkUrl = "http://example.com"
const flowType = "login"
const flow = {}

// Not sure how to mock this.
window.location.href = "http://example.com"
expect(initFlowUrl(sdkUrl, flowType, flow)).toBe(
"http://example.com/self-service/login/browser",
)
})
})
})
3 changes: 3 additions & 0 deletions packages/elements-react/src/theme/default/utils/url.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

export function restartFlowUrl(
flow: { request_url?: string; return_to?: string },
fallback: string,
Expand Down

0 comments on commit acde37b

Please sign in to comment.