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