Browse Source

Merge aa753d0146 into 90c90e179e

pull/8219/merge
Rene Turcios 16 hours ago
committed by GitHub
parent
commit
01aed2f6be
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 42
      apps/api/src/services/exchange-rate-data/exchange-rate-data.service.spec.ts
  2. 7
      apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts

42
apps/api/src/services/exchange-rate-data/exchange-rate-data.service.spec.ts

@ -0,0 +1,42 @@
import { ExchangeRateDataService } from './exchange-rate-data.service';
describe('ExchangeRateDataService', () => {
let service: ExchangeRateDataService;
beforeEach(() => {
service = new ExchangeRateDataService(null, null, null, null);
});
describe('toCurrency', () => {
it('should return the value unchanged for a null source currency without logging an error', () => {
const loggerSpy = jest.spyOn(service['logger'], 'error');
const result = service.toCurrency(100, null as any, 'EUR');
expect(result).toEqual(100);
expect(loggerSpy).not.toHaveBeenCalled();
});
it('should return the value unchanged for an undefined source currency without logging an error', () => {
const loggerSpy = jest.spyOn(service['logger'], 'error');
const result = service.toCurrency(100, undefined as any, 'EUR');
expect(result).toEqual(100);
expect(loggerSpy).not.toHaveBeenCalled();
});
it('should return the value unchanged for a null target currency without logging an error', () => {
const loggerSpy = jest.spyOn(service['logger'], 'error');
const result = service.toCurrency(100, 'EUR', null as any);
expect(result).toEqual(100);
expect(loggerSpy).not.toHaveBeenCalled();
});
it('should return 0 for a value of 0', () => {
expect(service.toCurrency(0, 'USD', 'EUR')).toEqual(0);
});
});
});

7
apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts

@ -257,6 +257,13 @@ export class ExchangeRateDataService {
return 0;
}
if (!aFromCurrency || !aToCurrency) {
// The currency of the value is unknown (e.g. an account without a
// currency), so no conversion can be performed. Return the value
// unchanged instead of logging an error for a "null" currency.
return aValue;
}
let factor: number;
if (aFromCurrency === aToCurrency) {

Loading…
Cancel
Save