04a17d2775
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
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,
|
||
);
|
||
});
|
||
});
|