t3-code-android-nightly/.repos/alchemy-effect/examples/prisma-tutorial/test/integ.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

38 lines
1.5 KiB
TypeScript

import * as Alchemy from "alchemy";
import * as Prisma from "alchemy/Prisma";
import * as Test from "alchemy/Test/Bun";
import { expect } from "bun:test";
import * as Console from "effect/Console";
import * as Effect from "effect/Effect";
import * as HttpClient from "effect/http/HttpClient";
import Stack from "../alchemy.run.ts";
const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
providers: Prisma.providers(),
state: Alchemy.localState(),
profile: process.env.ALCHEMY_PROFILE,
});
const stack = beforeAll(
destroy(Stack).pipe(Effect.andThen(deploy(Stack)), Effect.tap(Console.log)),
{ timeout: 120_000 },
);
afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack), { timeout: 120_000 });
test(
"serves the frontend and queries real Postgres",
Effect.gen(function* () {
const { url, apiUrl } = yield* stack;
const page = yield* Test.getWhenReady(String(url));
expect(yield* page.text).toContain("Prisma database clock");
const health = yield* Test.getWhenReady(`${apiUrl}/api/health`);
expect(yield* health.json).toEqual({ ok: true });
const response = yield* Test.getWhenReady(`${apiUrl}/api/time`);
expect(response.headers["access-control-allow-origin"]).toBe("*");
const data = (yield* response.json) as { time: string };
expect(data.time).toMatch(/^\d{4}-\d{2}-\d{2} /);
const client = yield* HttpClient.HttpClient;
expect((yield* client.get(`${apiUrl}/missing`)).status).toBe(404);
expect((yield* client.post(`${apiUrl}/api/time`)).status).toBe(405);
}),
{ timeout: 120_000 },
);