mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
feat: unify poll support
Co-authored-by: DBH <5251425+dbhurley@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { normalizePollDurationHours, normalizePollInput } from "./polls.js";
|
||||
|
||||
describe("polls", () => {
|
||||
it("normalizes question/options and validates maxSelections", () => {
|
||||
expect(
|
||||
normalizePollInput({
|
||||
question: " Lunch? ",
|
||||
options: [" Pizza ", " ", "Sushi"],
|
||||
maxSelections: 2,
|
||||
}),
|
||||
).toEqual({
|
||||
question: "Lunch?",
|
||||
options: ["Pizza", "Sushi"],
|
||||
maxSelections: 2,
|
||||
durationHours: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("enforces max option count when configured", () => {
|
||||
expect(() =>
|
||||
normalizePollInput(
|
||||
{ question: "Q", options: ["A", "B", "C"] },
|
||||
{ maxOptions: 2 },
|
||||
),
|
||||
).toThrow(/at most 2/);
|
||||
});
|
||||
|
||||
it("clamps poll duration with defaults", () => {
|
||||
expect(
|
||||
normalizePollDurationHours(undefined, { defaultHours: 24, maxHours: 48 }),
|
||||
).toBe(24);
|
||||
expect(
|
||||
normalizePollDurationHours(999, { defaultHours: 24, maxHours: 48 }),
|
||||
).toBe(48);
|
||||
expect(
|
||||
normalizePollDurationHours(1, { defaultHours: 24, maxHours: 48 }),
|
||||
).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user