| 1 | import { resolveBranchScope, type BranchScope } from "@/Neon/BranchScope"; |
| 2 | import { providers } from "@/Neon/Providers"; |
| 3 | import * as Test from "@/Test/Alchemy"; |
| 4 | import { expect } from "alchemy-test"; |
| 5 | import * as Effect from "effect/Effect"; |
| 6 | import * as Result from "effect/Result"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: providers() }); |
| 9 | |
| 10 | test.provider( |
| 11 | "explicit branch scope and conflicting-scope rejection", |
| 12 | () => |
| 13 | Effect.gen(function* () { |
| 14 | expect( |
| 15 | yield* resolveBranchScope({ |
| 16 | branch: { projectId: "project", branchId: "branch" }, |
| 17 | }), |
| 18 | ).toEqual({ projectId: "project", branchId: "branch" }); |
| 19 | // @ts-expect-error Scope alternatives are mutually exclusive, including for JavaScript callers at runtime. |
| 20 | const conflict: BranchScope = { |
| 21 | project: { projectId: "project" }, |
| 22 | branch: { projectId: "project", branchId: "branch" }, |
| 23 | }; |
| 24 | expect( |
| 25 | Result.isFailure( |
| 26 | yield* resolveBranchScope(conflict).pipe(Effect.result), |
| 27 | ), |
| 28 | ).toBe(true); |
| 29 | expect( |
| 30 | // @ts-expect-error A scope declaration is required. |
| 31 | Result.isFailure(yield* resolveBranchScope({}).pipe(Effect.result)), |
| 32 | ).toBe(true); |
| 33 | }), |
| 34 | { tags: ["provider:neon", "provider:neon:branch", "live"] }, |
| 35 | ); |