t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Prisma/LogsClient.test.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

71 lines
2.3 KiB
TypeScript

import { PrismaApiError } from "@/Prisma/Client";
import {
getBuildLogsRequest,
getDeploymentLogsRequest,
} from "@/Prisma/Internal/LogsClient";
import { Credentials } from "@/Prisma/Credentials";
import { describe, expect, it } from "alchemy-test";
import * as Effect from "effect/Effect";
import * as Redacted from "effect/Redacted";
const provideEnv = Effect.provideService(
Credentials,
Effect.succeed({
apiToken: Redacted.make("test-token"),
apiBaseUrl: "https://api.prisma.test",
}),
);
describe(
"Prisma log request builders",
{ tags: ["unit", "provider:prisma", "local"] },
() => {
it.effect("builds authenticated deployment log stream requests", () =>
Effect.gen(function* () {
const request = yield* getDeploymentLogsRequest("deployment-1", {
tail: 100,
fromStart: true,
cursor: "byte-42",
});
expect(request.url).toBe(
"wss://api.prisma.test/v1/deployments/deployment-1/logs?tail=100&cursor=byte-42&from_start=true",
);
expect(Redacted.value(request.headers.Authorization)).toBe(
"Bearer test-token",
);
}).pipe(provideEnv),
);
it.effect("builds authenticated build log stream requests", () =>
Effect.gen(function* () {
const request = yield* getBuildLogsRequest("build-1", {
follow: true,
cursor: "cursor-1",
});
expect(request.url).toBe(
"https://api.prisma.test/v1/builds/build-1/logs?follow=true&cursor=cursor-1",
);
expect(Redacted.value(request.headers.Authorization)).toBe(
"Bearer test-token",
);
expect(request.headers.Accept).toBe("application/x-ndjson");
}).pipe(provideEnv),
);
it.effect("rejects path-confusing resource IDs before building a URL", () =>
Effect.gen(function* () {
const deploymentLog = yield* getDeploymentLogsRequest(
"deployment-1/../../projects",
).pipe(Effect.flip);
const buildLog = yield* getBuildLogsRequest("build-1?token=leak").pipe(
Effect.flip,
);
for (const error of [deploymentLog, buildLog]) {
expect(error).toBeInstanceOf(PrismaApiError);
expect(error.message).toContain("invalid Prisma Management API");
}
}).pipe(provideEnv),
);
},
);