2020-06-27 00:22:45 +00:00
|
|
|
import { Money } from './money';
|
2020-06-26 21:31:30 +00:00
|
|
|
|
|
|
|
describe("Money", () => {
|
2020-06-27 00:35:09 +00:00
|
|
|
describe('Money.fromCents', () => {
|
|
|
|
it('succeeds from a old Money object', () => {
|
|
|
|
expect.assertions(2);
|
|
|
|
const old = Money.fromCents(333, 'eur');
|
2020-06-26 21:31:30 +00:00
|
|
|
|
2020-06-27 00:35:09 +00:00
|
|
|
const result = Money.fromCents(old);
|
|
|
|
expect(result).toStrictEqual(old);
|
2020-06-26 21:31:30 +00:00
|
|
|
|
2020-06-27 00:35:09 +00:00
|
|
|
expect(result).not.toBe(old);
|
|
|
|
});
|
|
|
|
it('succeeds from a json', () => {
|
|
|
|
expect.hasAssertions();
|
|
|
|
const old = { amount: 333, currency: 'eur' };
|
2020-06-26 21:31:30 +00:00
|
|
|
|
2020-06-27 00:35:09 +00:00
|
|
|
const result = Money.fromCents(old);
|
|
|
|
// eslint-disable-next-line jest/prefer-strict-equal
|
|
|
|
expect(result).toEqual(old);
|
2020-06-26 21:31:30 +00:00
|
|
|
|
2020-06-27 00:35:09 +00:00
|
|
|
expect(result).toBeInstanceOf(Money);
|
|
|
|
});
|
2020-06-26 21:31:30 +00:00
|
|
|
|
2020-06-27 00:35:09 +00:00
|
|
|
it('succeeds from function parameters', () => {
|
|
|
|
expect.hasAssertions();
|
|
|
|
const result = Money.fromCents(333, 'eur');
|
|
|
|
// eslint-disable-next-line jest/prefer-strict-equal
|
|
|
|
expect(result).toEqual({ amount: 333, currency: 'eur' });
|
2020-06-26 21:31:30 +00:00
|
|
|
|
2020-06-27 00:35:09 +00:00
|
|
|
expect(result).toBeInstanceOf(Money);
|
|
|
|
});
|
|
|
|
});
|
2020-06-27 00:22:45 +00:00
|
|
|
});
|