import { describe, it, expect, beforeEach } from 'vitest' import { setActivePinia, createPinia } from 'pinia' import { useCustomerStore } from '@/stores' describe('Customer Workflow Integration Tests', () => { beforeEach(() => { setActivePinia(createPinia()) }) describe('Customer Management', () => { it('should create and manage customers', async () => { const customerStore = useCustomerStore() const customer = await customerStore.createCustomer({ code: 'CUST-001', name: 'Test Customer', email: 'test@example.com', phone: '123-456-7890', address: '123 Main St', city: 'Springfield', country: 'USA', creditLimit: 10000 }) expect(customer.code).toBe('CUST-001') expect(customer.status).toBe('ACTIVE') expect(customer.creditUsed).toBe(0) }) it('should track credit usage', async () => { const customerStore = useCustomerStore() const customer = await customerStore.createCustomer({ code: 'CUST-002', name: 'Credit Test', email: 'credit@test.com', phone: '999-999-9999', address: 'Test', city: 'Test', country: 'USA', creditLimit: 5000 }) await customerStore.updateCreditUsage(customer.id, 2000) const updated = customerStore.customers.find((c) => c.id === customer.id) expect(updated?.creditUsed).toBe(2000) }) it('should identify at-risk customers', async () => { const customerStore = useCustomerStore() const customer = await customerStore.createCustomer({ code: 'CUST-RISK', name: 'Risk Customer', email: 'risk@test.com', phone: '888-888-8888', address: 'Risk Ave', city: 'Risk City', country: 'USA', creditLimit: 1000 }) // Use 85% of credit await customerStore.updateCreditUsage(customer.id, 850) const atRisk = customerStore.atRiskCustomers expect(atRisk.some((c) => c.id === customer.id)).toBe(true) }) it('should update customer status', async () => { const customerStore = useCustomerStore() const customer = await customerStore.createCustomer({ code: 'CUST-003', name: 'Status Test', email: 'status@test.com', phone: '777-777-7777', address: 'Status St', city: 'Status City', country: 'USA' }) await customerStore.updateCustomer(customer.id, { status: 'SUSPENDED' }) const updated = customerStore.customers.find((c) => c.id === customer.id) expect(updated?.status).toBe('SUSPENDED') }) }) describe('Customer Validation', () => { it('should maintain active customer count', async () => { const customerStore = useCustomerStore() const initial = customerStore.activeCustomers.length await customerStore.createCustomer({ code: 'CUST-NEW', name: 'New Customer', email: 'new@test.com', phone: '666-666-6666', address: 'New St', city: 'New City', country: 'USA' }) expect(customerStore.activeCustomers.length).toBe(initial + 1) }) }) })