Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GitWorkflowService.test.ts

132 lines3.8 KB

1import { assert, describe, it, vi } from "@effect/vitest";
2import { Effect, Layer } from "effect";
3​
4import * as GitManager from "./GitManager.ts";
5import * as GitWorkflowService from "./GitWorkflowService.ts";
6import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
7import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
8​
9function makeLayer(input: { readonly detect: VcsDriverRegistry.VcsDriverRegistryShape["detect"] }) {
10 return GitWorkflowService.layer.pipe(
11 Layer.provide(
12 Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({
13 detect: input.detect,
14 }),
15 ),
16 Layer.provide(Layer.mock(GitVcsDriver.GitVcsDriver)({})),
17 Layer.provide(Layer.mock(GitManager.GitManager)({})),
18 );
20​
21describe("GitWorkflowService", () => {
22 it.effect("returns an empty local status when no VCS repository is detected", () =>
23 Effect.gen(function* () {
24 const workflow = yield* GitWorkflowService.GitWorkflowService;
25 const status = yield* workflow.localStatus({ cwd: "/not-a-repo" });
26​
27 assert.deepStrictEqual(status, {
28 isRepo: false,
29 hasPrimaryRemote: false,
30 isDefaultRef: false,
31 refName: null,
32 hasWorkingTreeChanges: false,
33 workingTree: {
34 files: [],
35 insertions: 0,
36 deletions: 0,
37 },
38 });
39 }).pipe(
40 Effect.provide(
41 makeLayer({
42 detect: () => Effect.succeed(null),
43 }),
44 ),
45 ),
46 );
47​
48 it.effect("returns an empty full status when no VCS repository is detected", () =>
49 Effect.gen(function* () {
50 const workflow = yield* GitWorkflowService.GitWorkflowService;
51 const status = yield* workflow.status({ cwd: "/not-a-repo" });
52​
53 assert.deepStrictEqual(status, {
54 isRepo: false,
55 hasPrimaryRemote: false,
56 isDefaultRef: false,
57 refName: null,
58 hasWorkingTreeChanges: false,
59 workingTree: {
60 files: [],
61 insertions: 0,
62 deletions: 0,
63 },
64 hasUpstream: false,
65 aheadCount: 0,
66 behindCount: 0,
67 aheadOfDefaultCount: 0,
68 pr: null,
69 });
70 }).pipe(
71 Effect.provide(
72 makeLayer({
73 detect: () => Effect.succeed(null),
74 }),
75 ),
76 ),
77 );
78​
79 it.effect("does not call GitManager status methods when no VCS repository is detected", () => {
80 const localStatus = vi.fn();
81 const remoteStatus = vi.fn();
82 const status = vi.fn();
83​
84 const testLayer = GitWorkflowService.layer.pipe(
85 Layer.provide(
86 Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({
87 detect: () => Effect.succeed(null),
88 }),
89 ),
90 Layer.provide(Layer.mock(GitVcsDriver.GitVcsDriver)({})),
91 Layer.provide(
92 Layer.mock(GitManager.GitManager)({
93 localStatus,
94 remoteStatus,
95 status,
96 }),
97 ),
98 );
99​
100 return Effect.gen(function* () {
101 const workflow = yield* GitWorkflowService.GitWorkflowService;
102 yield* workflow.localStatus({ cwd: "/not-a-repo" });
103 yield* workflow.remoteStatus({ cwd: "/not-a-repo" });
104 yield* workflow.status({ cwd: "/not-a-repo" });
105​
106 assert.equal(localStatus.mock.calls.length, 0);
107 assert.equal(remoteStatus.mock.calls.length, 0);
108 assert.equal(status.mock.calls.length, 0);
109 }).pipe(Effect.provide(testLayer));
110 });
111​
112 it.effect("returns an empty ref list when no VCS repository is detected", () =>
113 Effect.gen(function* () {
114 const workflow = yield* GitWorkflowService.GitWorkflowService;
115 const refs = yield* workflow.listRefs({ cwd: "/not-a-repo" });
116​
117 assert.deepStrictEqual(refs, {
118 refs: [],
119 isRepo: false,
120 hasPrimaryRemote: false,
121 nextCursor: null,
122 totalCount: 0,
123 });
124 }).pipe(
125 Effect.provide(
126 makeLayer({
127 detect: () => Effect.succeed(null),
128 }),
129 ),
130 ),
131 );
132});