db953b1e28
- 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.
68 lines
1.5 KiB
Markdown
68 lines
1.5 KiB
Markdown
# Tests - Annas RechnungsManager
|
|
|
|
Vitest-basiertes Test-Framework für kritische Geschäftslogik.
|
|
|
|
## Setup
|
|
|
|
```bash
|
|
# Install dependencies (already done)
|
|
npm install
|
|
|
|
# Run tests
|
|
npm run test # Single run
|
|
npm run test:watch # Watch mode
|
|
npm run test:ui # Browser UI
|
|
npm run test:coverage # With coverage report
|
|
```
|
|
|
|
## Test Structure
|
|
|
|
```
|
|
tests/
|
|
├── lib/
|
|
│ ├── tax.test.ts # Steuerberechnungen (§14 UStG)
|
|
│ └── schemas.test.ts # Zod-Validierung (Input-Sicherheit)
|
|
└── README.md
|
|
```
|
|
|
|
## Coverage
|
|
|
|
- ✅ **tax.ts** - German tax calculations (19%, 7%, Kleinunternehmer)
|
|
- ✅ **schemas.ts** - Input validation (Zod schemas)
|
|
- ⚠️ **invoice-number.server.ts** - Requires Prisma mocking (TODO)
|
|
|
|
## Critical Test Areas
|
|
|
|
1. **Tax Calculations** - Must be correct per German tax law
|
|
2. **Input Validation** - Prevent invalid data in DB
|
|
3. **Invoice Logic** - §14 UStG compliance
|
|
4. **Buchhaltung** - Double-entry bookkeeping accuracy
|
|
|
|
## Running Specific Tests
|
|
|
|
```bash
|
|
# Run only tax tests
|
|
npx vitest run tests/lib/tax.test.ts
|
|
|
|
# Run with coverage
|
|
npm run test:coverage
|
|
# Opens: ./coverage/index.html
|
|
```
|
|
|
|
## Writing New Tests
|
|
|
|
```typescript
|
|
import { describe, it, expect } from "vitest";
|
|
import { myFunction } from "@/lib/my-module";
|
|
|
|
describe("myModule", () => {
|
|
it("should do something", () => {
|
|
expect(myFunction()).toBe(expected);
|
|
});
|
|
});
|
|
```
|
|
|
|
## CI Integration
|
|
|
|
Tests laufen automatisch in der Gitea Actions Pipeline (`.gitea/workflows/build.yml`).
|