Showing the changes to apps/server/src/sourceControl/GitLabSourceControlProvider.test.ts (1 of 24 files). Show all
Unified · Split
| @@ -0,0 +1,105 @@ | ||
| 1 | +import { assert, it } from "@effect/vitest"; | |
| 2 | +import { Effect, Layer, Option } from "effect"; | |
| 3 | + | |
| 4 | +import { GitLabCli, type GitLabCliShape } from "./GitLabCli.ts"; | |
| 5 | +import * as GitLabSourceControlProvider from "./GitLabSourceControlProvider.ts"; | |
| 6 | + | |
| 7 | +function makeProvider(gitlab: Partial<GitLabCliShape>) { | |
| 8 | + return GitLabSourceControlProvider.make().pipe(Effect.provide(Layer.mock(GitLabCli)(gitlab))); | |
| 9 | +} | |
| 10 | + | |
| 11 | +it.effect("maps GitLab MR summaries into provider-neutral change requests", () => | |
| 12 | + Effect.gen(function* () { | |
| 13 | + const provider = yield* makeProvider({ | |
| 14 | + getMergeRequest: () => | |
| 15 | + Effect.succeed({ | |
| 16 | + number: 42, | |
| 17 | + title: "Add GitLab provider", | |
| 18 | + url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42", | |
| 19 | + baseRefName: "main", | |
| 20 | + headRefName: "feature/source-control", | |
| 21 | + state: "open", | |
| 22 | + isCrossRepository: true, | |
| 23 | + headRepositoryNameWithOwner: "fork/t3code", | |
| 24 | + headRepositoryOwnerLogin: "fork", | |
| 25 | + }), | |
| 26 | + }); | |
| 27 | + | |
| 28 | + const changeRequest = yield* provider.getChangeRequest({ | |
| 29 | + cwd: "/repo", | |
| 30 | + reference: "42", | |
| 31 | + }); | |
| 32 | + | |
| 33 | + assert.deepStrictEqual(changeRequest, { | |
| 34 | + provider: "gitlab", | |
| 35 | + number: 42, | |
| 36 | + title: "Add GitLab provider", | |
| 37 | + url: "https://gitlab.com/pingdotgg/t3code/-/merge_requests/42", | |
| 38 | + baseRefName: "main", | |
| 39 | + headRefName: "feature/source-control", | |
| 40 | + state: "open", | |
| 41 | + updatedAt: Option.none(), | |
| 42 | + isCrossRepository: true, | |
| 43 | + headRepositoryNameWithOwner: "fork/t3code", | |
| 44 | + headRepositoryOwnerLogin: "fork", | |
| 45 | + }); | |
| 46 | + }), | |
| 47 | +); | |
| 48 | + | |
| 49 | +it.effect("lists GitLab MRs through provider-neutral input names", () => | |
| 50 | + Effect.gen(function* () { | |
| 51 | + let listInput: Parameters<GitLabCliShape["listMergeRequests"]>[0] | null = null; | |
| 52 | + const provider = yield* makeProvider({ | |
| 53 | + listMergeRequests: (input) => { | |
| 54 | + listInput = input; | |
| 55 | + return Effect.succeed([]); | |
| 56 | + }, | |
| 57 | + }); | |
| 58 | + | |
| 59 | + yield* provider.listChangeRequests({ | |
| 60 | + cwd: "/repo", | |
| 61 | + headSelector: "feature/provider", | |
| 62 | + state: "all", | |
| 63 | + limit: 10, | |
| 64 | + }); | |
| 65 | + | |
| 66 | + assert.deepStrictEqual(listInput, { | |
| 67 | + cwd: "/repo", | |
| 68 | + headSelector: "feature/provider", | |
| 69 | + state: "all", | |
| 70 | + limit: 10, | |
| 71 | + }); | |
| 72 | + }), | |
| 73 | +); | |
| 74 | + | |
| 75 | +it.effect("creates GitLab MRs through provider-neutral input names", () => | |
| 76 | + Effect.gen(function* () { | |
| 77 | + let createInput: Parameters<GitLabCliShape["createMergeRequest"]>[0] | null = null; | |
| 78 | + const provider = yield* makeProvider({ | |
| 79 | + createMergeRequest: (input) => { | |
| 80 | + createInput = input; | |
| 81 | + return Effect.void; | |
| 82 | + }, | |
| 83 | + }); | |
| 84 | + | |
| 85 | + yield* provider.createChangeRequest({ | |
| 86 | + cwd: "/repo", | |
| 87 | + baseRefName: "main", | |
| 88 | + headSelector: "owner:feature/provider", | |
| 89 | + title: "Provider MR", | |
| 90 | + bodyFile: "/tmp/body.md", | |
| 91 | + }); | |
| 92 | + | |
| 93 | + assert.deepStrictEqual(createInput, { | |
| 94 | + cwd: "/repo", | |
| 95 | + baseBranch: "main", | |
| 96 | + headSelector: "owner:feature/provider", | |
| 97 | + source: { | |
| 98 | + owner: "owner", | |
| 99 | + refName: "feature/provider", | |
| 100 | + }, | |
| 101 | + title: "Provider MR", | |
| 102 | + bodyFile: "/tmp/body.md", | |
| 103 | + }); | |
| 104 | + }), | |
| 105 | +); | |