| 1 | import { AlchemyContext } from "@/AlchemyContext.ts"; |
| 2 | import { AuthProviders } from "@/Auth/AuthProvider.ts"; |
| 3 | import { ArtifactStore, createArtifactStore } from "@/Artifacts.ts"; |
| 4 | import * as CliKit from "@/Cli/CliKit/index.ts"; |
| 5 | import * as Neon from "@/Neon"; |
| 6 | import { Credentials } from "@/Neon/Credentials.ts"; |
| 7 | import { Stack } from "@/Stack.ts"; |
| 8 | import { Stage } from "@/Stage.ts"; |
| 9 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 10 | import { expect, it } from "alchemy-test"; |
| 11 | import * as ConfigProvider from "effect/ConfigProvider"; |
| 12 | import * as Effect from "effect/Effect"; |
| 13 | import * as Layer from "effect/Layer"; |
| 14 | import * as Result from "effect/Result"; |
| 15 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 16 | import { v4 as uuidv4 } from "uuid"; |
| 17 | |
| 18 | it.live( |
| 19 | "resolving Neon credentials rejects an unknown explicit profile", |
| 20 | () => |
| 21 | Effect.gen(function* () { |
| 22 | const result = yield* Effect.result( |
| 23 | Effect.sandbox( |
| 24 | Effect.gen(function* () { |
| 25 | return yield* yield* Credentials; |
| 26 | }).pipe(Effect.provide(Neon.providers())), |
| 27 | ), |
| 28 | ); |
| 29 | expect(Result.isFailure(result)).toBe(true); |
| 30 | if (Result.isFailure(result)) { |
| 31 | expect(String(result.failure)).toContain("does not exist"); |
| 32 | expect(String(result.failure)).toContain("alchemy profile create"); |
| 33 | } |
| 34 | }).pipe( |
| 35 | Effect.provide( |
| 36 | Layer.mergeAll( |
| 37 | Layer.succeed(AuthProviders, {}), |
| 38 | Layer.succeed(Stage, "test"), |
| 39 | Layer.succeed(Stack, { |
| 40 | name: "test", |
| 41 | stage: "test", |
| 42 | resources: {}, |
| 43 | bindings: {}, |
| 44 | actions: {}, |
| 45 | }), |
| 46 | Layer.succeed(AlchemyContext, { |
| 47 | dev: false, |
| 48 | adopt: false, |
| 49 | dotAlchemy: ".alchemy", |
| 50 | }), |
| 51 | Layer.succeed( |
| 52 | ConfigProvider.ConfigProvider, |
| 53 | ConfigProvider.fromUnknown({ |
| 54 | ALCHEMY_PROFILE: `non-existent-${uuidv4()}`, |
| 55 | }), |
| 56 | ), |
| 57 | Layer.sync(ArtifactStore, createArtifactStore), |
| 58 | NodeServices.layer, |
| 59 | FetchHttpClient.layer, |
| 60 | CliKit.layer({ input: false }), |
| 61 | ), |
| 62 | ), |
| 63 | ), |
| 64 | { tags: ["unit", "provider:neon", "local"] }, |
| 65 | ); |