t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Cloudflare/Workers/DurableObjectState.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

50 lines
1.5 KiB
TypeScript

import {
fromDurableObjectState,
type DurableObjectAbortOptions,
} from "@/Cloudflare/Workers/DurableObjectState.ts";
import { RuntimeContext } from "@/RuntimeContext.ts";
import { describe, expect, it } from "alchemy-test";
import * as Effect from "effect/Effect";
describe(
"fromDurableObjectState.abort",
{
tags: [
"unit",
"provider:cloudflare",
"provider:cloudflare:worker",
"local",
],
},
() => {
const mockState = (abort: (...args: unknown[]) => void) =>
fromDurableObjectState({
id: { toString: () => "id" },
storage: { sql: {} },
abort,
} as never);
it.effect("forwards reason to the raw DurableObjectState", () =>
Effect.gen(function* () {
const calls: unknown[][] = [];
const state = mockState((...args) => {
calls.push(args);
});
yield* state.abort("Hello, World!");
expect(calls).toEqual([["Hello, World!", undefined]]);
}).pipe(Effect.provide(RuntimeContext.phantom)),
);
it.effect("forwards retryAlarm options to the raw DurableObjectState", () =>
Effect.gen(function* () {
const calls: unknown[][] = [];
const state = mockState((...args) => {
calls.push(args);
});
const options: DurableObjectAbortOptions = { retryAlarm: false };
yield* state.abort("Cleanup complete", options);
expect(calls).toEqual([["Cleanup complete", options]]);
}).pipe(Effect.provide(RuntimeContext.phantom)),
);
},
);