import { describe, expect, it } from "vitest";

import { createSplashLatestMessageCache } from "../splash_latest_message_cache";

describe("splash latest message cache", () => {
  it("isolates previews by chat identity", () => {
    const cache = createSplashLatestMessageCache();

    cache.set("user:1", "First user");
    cache.set("user:2", "Second user");

    expect(cache.get("user:1")?.message).toBe("First user");
    expect(cache.get("user:2")?.message).toBe("Second user");
    expect(cache.get("user:3")).toBeUndefined();
  });

  it("clears all session previews", () => {
    const cache = createSplashLatestMessageCache();
    cache.set("user:1", null);

    cache.clear();

    expect(cache.get("user:1")).toBeUndefined();
  });
});
