Files
t3code/apps/web/src/lib/desktopUpdateReactQuery.test.ts
T
f82bae1668 Update system overhaul (#1505)
Co-authored-by: Jono Kemball <[email protected]>
Co-authored-by: Ariaj Sarkar <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: codex <[email protected]>
2026-03-29 04:23:10 +00:00

50 lines
1.4 KiB
TypeScript

import { QueryClient } from "@tanstack/react-query";
import { describe, expect, it } from "vitest";
import type { DesktopUpdateState } from "@t3tools/contracts";
import {
desktopUpdateQueryKeys,
desktopUpdateStateQueryOptions,
setDesktopUpdateStateQueryData,
} from "./desktopUpdateReactQuery";
const baseState: DesktopUpdateState = {
enabled: true,
status: "idle",
currentVersion: "1.0.0",
hostArch: "x64",
appArch: "x64",
runningUnderArm64Translation: false,
availableVersion: null,
downloadedVersion: null,
downloadPercent: null,
checkedAt: null,
message: null,
errorContext: null,
canRetry: false,
};
describe("desktopUpdateStateQueryOptions", () => {
it("always refetches on mount so Settings does not reuse stale desktop update state", () => {
const options = desktopUpdateStateQueryOptions();
expect(options.staleTime).toBe(Infinity);
expect(options.refetchOnMount).toBe("always");
});
});
describe("setDesktopUpdateStateQueryData", () => {
it("writes desktop update state into the shared cache key", () => {
const queryClient = new QueryClient();
const nextState: DesktopUpdateState = {
...baseState,
status: "downloaded",
availableVersion: "1.1.0",
downloadedVersion: "1.1.0",
};
setDesktopUpdateStateQueryData(queryClient, nextState);
expect(queryClient.getQueryData(desktopUpdateQueryKeys.state())).toEqual(nextState);
});
});