import { vi } from 'vitest'; import type { SapClientService } from '../sap/sap-client.service.js'; import { CompanyService } from './company.service.js'; describe('CompanyService', () => { const make = (data: unknown) => { const request = vi.fn(async () => ({ data })); return { service: new CompanyService({ request } as unknown as SapClientService), request }; }; it('entrega solo el redondeo y el separador, sin el resto de la información de la empresa', async () => { const { service, request } = make({ RoundingMethod: 'tYES', AccountSegmentsSeparator: '.', LocalCurrency: 'SOL', DefaultBankAccount: '192-1153365-0-50' }); const settings = await service.settings(); expect(settings).toEqual({ roundingEnabled: true, accountSegmentsSeparator: '.', localCurrency: 'SOL' }); expect(request).toHaveBeenCalledWith({ method: 'POST', path: 'CompanyService_GetAdminInfo', body: {} }); }); it('sin redondeo ni separador usa los valores por defecto', async () => { const { service } = make({ RoundingMethod: 'tNO', AccountSegmentsSeparator: null }); expect(await service.settings()).toEqual({ roundingEnabled: false, accountSegmentsSeparator: '-', localCurrency: '' }); }); it('recuerda la respuesta un rato y luego la vuelve a pedir', async () => { const { service, request } = make({ RoundingMethod: 'tYES' }); await service.settings(1000); await service.settings(1000 + 60_000); expect(request).toHaveBeenCalledTimes(1); await service.settings(1000 + 11 * 60_000); expect(request).toHaveBeenCalledTimes(2); }); });