import { describe, expect, it } from 'vitest' import { accountingSettingsSchema, brandSchema, companySchema, contractSettingsSchema, customDomainSchema, insurancePolicySchema, pricingRuleSchema, subdomainSchema } from './company.schemas' describe('company schemas edge cases', () => { it('validates company and brand public configuration boundaries', () => { expect(companySchema.parse({ email: 'ops@example.test', address: { city: 'Rabat' } })).toMatchObject({ email: 'ops@example.test' }) expect(companySchema.safeParse({ email: 'bad-email' }).success).toBe(false) const brand = brandSchema.parse({ displayName: 'Atlas', websiteUrl: 'https://atlas.example.test', paypalEmail: 'paypal@example.test', defaultCurrency: 'MAD', homePageConfig: { showOffers: true, layout: { items: [{ id: 'hero-1', type: 'hero', x: 1, y: 1, w: 12, h: 4 }] } }, }) expect(brand.homePageConfig?.layout?.items[0].type).toBe('hero') expect(brandSchema.safeParse({ websiteUrl: 'not-url' }).success).toBe(false) expect(brandSchema.safeParse({ defaultCurrency: 'EUR' }).success).toBe(false) }) it('keeps contract, accounting, insurance, and pricing settings inside known enums', () => { expect(contractSettingsSchema.parse({ fuelPolicy: 'Return with the same fuel level.', fuelPolicyType: 'FULL_TO_FULL', additionalDriverPolicy: 'Additional drivers must be approved before pickup.', additionalDriverCharge: 'PER_DAY', })).toMatchObject({ fuelPolicy: 'Return with the same fuel level.', fuelPolicyType: 'FULL_TO_FULL', additionalDriverPolicy: 'Additional drivers must be approved before pickup.', }) expect(contractSettingsSchema.safeParse({ fuelPolicyType: 'CHAOS' }).success).toBe(false) expect(accountingSettingsSchema.parse({ reportingPeriod: 'MONTHLY', fiscalYearStart: 1, currency: 'MAD' })).toMatchObject({ fiscalYearStart: 1 }) expect(accountingSettingsSchema.safeParse({ fiscalYearStart: 13 }).success).toBe(false) expect(insurancePolicySchema.parse({ name: 'CDW', type: 'CDW', chargeType: 'PER_DAY', chargeValue: 100 })).toMatchObject({ isActive: true, isRequired: false, sortOrder: 0 }) expect(insurancePolicySchema.safeParse({ name: 'CDW', type: 'CDW', chargeType: 'PER_DAY', chargeValue: -1 }).success).toBe(false) expect(pricingRuleSchema.safeParse({ name: 'Young driver', type: 'SURCHARGE', condition: 'AGE_LESS_THAN', conditionValue: 25, adjustmentType: 'PERCENTAGE', adjustmentValue: 10 }).success).toBe(true) expect(pricingRuleSchema.safeParse({ name: '', type: 'SURCHARGE', condition: 'AGE_LESS_THAN', conditionValue: 25, adjustmentType: 'PERCENTAGE', adjustmentValue: 10 }).success).toBe(false) }) it('requires minimal custom domain and subdomain lengths', () => { expect(subdomainSchema.safeParse({ subdomain: 'ab' }).success).toBe(false) expect(customDomainSchema.safeParse({ customDomain: 'x.io' }).success).toBe(true) }) })