mirror of
https://github.com/Since-3/Kuma.git
synced 2026-10-12 20:51:18 +00:00
98 lines
3.2 KiB
TypeScript
98 lines
3.2 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import {
|
|
readTaxSettings,
|
|
toTaxColumns,
|
|
validateTaxSettings,
|
|
} from "@/src/modules/settings/lib/tax-settings";
|
|
|
|
describe("validateTaxSettings", () => {
|
|
it("verlangt bei Umsatzsteuerpflicht Steuersatz und eine Steuer-ID", () => {
|
|
expect(validateTaxSettings({ taxStatus: "regular", vatRate: 19 })).toMatchObject({
|
|
ok: false,
|
|
});
|
|
expect(
|
|
validateTaxSettings({ taxStatus: "regular", vatRate: 16, taxNumber: "12/345/67890" })
|
|
).toMatchObject({ ok: false });
|
|
expect(
|
|
validateTaxSettings({ taxStatus: "regular", vatRate: 19, taxNumber: "12/345/67890" })
|
|
).toEqual({
|
|
ok: true,
|
|
settings: { status: "regular", vatRate: 19, taxNumber: "12/345/67890", ustId: null },
|
|
});
|
|
});
|
|
|
|
it("akzeptiert eine reine Steuernummer - das war früher fälschlich ein Kleinunternehmer", () => {
|
|
const result = validateTaxSettings({
|
|
taxStatus: "regular",
|
|
vatRate: 19,
|
|
taxNumber: "12/345/67890",
|
|
ustId: "",
|
|
});
|
|
expect(result.ok && result.settings.status).toBe("regular");
|
|
});
|
|
|
|
it("lässt Kleinunternehmer ohne Steuer-ID zu", () => {
|
|
expect(validateTaxSettings({ taxStatus: "small_business" })).toEqual({
|
|
ok: true,
|
|
settings: { status: "small_business", taxNumber: null, ustId: null },
|
|
});
|
|
});
|
|
|
|
it("verlangt bei Steuerbefreiung den Grund, der auf der Rechnung steht", () => {
|
|
expect(validateTaxSettings({ taxStatus: "exempt", taxNumber: "12/345/67890" })).toMatchObject({
|
|
ok: false,
|
|
});
|
|
expect(
|
|
validateTaxSettings({
|
|
taxStatus: "exempt",
|
|
taxNumber: "12/345/67890",
|
|
taxExemptionNote: "Steuerfrei nach § 4 Nr. 21 UStG",
|
|
})
|
|
).toMatchObject({ ok: true, settings: { exemptionNote: "Steuerfrei nach § 4 Nr. 21 UStG" } });
|
|
});
|
|
|
|
it("normalisiert die USt-IdNr. und lehnt Unsinn ab", () => {
|
|
const ok = validateTaxSettings({ taxStatus: "small_business", ustId: " de 123 456 789 " });
|
|
expect(ok.ok && ok.settings.ustId).toBe("DE123456789");
|
|
expect(validateTaxSettings({ taxStatus: "small_business", ustId: "123" })).toMatchObject({
|
|
ok: false,
|
|
});
|
|
});
|
|
|
|
it("lehnt unbekannte Status ab", () => {
|
|
expect(validateTaxSettings({ taxStatus: "gemischt" })).toMatchObject({ ok: false });
|
|
});
|
|
});
|
|
|
|
describe("readTaxSettings", () => {
|
|
const empty = {
|
|
taxStatus: null,
|
|
vatRate: null,
|
|
taxNumber: null,
|
|
ustId: null,
|
|
taxExemptionNote: null,
|
|
};
|
|
|
|
it("liefert null, solange nichts hinterlegt ist - auch nicht bei vorhandener USt-IdNr.", () => {
|
|
expect(readTaxSettings(empty)).toBeNull();
|
|
expect(readTaxSettings({ ...empty, ustId: "DE123456789" })).toBeNull();
|
|
});
|
|
|
|
it("liefert null für einen gespeicherten, aber unvollständigen Stand", () => {
|
|
expect(readTaxSettings({ ...empty, taxStatus: "regular", vatRate: 19 })).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("toTaxColumns", () => {
|
|
it("leert Felder, die zum gewählten Status nicht gehören", () => {
|
|
expect(
|
|
toTaxColumns({ status: "small_business", taxNumber: "12/345/67890", ustId: null })
|
|
).toEqual({
|
|
taxStatus: "small_business",
|
|
vatRate: null,
|
|
taxNumber: "12/345/67890",
|
|
ustId: null,
|
|
taxExemptionNote: null,
|
|
});
|
|
});
|
|
});
|