| 1 | import { |
| 2 | fromDurableObjectState, |
| 3 | type DurableObjectAbortOptions, |
| 4 | } from "@/Cloudflare/Workers/DurableObjectState.ts"; |
| 5 | import { RuntimeContext } from "@/RuntimeContext.ts"; |
| 6 | import { describe, expect, it } from "alchemy-test"; |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | |
| 9 | describe( |
| 10 | "fromDurableObjectState.abort", |
| 11 | { |
| 12 | tags: [ |
| 13 | "unit", |
| 14 | "provider:cloudflare", |
| 15 | "provider:cloudflare:worker", |
| 16 | "local", |
| 17 | ], |
| 18 | }, |
| 19 | () => { |
| 20 | const mockState = (abort: (...args: unknown[]) => void) => |
| 21 | fromDurableObjectState({ |
| 22 | id: { toString: () => "id" }, |
| 23 | storage: { sql: {} }, |
| 24 | abort, |
| 25 | } as never); |
| 26 | |
| 27 | it.effect("forwards reason to the raw DurableObjectState", () => |
| 28 | Effect.gen(function* () { |
| 29 | const calls: unknown[][] = []; |
| 30 | const state = mockState((...args) => { |
| 31 | calls.push(args); |
| 32 | }); |
| 33 | yield* state.abort("Hello, World!"); |
| 34 | expect(calls).toEqual([["Hello, World!", undefined]]); |
| 35 | }).pipe(Effect.provide(RuntimeContext.phantom)), |
| 36 | ); |
| 37 | |
| 38 | it.effect("forwards retryAlarm options to the raw DurableObjectState", () => |
| 39 | Effect.gen(function* () { |
| 40 | const calls: unknown[][] = []; |
| 41 | const state = mockState((...args) => { |
| 42 | calls.push(args); |
| 43 | }); |
| 44 | const options: DurableObjectAbortOptions = { retryAlarm: false }; |
| 45 | yield* state.abort("Cleanup complete", options); |
| 46 | expect(calls).toEqual([["Cleanup complete", options]]); |
| 47 | }).pipe(Effect.provide(RuntimeContext.phantom)), |
| 48 | ); |
| 49 | }, |
| 50 | ); |