Files
twenty_crm/packages/twenty-front/src/utils/__tests__/convert-currency-amount.test.ts
gitstart-twenty 5f7442cf23 Add jest tests for twenty-front (#2983)
* Add jest tests for twenty-front

Co-authored-by: v1b3m <vibenjamin6@gmail.com>

* Fix tests

---------

Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com>
Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
2023-12-15 10:53:20 +01:00

36 lines
1.2 KiB
TypeScript

import {
convertCurrencyMicrosToCurrency,
convertCurrencyToCurrencyMicros,
} from '~/utils/convert-currency-amount';
describe('convertCurrencyToCurrencyMicros', () => {
it('should return null if currencyAmount is null', () => {
expect(convertCurrencyToCurrencyMicros(null)).toBeNull();
});
it('should throw an error if currencyAmount converted to micros is not a whole number', () => {
expect(() => convertCurrencyToCurrencyMicros(1.023)).toThrow(
'Cannot convert 1.023 to micros',
);
});
it('should convert currencyAmount to micros', () => {
expect(convertCurrencyToCurrencyMicros(1)).toBe(1000000);
expect(convertCurrencyToCurrencyMicros(1.5)).toBe(1500000);
});
});
describe('convertCurrencyMicrosToCurrency', () => {
it('should return null if currencyAmountMicros is null', () => {
expect(convertCurrencyMicrosToCurrency(null)).toBeNull();
});
it('should return null if currencyAmountMicros is undefined', () => {
expect(convertCurrencyMicrosToCurrency(undefined)).toBeNull();
});
it('should convert currency micros to currency', () => {
expect(convertCurrencyMicrosToCurrency(24000000)).toBe(24);
});
});