Prepare datamodel for multi-environment (#1765)
Co-authored-by: justsomelegs <[email protected]> Co-authored-by: codex <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
This commit is contained in:
121 files changed
+10195
-4958
No files matched your search
@@ -1,16 +1,17 @@
|
||||
import { QueryClient } from "@tanstack/react-query";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("../nativeApi", () => ({
|
||||
ensureNativeApi: vi.fn(),
|
||||
vi.mock("../environmentApi", () => ({
|
||||
ensureEnvironmentApi: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("../wsRpcClient", () => ({
|
||||
getWsRpcClient: vi.fn(),
|
||||
getWsRpcClientForEnvironment: vi.fn(),
|
||||
}));
|
||||
|
||||
import type { InfiniteData } from "@tanstack/react-query";
|
||||
import type { GitListBranchesResult } from "@t3tools/contracts";
|
||||
import { EnvironmentId, type GitListBranchesResult } from "@t3tools/contracts";
|
||||
|
||||
import {
|
||||
gitBranchSearchInfiniteQueryOptions,
|
||||
@@ -33,21 +34,25 @@ const BRANCH_SEARCH_RESULT: InfiniteData<GitListBranchesResult, number> = {
|
||||
pages: [BRANCH_QUERY_RESULT],
|
||||
pageParams: [0],
|
||||
};
|
||||
const ENVIRONMENT_A = EnvironmentId.makeUnsafe("environment-a");
|
||||
const ENVIRONMENT_B = EnvironmentId.makeUnsafe("environment-b");
|
||||
|
||||
describe("gitMutationKeys", () => {
|
||||
it("scopes stacked action keys by cwd", () => {
|
||||
expect(gitMutationKeys.runStackedAction("/repo/a")).not.toEqual(
|
||||
gitMutationKeys.runStackedAction("/repo/b"),
|
||||
expect(gitMutationKeys.runStackedAction(ENVIRONMENT_A, "/repo/a")).not.toEqual(
|
||||
gitMutationKeys.runStackedAction(ENVIRONMENT_A, "/repo/b"),
|
||||
);
|
||||
});
|
||||
|
||||
it("scopes pull keys by cwd", () => {
|
||||
expect(gitMutationKeys.pull("/repo/a")).not.toEqual(gitMutationKeys.pull("/repo/b"));
|
||||
expect(gitMutationKeys.pull(ENVIRONMENT_A, "/repo/a")).not.toEqual(
|
||||
gitMutationKeys.pull(ENVIRONMENT_A, "/repo/b"),
|
||||
);
|
||||
});
|
||||
|
||||
it("scopes pull request thread preparation keys by cwd", () => {
|
||||
expect(gitMutationKeys.preparePullRequestThread("/repo/a")).not.toEqual(
|
||||
gitMutationKeys.preparePullRequestThread("/repo/b"),
|
||||
expect(gitMutationKeys.preparePullRequestThread(ENVIRONMENT_A, "/repo/a")).not.toEqual(
|
||||
gitMutationKeys.preparePullRequestThread(ENVIRONMENT_A, "/repo/b"),
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -57,23 +62,31 @@ describe("git mutation options", () => {
|
||||
|
||||
it("attaches cwd-scoped mutation key for runStackedAction", () => {
|
||||
const options = gitRunStackedActionMutationOptions({
|
||||
environmentId: ENVIRONMENT_A,
|
||||
cwd: "/repo/a",
|
||||
queryClient,
|
||||
});
|
||||
expect(options.mutationKey).toEqual(gitMutationKeys.runStackedAction("/repo/a"));
|
||||
expect(options.mutationKey).toEqual(gitMutationKeys.runStackedAction(ENVIRONMENT_A, "/repo/a"));
|
||||
});
|
||||
|
||||
it("attaches cwd-scoped mutation key for pull", () => {
|
||||
const options = gitPullMutationOptions({ cwd: "/repo/a", queryClient });
|
||||
expect(options.mutationKey).toEqual(gitMutationKeys.pull("/repo/a"));
|
||||
const options = gitPullMutationOptions({
|
||||
environmentId: ENVIRONMENT_A,
|
||||
cwd: "/repo/a",
|
||||
queryClient,
|
||||
});
|
||||
expect(options.mutationKey).toEqual(gitMutationKeys.pull(ENVIRONMENT_A, "/repo/a"));
|
||||
});
|
||||
|
||||
it("attaches cwd-scoped mutation key for preparePullRequestThread", () => {
|
||||
const options = gitPreparePullRequestThreadMutationOptions({
|
||||
environmentId: ENVIRONMENT_A,
|
||||
cwd: "/repo/a",
|
||||
queryClient,
|
||||
});
|
||||
expect(options.mutationKey).toEqual(gitMutationKeys.preparePullRequestThread("/repo/a"));
|
||||
expect(options.mutationKey).toEqual(
|
||||
gitMutationKeys.preparePullRequestThread(ENVIRONMENT_A, "/repo/a"),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -83,6 +96,7 @@ describe("invalidateGitQueries", () => {
|
||||
|
||||
queryClient.setQueryData(
|
||||
gitBranchSearchInfiniteQueryOptions({
|
||||
environmentId: ENVIRONMENT_A,
|
||||
cwd: "/repo/a",
|
||||
query: "feature",
|
||||
}).queryKey,
|
||||
@@ -90,17 +104,19 @@ describe("invalidateGitQueries", () => {
|
||||
);
|
||||
queryClient.setQueryData(
|
||||
gitBranchSearchInfiniteQueryOptions({
|
||||
environmentId: ENVIRONMENT_B,
|
||||
cwd: "/repo/b",
|
||||
query: "feature",
|
||||
}).queryKey,
|
||||
BRANCH_SEARCH_RESULT,
|
||||
);
|
||||
|
||||
await invalidateGitQueries(queryClient, { cwd: "/repo/a" });
|
||||
await invalidateGitQueries(queryClient, { environmentId: ENVIRONMENT_A, cwd: "/repo/a" });
|
||||
|
||||
expect(
|
||||
queryClient.getQueryState(
|
||||
gitBranchSearchInfiniteQueryOptions({
|
||||
environmentId: ENVIRONMENT_A,
|
||||
cwd: "/repo/a",
|
||||
query: "feature",
|
||||
}).queryKey,
|
||||
@@ -109,6 +125,7 @@ describe("invalidateGitQueries", () => {
|
||||
expect(
|
||||
queryClient.getQueryState(
|
||||
gitBranchSearchInfiniteQueryOptions({
|
||||
environmentId: ENVIRONMENT_B,
|
||||
cwd: "/repo/b",
|
||||
query: "feature",
|
||||
}).queryKey,
|
||||
|
||||
Reference in new issue
Block a user