/** * Pure hydration rule: initialCompanyFormState. * * Verifies that PERSONAL users landing on /dashboard/company see an empty * name field (forcing a real business name) while keeping address.country * preserved from the signup context. Non-PERSONAL companies hydrate every * field as-stored. * * (c) 2026 TWWIM UG. All rights reserved. (www.twwim.com) */ import { describe, it, expect } from 'vitest'; import type { Company } from '@/domain/entities/Company'; import { initialCompanyFormState } from './companySettingsForm'; const baseCompany: Pick< Company, 'name' | 'website' | 'vatId' | 'industry' | 'size' | 'billingEmail' | 'address' > = { name: 'Max Mustermann', website: '', vatId: '', industry: '', size: '', billingEmail: '', address: { country: 'DE' }, }; describe('initialCompanyFormState', () => { it('blanks the name for PERSONAL upgrade but keeps address.country', () => { const state = initialCompanyFormState(baseCompany, true); expect(state.name).toBe(''); expect(state.address).toEqual({ country: 'DE' }); }); it('preserves existing name for non-PERSONAL companies', () => { const business = { ...baseCompany, name: 'Acme GmbH' }; const state = initialCompanyFormState(business, false); expect(state.name).toBe('Acme GmbH'); }); it('hydrates every non-name field regardless of PERSONAL flag', () => { const full = { ...baseCompany, name: 'Max Mustermann', website: 'https://example.com', vatId: 'DE123456789', industry: 'Tech', size: '1-10', billingEmail: 'billing@example.com', address: { street: 'Hauptstr 1', zip: '10115', city: 'Berlin', country: 'DE' }, }; const state = initialCompanyFormState(full, true); expect(state).toEqual({ name: '', website: 'https://example.com', vatId: 'DE123456789', industry: 'Tech', size: '1-10', billingEmail: 'billing@example.com', address: { street: 'Hauptstr 1', zip: '10115', city: 'Berlin', country: 'DE' }, // Pflichtangaben fields hydrate to '' when the company hasn't supplied them. legalForm: '', taxNumber: '', registerCourt: '', registerNumber: '', directorName: '', }); }); it('defaults country to DE (German-first) when the company has no address', () => { const noAddress = { ...baseCompany, address: undefined }; const state = initialCompanyFormState(noAddress, true); expect(state.address).toEqual({ country: 'DE' }); }); it('defaults country to DE when the address has no country', () => { const noCountry = { ...baseCompany, address: { street: 'Hauptstr 1', zip: '10115', city: 'Berlin' } }; const state = initialCompanyFormState(noCountry, false); expect(state.address.country).toBe('DE'); expect(state.address.city).toBe('Berlin'); }); });