import { describe, expect, it } from "vitest"; import { numericValue, offerPatchSchema, parseFurnitureIds, } from "./offer-input"; describe("offer compatibility", () => { it.each([0, "0", -1, "-1"])( "preserves explicit numeric value %s", (value) => { expect(numericValue(value, 99)).toBe(Number(value)); }, ); it.each([null, undefined, "", "invalid", Infinity])( "defaults missing or invalid value %s", (value) => { expect(numericValue(value, 99)).toBe(99); }, ); it("preserves bundle multiplicity and LTD/special offer values", () => { expect(parseFurnitureIds("12;23;12")).toEqual([12, 23, 12]); const values = { itemIds: "12;23;12", amount: 0, offerId: -1, orderNumber: 0, limitedSells: 4, limitedStack: 20, songId: 0, extradata: "a;b", haveOffer: "0", clubOnly: "1", }; expect(offerPatchSchema.parse(values)).toEqual(values); }); it.each(["1;0", "1;2x", "1;;2", "-1", "1.5"])( "rejects invalid furniture references %s", (value) => { expect(() => parseFurnitureIds(value)).toThrow(); }, ); it("rejects invalid page ids and nonfinite prices without changing field meaning", () => { expect(offerPatchSchema.safeParse({ pageId: 0 }).success).toBe(false); expect(offerPatchSchema.safeParse({ costCredits: Infinity }).success).toBe( false, ); expect(offerPatchSchema.parse({ offerId: 0, amount: 0 })).toEqual({ offerId: 0, amount: 0, }); }); });