t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/Lambda/toTimeoutSeconds.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

52 lines
1.7 KiB
TypeScript

import { toTimeoutSeconds } from "@/AWS/Lambda/Function.ts";
import * as Duration from "effect/Duration";
import { describe, expect, it } from "alchemy-test";
describe(
"toTimeoutSeconds",
{ tags: ["unit", "provider:aws", "provider:aws:lambda", "local"] },
() => {
it("returns undefined for undefined", () => {
expect(toTimeoutSeconds(undefined)).toBeUndefined();
});
it("converts a Duration to whole seconds", () => {
expect(toTimeoutSeconds(Duration.seconds(30))).toBe(30);
expect(toTimeoutSeconds(Duration.minutes(2))).toBe(120);
});
it("rounds sub-second and partial durations up", () => {
expect(toTimeoutSeconds(Duration.millis(1))).toBe(1);
expect(toTimeoutSeconds(Duration.millis(1500))).toBe(2);
expect(toTimeoutSeconds(Duration.millis(2001))).toBe(3);
});
it("returns undefined for an infinite Duration", () => {
expect(toTimeoutSeconds(Duration.infinity)).toBeUndefined();
});
describe("after state JSON round-trip", () => {
const roundTrip = (d: Duration.Duration) =>
JSON.parse(JSON.stringify(d)) as Duration.Duration;
it("converts a rehydrated Millis Duration", () => {
const json = roundTrip(Duration.seconds(42));
expect(json).toEqual({
_id: "Duration",
_tag: "Millis",
millis: 42_000,
});
expect(toTimeoutSeconds(json)).toBe(42);
});
it("converts a rehydrated Nanos Duration", () => {
const json = roundTrip(Duration.nanos(5_000_000_000n));
expect(toTimeoutSeconds(json)).toBe(5);
});
it("returns undefined for a rehydrated Infinity Duration", () => {
expect(toTimeoutSeconds(roundTrip(Duration.infinity))).toBeUndefined();
});
});
},
);