Files
outline/server/utils/RedisPrefixHelper.test.ts
Copilot 40bbfc78cd Refactor: Extract Redis cache key generation to RedisPrefixHelper (#11376)
* Initial plan

* Refactor Redis cache keys: delegate CacheHelper to RedisPrefixHelper and update callers

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>

* Add JSDoc documentation to getCollectionDocumentsKey method

Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>

* Remove unused indirection

* Remove mock

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
Co-authored-by: Tom Moor <tom@getoutline.com>
2026-02-09 14:03:02 -05:00

62 lines
2.2 KiB
TypeScript

import { RedisPrefixHelper } from "./RedisPrefixHelper";
describe("RedisPrefixHelper", () => {
describe("getUnfurlKey", () => {
it("should generate key with teamId and url", () => {
const teamId = "team-123";
const url = "https://example.com";
const result = RedisPrefixHelper.getUnfurlKey(teamId, url);
expect(result).toBe("unfurl:team-123:https://example.com");
});
it("should generate key with teamId and empty url", () => {
const teamId = "team-456";
const result = RedisPrefixHelper.getUnfurlKey(teamId);
expect(result).toBe("unfurl:team-456:");
});
it("should handle special characters in url", () => {
const teamId = "team-789";
const url = "https://example.com/path?query=value&other=123";
const result = RedisPrefixHelper.getUnfurlKey(teamId, url);
expect(result).toBe(
"unfurl:team-789:https://example.com/path?query=value&other=123"
);
});
});
describe("getCollectionDocumentsKey", () => {
it("should generate key with collectionId", () => {
const collectionId = "col-abc123";
const result = RedisPrefixHelper.getCollectionDocumentsKey(collectionId);
expect(result).toBe("cd:col-abc123");
});
it("should handle uuid format", () => {
const collectionId = "550e8400-e29b-41d4-a716-446655440000";
const result = RedisPrefixHelper.getCollectionDocumentsKey(collectionId);
expect(result).toBe("cd:550e8400-e29b-41d4-a716-446655440000");
});
});
describe("getEmbedCheckKey", () => {
it("should generate key with url", () => {
const url = "https://example.com/embed";
const result = RedisPrefixHelper.getEmbedCheckKey(url);
expect(result).toBe("embed:https://example.com/embed");
});
it("should handle urls with query parameters", () => {
const url = "https://example.com/video?v=abc123";
const result = RedisPrefixHelper.getEmbedCheckKey(url);
expect(result).toBe("embed:https://example.com/video?v=abc123");
});
it("should handle urls with fragments", () => {
const url = "https://example.com/page#section";
const result = RedisPrefixHelper.getEmbedCheckKey(url);
expect(result).toBe("embed:https://example.com/page#section");
});
});
});