Add comprehensive tests for client validation, revenue and expense categories, invoice generation, and schemas
- Implement tests for client validation functions including tax ID, VAT ID, IBAN, BIC, website, and company form validation. - Create tests for revenue and expense categories ensuring all expected categories and labels are present. - Add tests for invoice number generation with various scenarios including prefix handling and sequence padding. - Introduce tests for default categories and their integration, ensuring no overlaps and consistent naming conventions. - Implement Zod schema validation tests for currency, tax rates, IBAN, tax ID, VAT ID, invoices, companies, and customers. - Add utility tests for tax calculations, including item amounts and invoice totals, ensuring correct handling of tax rates and formatting. - Set up Vitest configuration and global test setup for consistent testing environment.
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
EINNAHME_KATEGORIEN,
|
||||
EINNAHME_LABELS,
|
||||
type EinnahmeKategorieKey,
|
||||
} from "@/lib/einnahmen";
|
||||
import {
|
||||
AUSGABE_KATEGORIEN,
|
||||
KATEGORIE_LABELS,
|
||||
type AusgabeKategorieKey,
|
||||
} from "@/lib/ausgaben";
|
||||
|
||||
describe("einnahmen.ts - Revenue Categories", () => {
|
||||
it("should have all expected categories", () => {
|
||||
expect(EINNAHME_KATEGORIEN).toContain("FUSSPFLEGE");
|
||||
expect(EINNAHME_KATEGORIEN).toContain("PRIVATEINLAGEN");
|
||||
expect(EINNAHME_KATEGORIEN).toContain("DARLEHEN");
|
||||
expect(EINNAHME_KATEGORIEN).toContain("STEUERERSTATTUNGEN");
|
||||
expect(EINNAHME_KATEGORIEN).toContain("ZINSERTRAEGE");
|
||||
expect(EINNAHME_KATEGORIEN).toContain("VERMIETUNG_VERPACHTUNG");
|
||||
expect(EINNAHME_KATEGORIEN).toContain("VERAEUSSERUNGSERLOES");
|
||||
expect(EINNAHME_KATEGORIEN).toContain("EIGENVERBRAUCH");
|
||||
expect(EINNAHME_KATEGORIEN).toContain("SONSTIGE_EINNAHMEN");
|
||||
});
|
||||
|
||||
it("should have 10 revenue categories", () => {
|
||||
expect(EINNAHME_KATEGORIEN).toHaveLength(10);
|
||||
});
|
||||
|
||||
it("should have labels for all categories", () => {
|
||||
EINNAHME_KATEGORIEN.forEach((key) => {
|
||||
expect(EINNAHME_LABELS[key as EinnahmeKategorieKey]).toBeDefined();
|
||||
expect(typeof EINNAHME_LABELS[key as EinnahmeKategorieKey]).toBe("string");
|
||||
});
|
||||
});
|
||||
|
||||
it("should have correct labels", () => {
|
||||
expect(EINNAHME_LABELS.FUSSPFLEGE).toBe("Fußpflege/Verkauf/Gutscheine");
|
||||
expect(EINNAHME_LABELS.PRIVATEINLAGEN).toBe("Privateinlagen");
|
||||
expect(EINNAHME_LABELS.DARLEHEN).toBe("Darlehen");
|
||||
expect(EINNAHME_LABELS.ZINSERTRAEGE).toBe("Zinserträge");
|
||||
});
|
||||
|
||||
it("should have valid TypeScript types", () => {
|
||||
const testKey: EinnahmeKategorieKey = "FUSSPFLEGE";
|
||||
expect(testKey).toBe("FUSSPFLEGE");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ausgaben.ts - Expense Categories", () => {
|
||||
it("should have all expected categories", () => {
|
||||
expect(AUSGABE_KATEGORIEN).toContain("WAREN_ROHSTOFFE");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("GERINGWERTIGE_WIRTSCHAFTSGUETER");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("ABSCHREIBUNGEN");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("MIETE");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("STROM_WASSER");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("TELEKOMMUNIKATION");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("FORTBILDUNG_MESSEN");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("BEITRAEGE");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("VERSICHERUNGEN");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("WERBEKOSTEN");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("ZINSEN");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("REISEKOSTEN");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("REPARATUREN_INSTANDHALTUNG");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("BUEROBEDARF");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("REPRAESENTATIONSKOSTEN");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("SONSTIGER_BETRIEBSBEDARF");
|
||||
expect(AUSGABE_KATEGORIEN).toContain("NEBENKOSTEN_GELDVERKEHR");
|
||||
});
|
||||
|
||||
it("should have 17 expense categories", () => {
|
||||
expect(AUSGABE_KATEGORIEN).toHaveLength(17);
|
||||
});
|
||||
|
||||
it("should have labels for all categories", () => {
|
||||
AUSGABE_KATEGORIEN.forEach((key) => {
|
||||
expect(KATEGORIE_LABELS[key as AusgabeKategorieKey]).toBeDefined();
|
||||
expect(typeof KATEGORIE_LABELS[key as AusgabeKategorieKey]).toBe("string");
|
||||
});
|
||||
});
|
||||
|
||||
it("should have correct labels", () => {
|
||||
expect(KATEGORIE_LABELS.WAREN_ROHSTOFFE).toBe("Waren, Rohstoffe, Hilfsstoffe");
|
||||
expect(KATEGORIE_LABELS.GERINGWERTIGE_WIRTSCHAFTSGUETER).toBe(
|
||||
"Geringwertige Wirtschaftsgüter"
|
||||
);
|
||||
expect(KATEGORIE_LABELS.MIETE).toBe("Miete");
|
||||
expect(KATEGORIE_LABELS.ZINSEN).toBe("Zinsen");
|
||||
});
|
||||
|
||||
it("should have valid TypeScript types", () => {
|
||||
const testKey: AusgabeKategorieKey = "MIETE";
|
||||
expect(testKey).toBe("MIETE");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Category Integration", () => {
|
||||
it("should not have overlapping keys between revenue and expenses", () => {
|
||||
const overlap = EINNAHME_KATEGORIEN.filter((key) =>
|
||||
AUSGABE_KATEGORIEN.includes(key as any)
|
||||
);
|
||||
expect(overlap).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("should have consistent naming convention (uppercase with underscores)", () => {
|
||||
const validPattern = /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/;
|
||||
|
||||
EINNAHME_KATEGORIEN.forEach((key) => {
|
||||
expect(key).toMatch(validPattern);
|
||||
});
|
||||
|
||||
AUSGABE_KATEGORIEN.forEach((key) => {
|
||||
expect(key).toMatch(validPattern);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user