Showing the changes to apps/server/src/sourceControl/SourceControlProviderRegistry.test.ts (1 of 59 files). Show all
Unified · Split
| @@ -1,11 +1,16 @@ | |||
| 1 | import { assert, it } from "@effect/vitest"; | 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| 2 | import { DateTime, Effect, Layer, Option } from "effect"; | 3 | import { DateTime, Effect, Layer, Option } from "effect"; |
| 3 | 4 | ||
| 4 | import { GitHubCli } from "./GitHubCli.ts"; | 5 | import { ServerConfig } from "../config.ts"; |
| 5 | import { GitLabCli } from "./GitLabCli.ts"; | 6 | import type * as VcsDriver from "../vcs/VcsDriver.ts"; |
| 7 | import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts"; | ||
| 8 | import * as VcsProcess from "../vcs/VcsProcess.ts"; | ||
| 9 | import * as AzureDevOpsCli from "./AzureDevOpsCli.ts"; | ||
| 10 | import * as BitbucketApi from "./BitbucketApi.ts"; | ||
| 11 | import * as GitHubCli from "./GitHubCli.ts"; | ||
| 12 | import * as GitLabCli from "./GitLabCli.ts"; | ||
| 6 | import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts"; | 13 | import * as SourceControlProviderRegistry from "./SourceControlProviderRegistry.ts"; |
| 7 | import { VcsDriverRegistry } from "../vcs/VcsDriverRegistry.ts"; | ||
| 8 | import type { VcsDriverShape } from "../vcs/VcsDriver.ts"; | ||
| 9 | 14 | ||
| 10 | const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z"); | 15 | const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z"); |
| 11 | 16 | ||
| @@ -29,10 +34,10 @@ function makeRegistry(input: { · 17 unmodified lines | |||
| 29 | expiresAt: Option.none(), | 34 | expiresAt: Option.none(), |
| 30 | }, | 35 | }, |
| 31 | }), | 36 | }), |
| 32 | } satisfies Partial<VcsDriverShape>; | 37 | } satisfies Partial<VcsDriver.VcsDriverShape>; |
| 33 | 38 | ||
| 34 | const registryLayer = Layer.mock(VcsDriverRegistry)({ | 39 | const registryLayer = Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({ |
| 35 | get: () => Effect.succeed(driver as unknown as VcsDriverShape), | 40 | get: () => Effect.succeed(driver as unknown as VcsDriver.VcsDriverShape), |
| 36 | resolve: () => | 41 | resolve: () => |
| 37 | Effect.succeed({ | 42 | Effect.succeed({ |
| 38 | kind: "git", | 43 | kind: "git", |
| @@ -46,13 +51,23 @@ function makeRegistry(input: { · 7 unmodified lines | |||
| 46 | expiresAt: Option.none(), | 51 | expiresAt: Option.none(), |
| 47 | }, | 52 | }, |
| 48 | }, | 53 | }, |
| 49 | driver: driver as unknown as VcsDriverShape, | 54 | driver: driver as unknown as VcsDriver.VcsDriverShape, |
| 50 | }), | 55 | }), |
| 51 | }); | 56 | }); |
| 52 | 57 | ||
| 53 | return SourceControlProviderRegistry.make().pipe( | 58 | return SourceControlProviderRegistry.make().pipe( |
| 54 | Effect.provide( | 59 | Effect.provide( |
| 55 | Layer.mergeAll(registryLayer, Layer.mock(GitHubCli)({}), Layer.mock(GitLabCli)({})), | 60 | Layer.mergeAll( |
| 61 | registryLayer, | ||
| 62 | Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({}), | ||
| 63 | Layer.mock(BitbucketApi.BitbucketApi)({}), | ||
| 64 | Layer.mock(GitHubCli.GitHubCli)({}), | ||
| 65 | Layer.mock(GitLabCli.GitLabCli)({}), | ||
| 66 | Layer.mock(VcsProcess.VcsProcess)({}), | ||
| 67 | ServerConfig.layerTest(process.cwd(), { prefix: "t3-source-control-registry-test-" }).pipe( | ||
| 68 | Layer.provide(NodeServices.layer), | ||
| 69 | ), | ||
| 70 | ), | ||
| 56 | ), | 71 | ), |
| 57 | ); | 72 | ); |
| 58 | } | 73 | } |
| @@ -93,6 +108,30 @@ it.effect("routes GitLab remotes to the GitLab provider", () => · 34 unmodified lines | |||
| 93 | }), | 108 | }), |
| 94 | ); | 109 | ); |
| 95 | 110 | ||
| 111 | it.effect("routes Bitbucket remotes to the Bitbucket provider", () => | ||
| 112 | Effect.gen(function* () { | ||
| 113 | const registry = yield* makeRegistry({ | ||
| 114 | remotes: [{ name: "origin", url: "git@bitbucket.org:pingdotgg/t3code.git" }], | ||
| 115 | }); | ||
| 116 | |||
| 117 | const provider = yield* registry.resolve({ cwd: "/repo" }); | ||
| 118 | |||
| 119 | assert.strictEqual(provider.kind, "bitbucket"); | ||
| 120 | }), | ||
| 121 | ); | ||
| 122 | |||
| 123 | it.effect("routes Azure DevOps remotes to the Azure DevOps provider", () => | ||
| 124 | Effect.gen(function* () { | ||
| 125 | const registry = yield* makeRegistry({ | ||
| 126 | remotes: [{ name: "origin", url: "https://dev.azure.com/acme/project/_git/repo" }], | ||
| 127 | }); | ||
| 128 | |||
| 129 | const provider = yield* registry.resolve({ cwd: "/repo" }); | ||
| 130 | |||
| 131 | assert.strictEqual(provider.kind, "azure-devops"); | ||
| 132 | }), | ||
| 133 | ); | ||
| 134 | |||
| 96 | it.effect("falls back to a non-origin remote when origin is not configured", () => | 135 | it.effect("falls back to a non-origin remote when origin is not configured", () => |
| 97 | Effect.gen(function* () { | 136 | Effect.gen(function* () { |
| 98 | const registry = yield* makeRegistry({ | 137 | const registry = yield* makeRegistry({ |