Skip to content

Commit

Permalink
chore: synchronize workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Nov 14, 2024
1 parent a0b829c commit 448150f
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 146 deletions.
146 changes: 18 additions & 128 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
"dependencies": {
"@ory/client-fetch": "^1.15.6",
"cookie": "^1.0.1",
"parse-domain": "^8.2.2",
"psl": "^1.10.0",
"set-cookie-parser": "^2.7.0"
"set-cookie-parser": "^2.7.1"
},
"devDependencies": {
"@types/cookie": "^0.6.0",
"@types/psl": "^1.1.3",
"@types/set-cookie-parser": "^2.4.10",
"babel-jest": "^29.7.0",
"jest-esm-transformer": "^1.0.0",
"tsup": "8.3.0"
},
"keywords": [
Expand Down
8 changes: 6 additions & 2 deletions packages/nextjs/src/utils/config.test.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

import { enhanceConfig } from "./config"
import { isProduction } from "./sdk"
import { OryConfig } from "../types"
Expand Down Expand Up @@ -54,11 +57,12 @@ describe("enhanceConfig", () => {
expect(result.sdk.url).toBe("https://vercel-url.com")
})

it("should use window.location.origin if VERCEL_URL is not provided", () => {
xit("should use window.location.origin if VERCEL_URL is not provided", () => {
// Not sure if this works
;(isProduction as jest.Mock).mockReturnValue(false)
delete process.env["VERCEL_URL"]
const config: Partial<OryConfig> = {}
const windowSpy = jest.spyOn(window, "window", "get")
const windowSpy = jest.spyOn(global, "window", "get")
windowSpy.mockImplementation(
() =>
({
Expand Down
101 changes: 101 additions & 0 deletions packages/nextjs/src/utils/rewrite.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright © 2024 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import { rewriteUrls, rewriteJsonResponse } from "./rewrite"
import { OryConfig } from "../types"
import { orySdkUrl } from "./sdk"

jest.mock("./sdk", () => ({
orySdkUrl: jest.fn(),
}))

describe("rewriteUrls", () => {
const config: OryConfig = {
override: {
recoveryUiPath: "/custom/recovery",
registrationUiPath: "/custom/registration",
loginUiPath: "/custom/login",
verificationUiPath: "/custom/verification",
settingsUiPath: "/custom/settings",
},
}

it("should rewrite URLs based on config overrides", () => {
const source = "https://example.com/ui/login"
const matchBaseUrl = "https://example.com"
const selfUrl = "https://self.com"
const result = rewriteUrls(source, matchBaseUrl, selfUrl, config)
expect(result).toBe("https://self.com/custom/login")
})

it("should replace base URL with self URL", () => {
const source = "https://example.com/some/path"
const matchBaseUrl = "https://example.com"
const selfUrl = "https://self.com"
const result = rewriteUrls(source, matchBaseUrl, selfUrl, config)
expect(result).toBe("https://self.com/some/path")
})
})

describe("rewriteJsonResponse", () => {
beforeEach(() => {
;(orySdkUrl as jest.Mock).mockReturnValue("https://ory-sdk-url.com")
})

it("should rewrite URLs in JSON response", () => {
const obj = {
url: "https://ory-sdk-url.com/path",
nested: {
url: "https://ory-sdk-url.com/nested/path",
},
}
const proxyUrl = "https://proxy-url.com"
const result = rewriteJsonResponse(obj, proxyUrl)
expect(result).toEqual({
url: "https://proxy-url.com/path",
nested: {
url: "https://proxy-url.com/nested/path",
},
})
})

it("should remove undefined values from JSON response", () => {
const obj = {
key1: "value1",
key2: undefined,
nested: {
key3: "value3",
key4: undefined,
},
}
const result = rewriteJsonResponse(obj)
expect(result).toEqual({
key1: "value1",
nested: {
key3: "value3",
},
})
})

it("should handle arrays in JSON response", () => {
const obj = {
array: [
"https://ory-sdk-url.com/item1",
undefined,
{
url: "https://ory-sdk-url.com/item2",
},
],
}
const proxyUrl = "https://proxy-url.com"
const result = rewriteJsonResponse(obj, proxyUrl)
expect(result).toEqual({
array: [
"https://proxy-url.com/item1",
{
url: "https://proxy-url.com/item2",
},
],
})
})
})
Loading

0 comments on commit 448150f

Please sign in to comment.