forked from pingdotgg/t3code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitReactQuery.test.ts
More file actions
101 lines (87 loc) · 3.23 KB
/
gitReactQuery.test.ts
File metadata and controls
101 lines (87 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { QueryClient } from "@tanstack/react-query";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { NativeApi } from "@t3tools/contracts";
import {
gitMutationKeys,
gitPreparePullRequestThreadMutationOptions,
gitPullMutationOptions,
gitRunStackedActionMutationOptions,
} from "./gitReactQuery";
import * as nativeApi from "../nativeApi";
afterEach(() => {
vi.restoreAllMocks();
});
describe("gitMutationKeys", () => {
it("scopes stacked action keys by cwd", () => {
expect(gitMutationKeys.runStackedAction("/repo/a")).not.toEqual(
gitMutationKeys.runStackedAction("/repo/b"),
);
});
it("scopes pull keys by cwd", () => {
expect(gitMutationKeys.pull("/repo/a")).not.toEqual(gitMutationKeys.pull("/repo/b"));
});
it("scopes pull request thread preparation keys by cwd", () => {
expect(gitMutationKeys.preparePullRequestThread("/repo/a")).not.toEqual(
gitMutationKeys.preparePullRequestThread("/repo/b"),
);
});
});
describe("git mutation options", () => {
const queryClient = new QueryClient();
it("attaches cwd-scoped mutation key for runStackedAction", () => {
const options = gitRunStackedActionMutationOptions({ cwd: "/repo/a", queryClient });
expect(options.mutationKey).toEqual(gitMutationKeys.runStackedAction("/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"));
});
it("attaches cwd-scoped mutation key for preparePullRequestThread", () => {
const options = gitPreparePullRequestThreadMutationOptions({
cwd: "/repo/a",
queryClient,
});
expect(options.mutationKey).toEqual(gitMutationKeys.preparePullRequestThread("/repo/a"));
});
it("forwards commit message instructions for stacked actions", async () => {
const runStackedAction = vi.fn().mockResolvedValue({});
vi.spyOn(nativeApi, "ensureNativeApi").mockReturnValue({
git: { runStackedAction },
} as unknown as NativeApi);
const options = gitRunStackedActionMutationOptions({ cwd: "/repo/a", queryClient });
const mutationFn = options.mutationFn;
expect(mutationFn).toBeDefined();
await mutationFn!(
{
action: "commit",
commitMessageInstructions: " Use Conventional Commits ",
},
{} as never,
);
expect(runStackedAction).toHaveBeenCalledWith({
cwd: "/repo/a",
action: "commit",
commitMessageInstructions: "Use Conventional Commits",
});
});
it("omits blank commit message instructions for stacked actions", async () => {
const runStackedAction = vi.fn().mockResolvedValue({});
vi.spyOn(nativeApi, "ensureNativeApi").mockReturnValue({
git: { runStackedAction },
} as unknown as NativeApi);
const options = gitRunStackedActionMutationOptions({ cwd: "/repo/a", queryClient });
const mutationFn = options.mutationFn;
expect(mutationFn).toBeDefined();
await mutationFn!(
{
action: "commit",
commitMessageInstructions: " ",
},
{} as never,
);
expect(runStackedAction).toHaveBeenCalledWith({
cwd: "/repo/a",
action: "commit",
});
});
});