1import { resolveBranchScope, type BranchScope } from "@/Neon/BranchScope";
2import { providers } from "@/Neon/Providers";
3import * as Test from "@/Test/Alchemy";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import * as Result from "effect/Result";
7
8const { test } = Test.make({ providers: providers() });
9
10test.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);