From bc71be85e09d6c03c7a0d4b6a7210fba0a18f529 Mon Sep 17 00:00:00 2001 From: Tushar Pandey Date: Mon, 10 Mar 2025 14:52:08 +0530 Subject: [PATCH] udpate branch with main, add tests for pathUtils --- .shiprc | 6 +++++ src/server/auth-client.ts | 2 +- src/utils/pathUtils.test.ts | 53 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 .shiprc create mode 100644 src/utils/pathUtils.test.ts diff --git a/.shiprc b/.shiprc new file mode 100644 index 000000000..362cab19c --- /dev/null +++ b/.shiprc @@ -0,0 +1,6 @@ +{ + "files": { + ".version": [] + }, + "postbump": "pnpm run docs" +} diff --git a/src/server/auth-client.ts b/src/server/auth-client.ts index 58a6e5502..28a44203e 100644 --- a/src/server/auth-client.ts +++ b/src/server/auth-client.ts @@ -2,6 +2,7 @@ import { NextResponse, type NextRequest } from "next/server"; import * as jose from "jose"; import * as oauth from "oauth4webapi"; +import { version } from "../../package.json"; import { AccessTokenError, AccessTokenErrorCode, @@ -154,7 +155,6 @@ export class AuthClient { const timeout = options.httpTimeout ?? 5000; if (enableTelemetry) { const name = "nextjs-auth0"; - const version = "4.0.2"; headers.set("User-Agent", `${name}/${version}`); headers.set( diff --git a/src/utils/pathUtils.test.ts b/src/utils/pathUtils.test.ts new file mode 100644 index 000000000..a70c340ec --- /dev/null +++ b/src/utils/pathUtils.test.ts @@ -0,0 +1,53 @@ +import { describe, expect, it } from "vitest"; + +import { + ensureNoLeadingSlash, + ensureTrailingSlash, + removeTrailingSlash +} from "./pathUtils"; + +describe("pathUtils", () => { + describe("ensureTrailingSlash", () => { + it("should add a trailing slash if not present", () => { + expect(ensureTrailingSlash("example.com/path")).toBe("example.com/path/"); + }); + + it("should not add a trailing slash if already present", () => { + expect(ensureTrailingSlash("example.com/path/")).toBe( + "example.com/path/" + ); + }); + + it("should return the same string if it is empty", () => { + expect(ensureTrailingSlash("")).toBe(""); + }); + }); + + describe("ensureNoLeadingSlash", () => { + it("should remove the leading slash if present", () => { + expect(ensureNoLeadingSlash("/example/path")).toBe("example/path"); + }); + + it("should not remove the leading slash if not present", () => { + expect(ensureNoLeadingSlash("example/path")).toBe("example/path"); + }); + + it("should return the same string if it is empty", () => { + expect(ensureNoLeadingSlash("")).toBe(""); + }); + }); + + describe("removeTrailingSlash", () => { + it("should remove the trailing slash if present", () => { + expect(removeTrailingSlash("example.com/path/")).toBe("example.com/path"); + }); + + it("should not remove the trailing slash if not present", () => { + expect(removeTrailingSlash("example.com/path")).toBe("example.com/path"); + }); + + it("should return the same string if it is empty", () => { + expect(removeTrailingSlash("")).toBe(""); + }); + }); +});