-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathGitLabSourceControlProvider.test.ts
More file actions
152 lines (138 loc) · 4.31 KB
/
GitLabSourceControlProvider.test.ts
File metadata and controls
152 lines (138 loc) · 4.31 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { assert, it } from "@effect/vitest";
import { ChildProcessSpawner } from "effect/unstable/process";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as GitLabCli from "./GitLabCli.ts";
import { parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts";
import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts";
function makeProvider(gitlab: Partial<GitLabCli.GitLabCliShape>) {
return GitLabSourceControlProvider.make().pipe(
Effect.provide(Layer.mock(GitLabCli.GitLabCli)(gitlab)),
);
}
it.effect("maps GitLab MR summaries into provider-neutral change requests", () =>
Effect.gen(function* () {
const provider = yield* makeProvider({
getMergeRequest: () =>
Effect.succeed({
number: 42,
title: "Add GitLab provider",
url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42",
baseRefName: "main",
headRefName: "feature/source-control",
state: "open",
isCrossRepository: true,
headRepositoryNameWithOwner: "fork/t3code",
headRepositoryOwnerLogin: "fork",
}),
});
const changeRequest = yield* provider.getChangeRequest({
cwd: "/repo",
reference: "42",
});
assert.deepStrictEqual(changeRequest, {
provider: "gitlab",
number: 42,
title: "Add GitLab provider",
url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42",
baseRefName: "main",
headRefName: "feature/source-control",
state: "open",
updatedAt: Option.none(),
isCrossRepository: true,
headRepositoryNameWithOwner: "fork/t3code",
headRepositoryOwnerLogin: "fork",
});
}),
);
it.effect("lists GitLab MRs through provider-neutral input names", () =>
Effect.gen(function* () {
let listInput: Parameters<GitLabCli.GitLabCliShape["listMergeRequests"]>[0] | null = null;
const provider = yield* makeProvider({
listMergeRequests: (input) => {
listInput = input;
return Effect.succeed([]);
},
});
yield* provider.listChangeRequests({
cwd: "/repo",
headSelector: "feature/provider",
state: "all",
limit: 10,
});
assert.deepStrictEqual(listInput, {
cwd: "/repo",
headSelector: "feature/provider",
state: "all",
limit: 10,
});
}),
);
it.effect("creates GitLab MRs through provider-neutral input names", () =>
Effect.gen(function* () {
let createInput: Parameters<GitLabCli.GitLabCliShape["createMergeRequest"]>[0] | null = null;
const provider = yield* makeProvider({
createMergeRequest: (input) => {
createInput = input;
return Effect.void;
},
});
yield* provider.createChangeRequest({
cwd: "/repo",
baseRefName: "main",
headSelector: "owner:feature/provider",
title: "Provider MR",
bodyFile: "/tmp/body.md",
});
assert.deepStrictEqual(createInput, {
cwd: "/repo",
baseBranch: "main",
headSelector: "owner:feature/provider",
source: {
owner: "owner",
refName: "feature/provider",
},
title: "Provider MR",
bodyFile: "/tmp/body.md",
});
}),
);
it("accepts authenticated GitLab hosts when another configured host fails", () => {
const auth = GitLabSourceControlProvider.discovery.parseAuth({
exitCode: ChildProcessSpawner.ExitCode(1),
stdout: `gitlab.com
x gitlab.com: API call failed: 401 Unauthorized
! No token found
self-hosted.example.test
✓ Logged in to self-hosted.example.test as gitlab-user
✓ Token found: ******
`,
stderr: "",
});
assert.deepStrictEqual(
{
status: auth.status,
account: auth.account,
host: auth.host,
},
{
status: "authenticated",
account: Option.some("gitlab-user"),
host: Option.some("self-hosted.example.test"),
},
);
});
it("parses authenticated GitLab auth status hosts with ports and single-label names", () => {
assert.deepStrictEqual(
parseGitLabAuthStatusHosts(`localhost:8080
✓ Logged in to localhost:8080 as local-user
selfhosted
✓ Logged in to selfhosted as single-label-user
`),
[
{ host: "localhost:8080", account: "local-user" },
{ host: "selfhosted", account: "single-label-user" },
],
);
});