The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update case-sensitive-keys.test.ts
Kiran K817088aad756
diff --git a/apps/web/tests/misc/case-sensitive-keys.test.ts b/apps/web/tests/misc/case-sensitive-keys.test.tsindex 2a2d804825..53b0da27cc 100644--- a/apps/web/tests/misc/case-sensitive-keys.test.ts+++ b/apps/web/tests/misc/case-sensitive-keys.test.ts@@ -1,142 +1,77 @@import { decodeKey, encodeKey } from "@/lib/api/links/case-sensitivity";import { describe, expect, it } from "vitest";-const basicKeys = [- "Hello World",- "Case-Sensitive123",- "!@#$%^&*()",- "🌟⭐️✨",- "Mixed🌟Emoji⭐️Text",- "ñáéíóúü",- "漢字",- "abc",-];--const edgeCaseKeys = [- "", // empty string- " ", // single space- " ", // multiple spaces- "\t\n\r", // control characters- "a".repeat(100), // long string- "a".repeat(1000), // very long string-];--const urlLikeKeys = [- "path/to/resource",- "query?param=value",- "hash#section",- "user:pass@host",- "multiple/levels/of/nesting/in/path",- "mixed/path?with=query&and#hash",-];--const specialCharKeys = [- "+_)(*&^%$#@!~",- "\\\\\\", // multiple backslashes- "'''\"\"\"", // quotes- "tabs\t\t\tspaces newlines\n\n",- "null\0byte", // null byte- "unicode→↓←↑", // arrows- "mixing→special\t\nchars\0with★unicode",-];+const testCases = {+ "basic strings": [+ "Hello World",+ "Case-Sensitive123",+ "abc",+ "!@#$%^&*()",+ "+_)(*&^%$#@!~",+ ],+ "special content": [+ "\\\\\\", // backslashes+ "'''\"\"\"", // quotes+ "\t\n\r", // control characters+ "null\0byte", // null byte+ "unicode→↓←↑", // arrows+ "🌟⭐️✨", // basic emojis+ "Mixed🌟Emoji⭐️Text", // mixed content+ "👨👩👧👦", // complex emoji+ ],+ international: [+ "漢字한글テストñáéíóúüрусскийالعربية", // mixed scripts+ "עִברִית नमस्ते ᚠᚢᚦᚨᚱᚲ", // more scripts+ ],+ "URLs and paths": [+ "path/to/resource",+ "query?param=value&complex=true#hash",+ "user:pass@host:8080/path?query#fragment",+ ],+ "edge cases": [+ "", // empty+ " ", // single space+ " ", // multiple spaces+ "a".repeat(100), // long string+ ],+};-const unicodeKeys = [- "한글테스트", // Korean- "测试中文", // Chinese- "русский", // Russian- "العربية", // Arabic- "עִברִית", // Hebrew- "🌈🌟⭐️✨🌙☀️", // Only emojis- "👨👩👧👦", // Complex emoji (family)- "नमस्ते", // Hindi- "ᚠᚢᚦᚨᚱᚲ", // Runic+const caseVariants = [+ ["github", "GITHUB", "Github", "gitHub"],+ ["URL-Path", "url-path", "Url-Path", "URL-PATH"],+ ["Mixed_Case_123", "MIXED_CASE_123", "mixed_case_123"],];-describe("case-sensitive key encoding/decoding - basic cases", () => {- basicKeys.forEach((key) => {- it(`should handle: ${key}`, () => {- const encoded = encodeKey(key);- const decoded = decodeKey(encoded);- expect(decoded).toBe(key);- });- });-});--describe("case-sensitive key encoding/decoding - edge cases", () => {- edgeCaseKeys.forEach((key) => {- it(`should handle edge case: ${key.length > 20 ? `${key.slice(0, 20)}... (length: ${key.length})` : key}`, () => {- const encoded = encodeKey(key);- const decoded = decodeKey(encoded);- expect(decoded).toBe(key);- });- });-});--describe("case-sensitive key encoding/decoding - URL-like strings", () => {- urlLikeKeys.forEach((key) => {- it(`should handle URL-like string: ${key}`, () => {- const encoded = encodeKey(key);- const decoded = decodeKey(encoded);- expect(decoded).toBe(key);- });- });-});+describe("case-sensitive key encoding/decoding", () => {+ Object.entries(testCases).forEach(([category, cases]) => {+ describe(category, () => {+ cases.forEach((input) => {+ const testName =+ input.length > 20+ ? `${input.slice(0, 20)}... (${input.length})`+ : input || "(empty string)";-describe("case-sensitive key encoding/decoding - special characters", () => {- specialCharKeys.forEach((key) => {- it(`should handle special chars: ${key}`, () => {- const encoded = encodeKey(key);- const decoded = decodeKey(encoded);- expect(decoded).toBe(key);- });- });-});+ it(testName, () => {+ const encoded = encodeKey(input);+ const decoded = decodeKey(encoded);-describe("case-sensitive key encoding/decoding - unicode", () => {- unicodeKeys.forEach((key) => {- it(`should handle unicode: ${key}`, () => {- const encoded = encodeKey(key);- const decoded = decodeKey(encoded);- expect(decoded).toBe(key);+ expect(decoded).toBe(input);+ });+ });});});-});-describe("case sensitivity variants", () => {- const variantGroups = [- ["github", "GITHUB", "Github", "gitHub"],- ["TEST", "test", "Test", "tEsT"],- ["Mixed_Case_123", "MIXED_CASE_123", "mixed_case_123"],- ["URL-Path", "url-path", "Url-Path", "URL-PATH"],- ];+ it("should handle case variants correctly", () => {+ caseVariants.forEach((variants, i) => {+ const encodedSet = new Set(variants.map(encodeKey));- variantGroups.forEach((variants, index) => {- it(`variant group ${index + 1} should produce unique encodings`, () => {- const encodedKeys = new Set(variants.map(encodeKey));- expect(encodedKeys.size).toBe(variants.length); // Ensure uniqueness+ expect(encodedSet.size).toBe(variants.length);variants.forEach((variant) => {- expect(decodeKey(encodeKey(variant))).toBe(variant);+ const encoded = encodeKey(variant);+ const decoded = decodeKey(encoded);+ expect(decoded).toBe(variant);});});});});--describe("encoding consistency", () => {- const testKey = "Test-Key-123";-- it("should produce consistent encodings", () => {- const firstEncoding = encodeKey(testKey);- for (let i = 0; i < 100; i++) {- expect(encodeKey(testKey)).toBe(firstEncoding);- }- });-- it("should handle repeated encode/decode cycles", () => {- let value = testKey;- for (let i = 0; i < 10; i++) {- value = decodeKey(encodeKey(value));- expect(value).toBe(testKey);- }- });-});