Skip to content

Commit

Permalink
test: fix assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkvasnicak committed Mar 26, 2024
1 parent b1e9261 commit d2d6e00
Showing 1 changed file with 61 additions and 7 deletions.
68 changes: 61 additions & 7 deletions packages/frames.js/src/next/getCurrentUrl.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import { getCurrentUrl } from "./getCurrentUrl";

describe("getCurrentUrl", () => {
beforeEach(() => {
// @ts-expect-error
process.env.NODE_ENV = "test";
});

afterEach(() => {
delete process.env.VERCEL_URL;
delete process.env.APP_URL;
});

it("works with relative url property", () => {
expect(
getCurrentUrl({
url: "/test",
headers: {
host: "localhost",
},
} as unknown as Request)
).toEqual(new URL("http://localhost/test"));
} as unknown as Request)?.toString()
).toEqual("http://localhost/test");
});

it("takes value from process.env.VERCEL_URL if available", () => {
Expand All @@ -21,13 +32,56 @@ describe("getCurrentUrl", () => {
headers: {
host: "localhost",
},
} as unknown as Request)
).toEqual(new URL("http://test.com/"));
} as unknown as Request)?.toString()
).toEqual("http://test.com/test");
});

it("takes value from process.env.VERCEL_URL and uses https if NODE_ENV=production if available", () => {
process.env.VERCEL_URL = "test.com";
// @ts-expect-error
process.env.NODE_ENV = "production";

expect(
getCurrentUrl({
url: "/test",
headers: {
host: "localhost",
},
} as unknown as Request)?.toString()
).toEqual("https://test.com/test");
});

it("takes value from process.env.APP_URL if available", () => {
process.env.APP_URL = "app.com";

expect(
getCurrentUrl({
url: "/test",
headers: {
host: "localhost",
},
} as unknown as Request)?.toString()
).toEqual("http://app.com/test");
});

it("takes value from process.env.APP_URL and uses https if NODE_ENV=production if available", () => {
process.env.APP_URL = "test.com";
// @ts-expect-error
process.env.NODE_ENV = "production";

expect(
getCurrentUrl({
url: "/test",
headers: {
host: "localhost",
},
} as unknown as Request)?.toString()
).toEqual("https://test.com/test");
});

it("supports proper url in Request object", () => {
expect(getCurrentUrl(new Request("http://localhost/test"))).toEqual(
new URL("http://localhost/test")
);
expect(
getCurrentUrl(new Request("http://localhost/test"))?.toString()
).toEqual("http://localhost/test");
});
});

0 comments on commit d2d6e00

Please sign in to comment.