feat(browser-ext): move browser extension to browser-ext/ and update API client to tRPC
- Create browser-ext/ with full extension code (MV3 manifest, background service worker, content script, popup, options page) - Add tRPC API client that communicates with unified monolith endpoints - Implement cache, settings, and phishing detection utilities - Create extension tRPC router in web app (getAuthStatus, linkDevice, reportPhishing) - Configure Vite build with manifest V3 support - Write unit tests for cache, phishing detector, and API client - All 20 tests passing, TypeScript lint clean
This commit is contained in:
53
browser-ext/tests/cache.test.ts
Normal file
53
browser-ext/tests/cache.test.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { Cache } from "../src/lib/cache";
|
||||
|
||||
describe("Cache", () => {
|
||||
let cache: Cache<string>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
cache = new Cache(1000);
|
||||
});
|
||||
|
||||
it("should store and retrieve values", () => {
|
||||
cache.set("key1", "value1");
|
||||
expect(cache.get("key1")).toBe("value1");
|
||||
});
|
||||
|
||||
it("should return null for missing keys", () => {
|
||||
expect(cache.get("nonexistent")).toBeNull();
|
||||
});
|
||||
|
||||
it("should expire entries after TTL", () => {
|
||||
cache.set("key1", "value1");
|
||||
vi.advanceTimersByTime(1500);
|
||||
expect(cache.get("key1")).toBeNull();
|
||||
});
|
||||
|
||||
it("should not expire entries before TTL", () => {
|
||||
cache.set("key1", "value1");
|
||||
vi.advanceTimersByTime(500);
|
||||
expect(cache.get("key1")).toBe("value1");
|
||||
});
|
||||
|
||||
it("should delete entries", () => {
|
||||
cache.set("key1", "value1");
|
||||
cache.delete("key1");
|
||||
expect(cache.get("key1")).toBeNull();
|
||||
});
|
||||
|
||||
it("should clear all entries", () => {
|
||||
cache.set("key1", "value1");
|
||||
cache.set("key2", "value2");
|
||||
cache.clear();
|
||||
expect(cache.get("key1")).toBeNull();
|
||||
expect(cache.get("key2")).toBeNull();
|
||||
});
|
||||
|
||||
it("should not return expired entries when they are cleaned up on get", () => {
|
||||
cache.set("key1", "value1");
|
||||
vi.advanceTimersByTime(1001);
|
||||
const result = cache.get("key1");
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user