Files
butcem/src/shared/schemas/recurring.test.ts
T

51 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from "vitest";
import { recurringRuleFormSchema } from "./recurring";
/** Formun gönderdiği biçim: tüm alanlar string, seçilmeyenler boş. */
const formValues = {
type: "expense",
amount: "1.250,00",
isEstimate: false,
accountId: "a".repeat(24),
toAccountId: "",
categoryId: "b".repeat(24),
payee: "",
description: "",
tags: "",
startDate: "2026-11-05",
frequency: "monthly",
interval: "1",
monthlyMode: "day",
endKind: "never",
count: "",
endDate: "",
};
describe("recurringRuleFormSchema", () => {
it("boş isteğe bağlı alanlarla geçerli; bitiş türüne göre count/endDate ayıklanır", () => {
const x = recurringRuleFormSchema.parse(formValues);
expect(x).toMatchObject({ amount: 125000, interval: 1, count: null, endDate: null });
const c = recurringRuleFormSchema.parse({ ...formValues, endKind: "count", count: "12" });
expect(c.count).toBe(12);
const d = recurringRuleFormSchema.parse({
...formValues,
endKind: "date",
endDate: "2027-01-01",
count: "5",
});
expect(d).toMatchObject({ endDate: "2027-01-01", count: null });
});
it("seçilen bitiş türünün değeri zorunlu", () => {
expect(recurringRuleFormSchema.safeParse({ ...formValues, endKind: "count" }).success).toBe(
false,
);
expect(recurringRuleFormSchema.safeParse({ ...formValues, endKind: "date" }).success).toBe(
false,
);
expect(recurringRuleFormSchema.safeParse({ ...formValues, interval: "13" }).success).toBe(
false,
);
});
});