Showing the changes to apps/web/src/lib/gitReactQuery.test.ts (1 of 121 files). Show all
Unified · Split
| @@ -1,16 +1,17 @@ | ||
| 1 | 1 | import { QueryClient } from "@tanstack/react-query"; |
| 2 | 2 | import { describe, expect, it, vi } from "vitest"; |
| 3 | 3 | |
| 4 | −vi.mock("../nativeApi", () => ({ | |
| 5 | − ensureNativeApi: vi.fn(), | |
| 4 | +vi.mock("../environmentApi", () => ({ | |
| 5 | + ensureEnvironmentApi: vi.fn(), | |
| 6 | 6 | })); |
| 7 | 7 | |
| 8 | 8 | vi.mock("../wsRpcClient", () => ({ |
| 9 | 9 | getWsRpcClient: vi.fn(), |
| 10 | + getWsRpcClientForEnvironment: vi.fn(), | |
| 10 | 11 | })); |
| 11 | 12 | |
| 12 | 13 | import type { InfiniteData } from "@tanstack/react-query"; |
| 13 | −import type { GitListBranchesResult } from "@t3tools/contracts"; | |
| 14 | +import { EnvironmentId, type GitListBranchesResult } from "@t3tools/contracts"; | |
| 14 | 15 | |
| 15 | 16 | import { |
| 16 | 17 | gitBranchSearchInfiniteQueryOptions, |
| @@ -33,21 +34,25 @@ const BRANCH_SEARCH_RESULT: InfiniteData<GitListBranchesResult, number> = { · 16 unmodified lines | ||
| 33 | 34 | pages: [BRANCH_QUERY_RESULT], |
| 34 | 35 | pageParams: [0], |
| 35 | 36 | }; |
| 37 | +const ENVIRONMENT_A = EnvironmentId.makeUnsafe("environment-a"); | |
| 38 | +const ENVIRONMENT_B = EnvironmentId.makeUnsafe("environment-b"); | |
| 36 | 39 | |
| 37 | 40 | describe("gitMutationKeys", () => { |
| 38 | 41 | it("scopes stacked action keys by cwd", () => { |
| 39 | − expect(gitMutationKeys.runStackedAction("/repo/a")).not.toEqual( | |
| 40 | − gitMutationKeys.runStackedAction("/repo/b"), | |
| 42 | + expect(gitMutationKeys.runStackedAction(ENVIRONMENT_A, "/repo/a")).not.toEqual( | |
| 43 | + gitMutationKeys.runStackedAction(ENVIRONMENT_A, "/repo/b"), | |
| 41 | 44 | ); |
| 42 | 45 | }); |
| 43 | 46 | |
| 44 | 47 | it("scopes pull keys by cwd", () => { |
| 45 | − expect(gitMutationKeys.pull("/repo/a")).not.toEqual(gitMutationKeys.pull("/repo/b")); | |
| 48 | + expect(gitMutationKeys.pull(ENVIRONMENT_A, "/repo/a")).not.toEqual( | |
| 49 | + gitMutationKeys.pull(ENVIRONMENT_A, "/repo/b"), | |
| 50 | + ); | |
| 46 | 51 | }); |
| 47 | 52 | |
| 48 | 53 | it("scopes pull request thread preparation keys by cwd", () => { |
| 49 | − expect(gitMutationKeys.preparePullRequestThread("/repo/a")).not.toEqual( | |
| 50 | − gitMutationKeys.preparePullRequestThread("/repo/b"), | |
| 54 | + expect(gitMutationKeys.preparePullRequestThread(ENVIRONMENT_A, "/repo/a")).not.toEqual( | |
| 55 | + gitMutationKeys.preparePullRequestThread(ENVIRONMENT_A, "/repo/b"), | |
| 51 | 56 | ); |
| 52 | 57 | }); |
| 53 | 58 | }); |
| @@ -57,23 +62,31 @@ describe("git mutation options", () => { · 3 unmodified lines | ||
| 57 | 62 | |
| 58 | 63 | it("attaches cwd-scoped mutation key for runStackedAction", () => { |
| 59 | 64 | const options = gitRunStackedActionMutationOptions({ |
| 65 | + environmentId: ENVIRONMENT_A, | |
| 60 | 66 | cwd: "/repo/a", |
| 61 | 67 | queryClient, |
| 62 | 68 | }); |
| 63 | − expect(options.mutationKey).toEqual(gitMutationKeys.runStackedAction("/repo/a")); | |
| 69 | + expect(options.mutationKey).toEqual(gitMutationKeys.runStackedAction(ENVIRONMENT_A, "/repo/a")); | |
| 64 | 70 | }); |
| 65 | 71 | |
| 66 | 72 | it("attaches cwd-scoped mutation key for pull", () => { |
| 67 | − const options = gitPullMutationOptions({ cwd: "/repo/a", queryClient }); | |
| 68 | − expect(options.mutationKey).toEqual(gitMutationKeys.pull("/repo/a")); | |
| 73 | + const options = gitPullMutationOptions({ | |
| 74 | + environmentId: ENVIRONMENT_A, | |
| 75 | + cwd: "/repo/a", | |
| 76 | + queryClient, | |
| 77 | + }); | |
| 78 | + expect(options.mutationKey).toEqual(gitMutationKeys.pull(ENVIRONMENT_A, "/repo/a")); | |
| 69 | 79 | }); |
| 70 | 80 | |
| 71 | 81 | it("attaches cwd-scoped mutation key for preparePullRequestThread", () => { |
| 72 | 82 | const options = gitPreparePullRequestThreadMutationOptions({ |
| 83 | + environmentId: ENVIRONMENT_A, | |
| 73 | 84 | cwd: "/repo/a", |
| 74 | 85 | queryClient, |
| 75 | 86 | }); |
| 76 | − expect(options.mutationKey).toEqual(gitMutationKeys.preparePullRequestThread("/repo/a")); | |
| 87 | + expect(options.mutationKey).toEqual( | |
| 88 | + gitMutationKeys.preparePullRequestThread(ENVIRONMENT_A, "/repo/a"), | |
| 89 | + ); | |
| 77 | 90 | }); |
| 78 | 91 | }); |
| 79 | 92 | |
| @@ -83,6 +96,7 @@ describe("invalidateGitQueries", () => { · 3 unmodified lines | ||
| 83 | 96 | |
| 84 | 97 | queryClient.setQueryData( |
| 85 | 98 | gitBranchSearchInfiniteQueryOptions({ |
| 99 | + environmentId: ENVIRONMENT_A, | |
| 86 | 100 | cwd: "/repo/a", |
| 87 | 101 | query: "feature", |
| 88 | 102 | }).queryKey, |
| @@ -90,17 +104,19 @@ describe("invalidateGitQueries", () => { · 1 unmodified line | ||
| 90 | 104 | ); |
| 91 | 105 | queryClient.setQueryData( |
| 92 | 106 | gitBranchSearchInfiniteQueryOptions({ |
| 107 | + environmentId: ENVIRONMENT_B, | |
| 93 | 108 | cwd: "/repo/b", |
| 94 | 109 | query: "feature", |
| 95 | 110 | }).queryKey, |
| 96 | 111 | BRANCH_SEARCH_RESULT, |
| 97 | 112 | ); |
| 98 | 113 | |
| 99 | − await invalidateGitQueries(queryClient, { cwd: "/repo/a" }); | |
| 114 | + await invalidateGitQueries(queryClient, { environmentId: ENVIRONMENT_A, cwd: "/repo/a" }); | |
| 100 | 115 | |
| 101 | 116 | expect( |
| 102 | 117 | queryClient.getQueryState( |
| 103 | 118 | gitBranchSearchInfiniteQueryOptions({ |
| 119 | + environmentId: ENVIRONMENT_A, | |
| 104 | 120 | cwd: "/repo/a", |
| 105 | 121 | query: "feature", |
| 106 | 122 | }).queryKey, |
| @@ -109,6 +125,7 @@ describe("invalidateGitQueries", () => { · 2 unmodified lines | ||
| 109 | 125 | expect( |
| 110 | 126 | queryClient.getQueryState( |
| 111 | 127 | gitBranchSearchInfiniteQueryOptions({ |
| 128 | + environmentId: ENVIRONMENT_B, | |
| 112 | 129 | cwd: "/repo/b", |
| 113 | 130 | query: "feature", |
| 114 | 131 | }).queryKey, |