Open History to see the last commit
1import type { GitStatusRemoteResult, GitStatusResult } from "@t3tools/contracts";
2import { describe, expect, it } from "vitest";
3
4import { applyGitStatusStreamEvent } from "./git";
5
6describe("applyGitStatusStreamEvent", () => {
7 it("treats a remote-only update as a repository when local state is missing", () => {
8 const remote: GitStatusRemoteResult = {
9 hasUpstream: true,
10 aheadCount: 2,
11 behindCount: 1,
12 pr: null,
13 };
14
15 expect(applyGitStatusStreamEvent(null, { _tag: "remoteUpdated", remote })).toEqual({
16 isRepo: true,
17 hasOriginRemote: false,
18 isDefaultBranch: false,
19 branch: null,
20 hasWorkingTreeChanges: false,
21 workingTree: { files: [], insertions: 0, deletions: 0 },
22 hasUpstream: true,
23 aheadCount: 2,
24 behindCount: 1,
25 pr: null,
26 });
27 });
28
29 it("preserves local-only fields when applying a remote update", () => {
30 const current: GitStatusResult = {
31 isRepo: true,
32 hostingProvider: {
33 kind: "github",
34 name: "GitHub",
35 baseUrl: "https://github.com",
36 },
37 hasOriginRemote: true,
38 isDefaultBranch: false,
39 branch: "feature/demo",
40 hasWorkingTreeChanges: true,
41 workingTree: {
42 files: [{ path: "src/demo.ts", insertions: 1, deletions: 0 }],
43 insertions: 1,
44 deletions: 0,
45 },
46 hasUpstream: false,
47 aheadCount: 0,
48 behindCount: 0,
49 pr: null,
50 };
51
52 const remote: GitStatusRemoteResult = {
53 hasUpstream: true,
54 aheadCount: 2,
55 behindCount: 1,
56 pr: null,
57 };
58
59 expect(applyGitStatusStreamEvent(current, { _tag: "remoteUpdated", remote })).toEqual({
60 ...current,
61 hasUpstream: true,
62 aheadCount: 2,
63 behindCount: 1,
64 pr: null,
65 });
66 });
67});