Skip to content

Commit 963ae55

Browse files
authored
feat(payment-stripe): update currency conversions (#171)
1 parent 56e1e12 commit 963ae55

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect } from 'chai';
2+
import convertBalanceFromUnit from '@helpers/convert-balance-from-unit';
3+
4+
describe('helpers/convert-balance-from-unit', () => {
5+
it('should correctly convert balance: pending usd balance', () => {
6+
expect(
7+
convertBalanceFromUnit({
8+
available: { usd: 0, eur: 0 },
9+
instant: { usd: 0, eur: 0 },
10+
pending: { usd: 2820000, eur: 0 },
11+
}),
12+
).to.deep.equal({
13+
available: { usd: 0, eur: 0 },
14+
instant: { usd: 0, eur: 0 },
15+
pending: { usd: 28200, eur: 0 },
16+
});
17+
});
18+
19+
it('should correctly convert balance: whole usd balances', () => {
20+
expect(
21+
convertBalanceFromUnit({
22+
available: { usd: 100, eur: 0 },
23+
instant: { usd: 2000000, eur: 0 },
24+
pending: { usd: 2820000, eur: 0 },
25+
}),
26+
).to.deep.equal({
27+
available: { usd: 1, eur: 0 },
28+
instant: { usd: 20000, eur: 0 },
29+
pending: { usd: 28200, eur: 0 },
30+
});
31+
});
32+
});

microservices/payment-stripe/src/helpers/convert-balance-from-unit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import type { TCustomerBalance } from '@services/payment-gateway/stripe';
99
const convertBalanceFromUnit = (balance: TCustomerBalance): TCustomerBalance => {
1010
const currencies = { usd: 0, eur: 0 };
1111
const convertedInput: TCustomerBalance = {
12-
[BalanceType.INSTANT]: currencies,
13-
[BalanceType.PENDING]: currencies,
14-
[BalanceType.AVAILABLE]: currencies,
12+
[BalanceType.INSTANT]: { ...currencies },
13+
[BalanceType.PENDING]: { ...currencies },
14+
[BalanceType.AVAILABLE]: { ...currencies },
1515
};
1616

1717
Object.keys(balance).forEach((type: BalanceType) => {

0 commit comments

Comments
 (0)