-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 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
61 changes: 61 additions & 0 deletions
61
packages/elements-react/src/theme/default/utils/__tests__/url.spec.ts
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,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", | ||
) | ||
}) | ||
}) | ||
}) |
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