A personal media tracker built on the AT Protocol opnshelf.xyz
at main 26 lines 938 B view raw
1// @vitest-environment jsdom 2 3import { authControllerMeQueryKey } from "@opnshelf/api"; 4import { QueryClient } from "@tanstack/react-query"; 5import { describe, expect, it, vi } from "vitest"; 6import { publishSignedOutAuthState } from "./auth-cache"; 7 8describe("publishSignedOutAuthState", () => { 9 it("publishes a signed-out auth state and invalidates the auth query", async () => { 10 const queryClient = new QueryClient(); 11 const queryKey = authControllerMeQueryKey(); 12 const cancelQueries = vi.spyOn(queryClient, "cancelQueries"); 13 const invalidateQueries = vi.spyOn(queryClient, "invalidateQueries"); 14 15 queryClient.setQueryData(queryKey, { 16 did: "did:plc:alice", 17 handle: "alice", 18 }); 19 20 await publishSignedOutAuthState(queryClient); 21 22 expect(cancelQueries).toHaveBeenCalledWith({ queryKey }); 23 expect(queryClient.getQueryData(queryKey)).toBeNull(); 24 expect(invalidateQueries).toHaveBeenCalledWith({ queryKey }); 25 }); 26});