@adtrackify/at-service-common 3.2.30 → 3.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/__tests__/libs/currency.spec.js +56 -46
- package/dist/cjs/__tests__/libs/currency.spec.js.map +1 -1
- package/dist/cjs/libs/currency.d.ts +1 -2
- package/dist/cjs/libs/currency.js +6 -6
- package/dist/cjs/libs/currency.js.map +1 -1
- package/dist/esm/__tests__/libs/currency.spec.js +56 -43
- package/dist/esm/__tests__/libs/currency.spec.js.map +1 -1
- package/dist/esm/libs/currency.d.ts +1 -2
- package/dist/esm/libs/currency.js +6 -6
- package/dist/esm/libs/currency.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const big_js_1 = __importDefault(require("big.js"));
|
|
7
3
|
const currency_1 = require("../../libs/currency");
|
|
8
4
|
const helpers_1 = require("../../helpers");
|
|
9
5
|
jest.mock('../../helpers', () => ({
|
|
@@ -17,95 +13,93 @@ describe('convertAmountBetweenCurrencies', () => {
|
|
|
17
13
|
});
|
|
18
14
|
describe('successful conversions', () => {
|
|
19
15
|
it('should convert USD to EUR with exchange rate', () => {
|
|
20
|
-
const amount =
|
|
16
|
+
const amount = 100.00;
|
|
21
17
|
const fromCurrency = 'USD';
|
|
22
18
|
const toCurrency = 'EUR';
|
|
23
19
|
const exchangeRate = 0.85;
|
|
24
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
20
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
25
21
|
expect(result).toBe(85.00);
|
|
26
22
|
});
|
|
27
23
|
it('should convert EUR to USD with exchange rate', () => {
|
|
28
|
-
const amount =
|
|
24
|
+
const amount = 100.00;
|
|
29
25
|
const fromCurrency = 'EUR';
|
|
30
26
|
const toCurrency = 'USD';
|
|
31
27
|
const exchangeRate = 1.18;
|
|
32
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
28
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
33
29
|
expect(result).toBe(118.00);
|
|
34
30
|
});
|
|
35
31
|
it('should handle decimal amounts correctly', () => {
|
|
36
|
-
const amount =
|
|
32
|
+
const amount = 123.45;
|
|
37
33
|
const fromCurrency = 'USD';
|
|
38
34
|
const toCurrency = 'EUR';
|
|
39
35
|
const exchangeRate = 0.92;
|
|
40
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
36
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
41
37
|
expect(result).toBe(113.57);
|
|
42
38
|
});
|
|
43
39
|
it('should round result to 2 decimal places', () => {
|
|
44
|
-
const amount =
|
|
40
|
+
const amount = 100.00;
|
|
45
41
|
const fromCurrency = 'USD';
|
|
46
42
|
const toCurrency = 'EUR';
|
|
47
43
|
const exchangeRate = 0.333333;
|
|
48
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
44
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
49
45
|
expect(result).toBe(33.33);
|
|
50
46
|
});
|
|
51
47
|
it('should handle zero amount', () => {
|
|
52
|
-
const amount =
|
|
48
|
+
const amount = 0.00;
|
|
53
49
|
const fromCurrency = 'USD';
|
|
54
50
|
const toCurrency = 'EUR';
|
|
55
51
|
const exchangeRate = 0.85;
|
|
56
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
52
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
57
53
|
expect(result).toBe(0.00);
|
|
58
54
|
});
|
|
59
55
|
it('should handle exchange rate of 1', () => {
|
|
60
|
-
const amount =
|
|
56
|
+
const amount = 100.00;
|
|
61
57
|
const fromCurrency = 'USD';
|
|
62
58
|
const toCurrency = 'USD';
|
|
63
59
|
const exchangeRate = 1.0;
|
|
64
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
60
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
65
61
|
expect(result).toBe(100.00);
|
|
66
62
|
});
|
|
67
63
|
it('should handle very small amounts', () => {
|
|
68
|
-
const amount =
|
|
64
|
+
const amount = 0.01;
|
|
69
65
|
const fromCurrency = 'USD';
|
|
70
66
|
const toCurrency = 'EUR';
|
|
71
67
|
const exchangeRate = 0.85;
|
|
72
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
68
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
73
69
|
expect(result).toBe(0.01);
|
|
74
70
|
});
|
|
75
71
|
it('should handle large amounts', () => {
|
|
76
|
-
const amount =
|
|
72
|
+
const amount = 1000000.00;
|
|
77
73
|
const fromCurrency = 'USD';
|
|
78
74
|
const toCurrency = 'EUR';
|
|
79
75
|
const exchangeRate = 0.85;
|
|
80
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
76
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
81
77
|
expect(result).toBe(850000.00);
|
|
82
78
|
});
|
|
83
79
|
});
|
|
84
80
|
describe('error handling', () => {
|
|
85
|
-
it('should return
|
|
86
|
-
const amount =
|
|
81
|
+
it('should return undefined when exchange rate is invalid', () => {
|
|
82
|
+
const amount = 100.00;
|
|
87
83
|
const fromCurrency = 'USD';
|
|
88
84
|
const toCurrency = 'EUR';
|
|
89
85
|
const exchangeRate = NaN;
|
|
90
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
91
|
-
expect(result).
|
|
92
|
-
expect(helpers_1.Logger.error).toHaveBeenCalledWith('
|
|
93
|
-
error: expect.any(Error),
|
|
86
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
87
|
+
expect(result).toBeUndefined();
|
|
88
|
+
expect(helpers_1.Logger.error).toHaveBeenCalledWith('Amount and exchange rate must be valid numbers', {
|
|
94
89
|
amount,
|
|
95
90
|
fromCurrency,
|
|
96
91
|
toCurrency,
|
|
97
92
|
exchangeRate: NaN,
|
|
98
93
|
});
|
|
99
94
|
});
|
|
100
|
-
it('should return
|
|
101
|
-
const amount =
|
|
95
|
+
it('should return undefined when exchange rate is Infinity', () => {
|
|
96
|
+
const amount = 100.00;
|
|
102
97
|
const fromCurrency = 'USD';
|
|
103
98
|
const toCurrency = 'EUR';
|
|
104
99
|
const exchangeRate = Infinity;
|
|
105
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
106
|
-
expect(result).
|
|
107
|
-
expect(helpers_1.Logger.error).toHaveBeenCalledWith('
|
|
108
|
-
error: expect.any(Error),
|
|
100
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
101
|
+
expect(result).toBeUndefined();
|
|
102
|
+
expect(helpers_1.Logger.error).toHaveBeenCalledWith('Amount and exchange rate must be valid numbers', {
|
|
109
103
|
amount,
|
|
110
104
|
fromCurrency,
|
|
111
105
|
toCurrency,
|
|
@@ -115,54 +109,70 @@ describe('convertAmountBetweenCurrencies', () => {
|
|
|
115
109
|
});
|
|
116
110
|
describe('edge cases', () => {
|
|
117
111
|
it('should handle very small exchange rates', () => {
|
|
118
|
-
const amount =
|
|
112
|
+
const amount = 100.00;
|
|
119
113
|
const fromCurrency = 'USD';
|
|
120
114
|
const toCurrency = 'JPY';
|
|
121
115
|
const exchangeRate = 0.001;
|
|
122
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
116
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
123
117
|
expect(result).toBe(0.10);
|
|
124
118
|
});
|
|
125
119
|
it('should handle very large exchange rates', () => {
|
|
126
|
-
const amount =
|
|
120
|
+
const amount = 1.00;
|
|
127
121
|
const fromCurrency = 'JPY';
|
|
128
122
|
const toCurrency = 'USD';
|
|
129
123
|
const exchangeRate = 1000;
|
|
130
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
124
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
131
125
|
expect(result).toBe(1000.00);
|
|
132
126
|
});
|
|
133
127
|
it('should handle zero exchange rate', () => {
|
|
134
|
-
const amount =
|
|
128
|
+
const amount = 100.00;
|
|
135
129
|
const fromCurrency = 'USD';
|
|
136
130
|
const toCurrency = 'EUR';
|
|
137
131
|
const exchangeRate = 0;
|
|
138
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
132
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
139
133
|
expect(result).toBe(0.00);
|
|
140
134
|
});
|
|
141
135
|
it('should handle different currency codes', () => {
|
|
142
|
-
const amount =
|
|
136
|
+
const amount = 50.00;
|
|
143
137
|
const fromCurrency = 'GBP';
|
|
144
138
|
const toCurrency = 'CAD';
|
|
145
139
|
const exchangeRate = 1.75;
|
|
146
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
140
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
147
141
|
expect(result).toBe(87.50);
|
|
148
142
|
});
|
|
149
143
|
});
|
|
150
144
|
describe('Big.js precision handling', () => {
|
|
151
145
|
it('should handle Big.js precision correctly', () => {
|
|
152
|
-
const amount =
|
|
146
|
+
const amount = '0.333333333333333333';
|
|
153
147
|
const fromCurrency = 'USD';
|
|
154
148
|
const toCurrency = 'EUR';
|
|
155
149
|
const exchangeRate = 0.85;
|
|
156
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
150
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
157
151
|
expect(result).toBe(0.28);
|
|
158
152
|
});
|
|
159
153
|
it('should handle Big.js with high precision exchange rate', () => {
|
|
160
|
-
const amount =
|
|
154
|
+
const amount = '1931305.25';
|
|
161
155
|
const fromCurrency = 'USD';
|
|
162
156
|
const toCurrency = 'EUR';
|
|
163
|
-
const exchangeRate =
|
|
164
|
-
const result = (0, currency_1.convertAmountBetweenCurrencies)(
|
|
165
|
-
expect(result).toBe(
|
|
157
|
+
const exchangeRate = 1.165772907437631;
|
|
158
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
159
|
+
expect(result).toBe(2251463.34);
|
|
160
|
+
});
|
|
161
|
+
it('should handle Big.js with high precision exchange rate', () => {
|
|
162
|
+
const amount = '6809633.24';
|
|
163
|
+
const fromCurrency = 'CAD';
|
|
164
|
+
const toCurrency = 'USD';
|
|
165
|
+
const exchangeRate = 0.7276431637924762;
|
|
166
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
167
|
+
expect(result).toBe(4954983.08);
|
|
168
|
+
});
|
|
169
|
+
it('should handle Big.js with high precision exchange rate', () => {
|
|
170
|
+
const amount = '81.1723990090352666861';
|
|
171
|
+
const fromCurrency = 'CAD';
|
|
172
|
+
const toCurrency = 'USD';
|
|
173
|
+
const exchangeRate = 0.6520179956966812;
|
|
174
|
+
const result = (0, currency_1.convertAmountBetweenCurrencies)(fromCurrency, toCurrency, amount, exchangeRate);
|
|
175
|
+
expect(result).toBe(52.93);
|
|
166
176
|
});
|
|
167
177
|
});
|
|
168
178
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.spec.js","sourceRoot":"","sources":["../../../../src/__tests__/libs/currency.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"currency.spec.js","sourceRoot":"","sources":["../../../../src/__tests__/libs/currency.spec.ts"],"names":[],"mappings":";;AAKA,kDAAqE;AACrE,2CAAuC;AAEvC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAChC,MAAM,EAAE;QACN,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;KACjB;CACF,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;YACtD,MAAM,MAAM,GAAG,MAAM,CAAC;YACtB,MAAM,YAAY,GAAG,KAAK,CAAC;YAC3B,MAAM,UAAU,GAAG,KAAK,CAAC;YACzB,MAAM,YAAY,GAAG,IAAI,CAAC;YAE1B,MAAM,MAAM,GAAG,IAAA,yCAA8B,EAAC,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;YAE9F,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;YACtD,MAAM,MAAM,GAAG,MAAM,CAAC;YACtB,MAAM,YAAY,GAAG,KAAK,CAAC;YAC3B,MAAM,UAAU,GAAG,KAAK,CAAC;YACzB,MAAM,YAAY,GAAG,IAAI,CAAC;YAE1B,MAAM,MAAM,GAAG,IAAA,yCAA8B,EAAC,YAAY,EAAE,UAAU,EAA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AM,YAAY,GAAG,kBAAkB,CAAC;YAExC,MAAM,MAAM,GAAG,IAAA,yCAA8B,EAAC,YAAY,EAAE,UAAU,EAAE,MAAuB,EAAE,YAAY,CAAC,CAAC;YAE/G,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE;YAChE,MAAM,MAAM,GAAG,wBAAwB,CAAC;YACxC,MAAM,YAAY,GAAG,KAAK,CAAC;YAC3B,MAAM,UAAU,GAAG,KAAK,CAAC;YACzB,MAAM,YAAY,GAAG,kBAAkB,CAAC;YAExC,MAAM,MAAM,GAAG,IAAA,yCAA8B,EAAC,YAAY,EAAE,UAAU,EAAE,MAAuB,EAAE,YAAY,CAAC,CAAC;YAE/G,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const convertAmountBetweenCurrencies: (amount: Big, fromCurrency: string, toCurrency: string, exchangeRate: number) => number | null;
|
|
1
|
+
export declare const convertAmountBetweenCurrencies: (fromCurrency: string, toCurrency: string, amount: number, exchangeRate: number) => number | undefined;
|
|
@@ -6,18 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.convertAmountBetweenCurrencies = void 0;
|
|
7
7
|
const big_js_1 = __importDefault(require("big.js"));
|
|
8
8
|
const helpers_1 = require("../helpers");
|
|
9
|
-
const convertAmountBetweenCurrencies = (
|
|
9
|
+
const convertAmountBetweenCurrencies = (fromCurrency, toCurrency, amount, exchangeRate) => {
|
|
10
10
|
try {
|
|
11
|
-
if (
|
|
12
|
-
helpers_1.Logger.error('Amount and exchange rate must be numbers', { amount, fromCurrency, toCurrency, exchangeRate });
|
|
13
|
-
return
|
|
11
|
+
if (isNaN(amount) || isNaN(exchangeRate) || !isFinite(amount) || !isFinite(exchangeRate)) {
|
|
12
|
+
helpers_1.Logger.error('Amount and exchange rate must be valid numbers', { amount, fromCurrency, toCurrency, exchangeRate });
|
|
13
|
+
return undefined;
|
|
14
14
|
}
|
|
15
15
|
const exchangeRateBig = (0, big_js_1.default)(exchangeRate);
|
|
16
|
-
return amount.times(exchangeRateBig).round(2).toNumber();
|
|
16
|
+
return (0, big_js_1.default)(amount).times(exchangeRateBig).round(2).toNumber();
|
|
17
17
|
}
|
|
18
18
|
catch (error) {
|
|
19
19
|
helpers_1.Logger.error('Failed to convert currency', { error, amount, fromCurrency, toCurrency, exchangeRate });
|
|
20
|
-
return
|
|
20
|
+
return undefined;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
exports.convertAmountBetweenCurrencies = convertAmountBetweenCurrencies;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/libs/currency.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAyB;AACzB,wCAAoC;AAE7B,MAAM,8BAA8B,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/libs/currency.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAyB;AACzB,wCAAoC;AAE7B,MAAM,8BAA8B,GAAG,CAAC,YAAoB,EAAE,UAAkB,EAAE,MAAc,EAAE,YAAoB,EAAsB,EAAE;IACnJ,IAAI;QACF,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YACxF,gBAAM,CAAC,KAAK,CAAC,gDAAgD,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;YACnH,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,eAAe,GAAG,IAAA,gBAAG,EAAC,YAAY,CAAC,CAAC;QAC1C,OAAO,IAAA,gBAAG,EAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;KAC/D;IAAC,OAAO,KAAK,EAAE;QACd,gBAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;QACtG,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAA;AAZY,QAAA,8BAA8B,kCAY1C"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Big from 'big.js';
|
|
2
1
|
import { convertAmountBetweenCurrencies } from '../../libs/currency';
|
|
3
2
|
import { Logger } from '../../helpers';
|
|
4
3
|
jest.mock('../../helpers', () => ({
|
|
@@ -12,95 +11,93 @@ describe('convertAmountBetweenCurrencies', () => {
|
|
|
12
11
|
});
|
|
13
12
|
describe('successful conversions', () => {
|
|
14
13
|
it('should convert USD to EUR with exchange rate', () => {
|
|
15
|
-
const amount =
|
|
14
|
+
const amount = 100.00;
|
|
16
15
|
const fromCurrency = 'USD';
|
|
17
16
|
const toCurrency = 'EUR';
|
|
18
17
|
const exchangeRate = 0.85;
|
|
19
|
-
const result = convertAmountBetweenCurrencies(
|
|
18
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
20
19
|
expect(result).toBe(85.00);
|
|
21
20
|
});
|
|
22
21
|
it('should convert EUR to USD with exchange rate', () => {
|
|
23
|
-
const amount =
|
|
22
|
+
const amount = 100.00;
|
|
24
23
|
const fromCurrency = 'EUR';
|
|
25
24
|
const toCurrency = 'USD';
|
|
26
25
|
const exchangeRate = 1.18;
|
|
27
|
-
const result = convertAmountBetweenCurrencies(
|
|
26
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
28
27
|
expect(result).toBe(118.00);
|
|
29
28
|
});
|
|
30
29
|
it('should handle decimal amounts correctly', () => {
|
|
31
|
-
const amount =
|
|
30
|
+
const amount = 123.45;
|
|
32
31
|
const fromCurrency = 'USD';
|
|
33
32
|
const toCurrency = 'EUR';
|
|
34
33
|
const exchangeRate = 0.92;
|
|
35
|
-
const result = convertAmountBetweenCurrencies(
|
|
34
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
36
35
|
expect(result).toBe(113.57);
|
|
37
36
|
});
|
|
38
37
|
it('should round result to 2 decimal places', () => {
|
|
39
|
-
const amount =
|
|
38
|
+
const amount = 100.00;
|
|
40
39
|
const fromCurrency = 'USD';
|
|
41
40
|
const toCurrency = 'EUR';
|
|
42
41
|
const exchangeRate = 0.333333;
|
|
43
|
-
const result = convertAmountBetweenCurrencies(
|
|
42
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
44
43
|
expect(result).toBe(33.33);
|
|
45
44
|
});
|
|
46
45
|
it('should handle zero amount', () => {
|
|
47
|
-
const amount =
|
|
46
|
+
const amount = 0.00;
|
|
48
47
|
const fromCurrency = 'USD';
|
|
49
48
|
const toCurrency = 'EUR';
|
|
50
49
|
const exchangeRate = 0.85;
|
|
51
|
-
const result = convertAmountBetweenCurrencies(
|
|
50
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
52
51
|
expect(result).toBe(0.00);
|
|
53
52
|
});
|
|
54
53
|
it('should handle exchange rate of 1', () => {
|
|
55
|
-
const amount =
|
|
54
|
+
const amount = 100.00;
|
|
56
55
|
const fromCurrency = 'USD';
|
|
57
56
|
const toCurrency = 'USD';
|
|
58
57
|
const exchangeRate = 1.0;
|
|
59
|
-
const result = convertAmountBetweenCurrencies(
|
|
58
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
60
59
|
expect(result).toBe(100.00);
|
|
61
60
|
});
|
|
62
61
|
it('should handle very small amounts', () => {
|
|
63
|
-
const amount =
|
|
62
|
+
const amount = 0.01;
|
|
64
63
|
const fromCurrency = 'USD';
|
|
65
64
|
const toCurrency = 'EUR';
|
|
66
65
|
const exchangeRate = 0.85;
|
|
67
|
-
const result = convertAmountBetweenCurrencies(
|
|
66
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
68
67
|
expect(result).toBe(0.01);
|
|
69
68
|
});
|
|
70
69
|
it('should handle large amounts', () => {
|
|
71
|
-
const amount =
|
|
70
|
+
const amount = 1000000.00;
|
|
72
71
|
const fromCurrency = 'USD';
|
|
73
72
|
const toCurrency = 'EUR';
|
|
74
73
|
const exchangeRate = 0.85;
|
|
75
|
-
const result = convertAmountBetweenCurrencies(
|
|
74
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
76
75
|
expect(result).toBe(850000.00);
|
|
77
76
|
});
|
|
78
77
|
});
|
|
79
78
|
describe('error handling', () => {
|
|
80
|
-
it('should return
|
|
81
|
-
const amount =
|
|
79
|
+
it('should return undefined when exchange rate is invalid', () => {
|
|
80
|
+
const amount = 100.00;
|
|
82
81
|
const fromCurrency = 'USD';
|
|
83
82
|
const toCurrency = 'EUR';
|
|
84
83
|
const exchangeRate = NaN;
|
|
85
|
-
const result = convertAmountBetweenCurrencies(
|
|
86
|
-
expect(result).
|
|
87
|
-
expect(Logger.error).toHaveBeenCalledWith('
|
|
88
|
-
error: expect.any(Error),
|
|
84
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
85
|
+
expect(result).toBeUndefined();
|
|
86
|
+
expect(Logger.error).toHaveBeenCalledWith('Amount and exchange rate must be valid numbers', {
|
|
89
87
|
amount,
|
|
90
88
|
fromCurrency,
|
|
91
89
|
toCurrency,
|
|
92
90
|
exchangeRate: NaN,
|
|
93
91
|
});
|
|
94
92
|
});
|
|
95
|
-
it('should return
|
|
96
|
-
const amount =
|
|
93
|
+
it('should return undefined when exchange rate is Infinity', () => {
|
|
94
|
+
const amount = 100.00;
|
|
97
95
|
const fromCurrency = 'USD';
|
|
98
96
|
const toCurrency = 'EUR';
|
|
99
97
|
const exchangeRate = Infinity;
|
|
100
|
-
const result = convertAmountBetweenCurrencies(
|
|
101
|
-
expect(result).
|
|
102
|
-
expect(Logger.error).toHaveBeenCalledWith('
|
|
103
|
-
error: expect.any(Error),
|
|
98
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
99
|
+
expect(result).toBeUndefined();
|
|
100
|
+
expect(Logger.error).toHaveBeenCalledWith('Amount and exchange rate must be valid numbers', {
|
|
104
101
|
amount,
|
|
105
102
|
fromCurrency,
|
|
106
103
|
toCurrency,
|
|
@@ -110,54 +107,70 @@ describe('convertAmountBetweenCurrencies', () => {
|
|
|
110
107
|
});
|
|
111
108
|
describe('edge cases', () => {
|
|
112
109
|
it('should handle very small exchange rates', () => {
|
|
113
|
-
const amount =
|
|
110
|
+
const amount = 100.00;
|
|
114
111
|
const fromCurrency = 'USD';
|
|
115
112
|
const toCurrency = 'JPY';
|
|
116
113
|
const exchangeRate = 0.001;
|
|
117
|
-
const result = convertAmountBetweenCurrencies(
|
|
114
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
118
115
|
expect(result).toBe(0.10);
|
|
119
116
|
});
|
|
120
117
|
it('should handle very large exchange rates', () => {
|
|
121
|
-
const amount =
|
|
118
|
+
const amount = 1.00;
|
|
122
119
|
const fromCurrency = 'JPY';
|
|
123
120
|
const toCurrency = 'USD';
|
|
124
121
|
const exchangeRate = 1000;
|
|
125
|
-
const result = convertAmountBetweenCurrencies(
|
|
122
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
126
123
|
expect(result).toBe(1000.00);
|
|
127
124
|
});
|
|
128
125
|
it('should handle zero exchange rate', () => {
|
|
129
|
-
const amount =
|
|
126
|
+
const amount = 100.00;
|
|
130
127
|
const fromCurrency = 'USD';
|
|
131
128
|
const toCurrency = 'EUR';
|
|
132
129
|
const exchangeRate = 0;
|
|
133
|
-
const result = convertAmountBetweenCurrencies(
|
|
130
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
134
131
|
expect(result).toBe(0.00);
|
|
135
132
|
});
|
|
136
133
|
it('should handle different currency codes', () => {
|
|
137
|
-
const amount =
|
|
134
|
+
const amount = 50.00;
|
|
138
135
|
const fromCurrency = 'GBP';
|
|
139
136
|
const toCurrency = 'CAD';
|
|
140
137
|
const exchangeRate = 1.75;
|
|
141
|
-
const result = convertAmountBetweenCurrencies(
|
|
138
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
142
139
|
expect(result).toBe(87.50);
|
|
143
140
|
});
|
|
144
141
|
});
|
|
145
142
|
describe('Big.js precision handling', () => {
|
|
146
143
|
it('should handle Big.js precision correctly', () => {
|
|
147
|
-
const amount =
|
|
144
|
+
const amount = '0.333333333333333333';
|
|
148
145
|
const fromCurrency = 'USD';
|
|
149
146
|
const toCurrency = 'EUR';
|
|
150
147
|
const exchangeRate = 0.85;
|
|
151
|
-
const result = convertAmountBetweenCurrencies(
|
|
148
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
152
149
|
expect(result).toBe(0.28);
|
|
153
150
|
});
|
|
154
151
|
it('should handle Big.js with high precision exchange rate', () => {
|
|
155
|
-
const amount =
|
|
152
|
+
const amount = '1931305.25';
|
|
156
153
|
const fromCurrency = 'USD';
|
|
157
154
|
const toCurrency = 'EUR';
|
|
158
|
-
const exchangeRate =
|
|
159
|
-
const result = convertAmountBetweenCurrencies(
|
|
160
|
-
expect(result).toBe(
|
|
155
|
+
const exchangeRate = 1.165772907437631;
|
|
156
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
157
|
+
expect(result).toBe(2251463.34);
|
|
158
|
+
});
|
|
159
|
+
it('should handle Big.js with high precision exchange rate', () => {
|
|
160
|
+
const amount = '6809633.24';
|
|
161
|
+
const fromCurrency = 'CAD';
|
|
162
|
+
const toCurrency = 'USD';
|
|
163
|
+
const exchangeRate = 0.7276431637924762;
|
|
164
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
165
|
+
expect(result).toBe(4954983.08);
|
|
166
|
+
});
|
|
167
|
+
it('should handle Big.js with high precision exchange rate', () => {
|
|
168
|
+
const amount = '81.1723990090352666861';
|
|
169
|
+
const fromCurrency = 'CAD';
|
|
170
|
+
const toCurrency = 'USD';
|
|
171
|
+
const exchangeRate = 0.6520179956966812;
|
|
172
|
+
const result = convertAmountBetweenCurrencies(fromCurrency, toCurrency, amount, exchangeRate);
|
|
173
|
+
expect(result).toBe(52.93);
|
|
161
174
|
});
|
|
162
175
|
});
|
|
163
176
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.spec.js","sourceRoot":"","sources":["../../../../src/__tests__/libs/currency.spec.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"currency.spec.js","sourceRoot":"","sources":["../../../../src/__tests__/libs/currency.spec.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;IAChC,MAAM,EAAE;QACN,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;KACjB;CACF,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,UAAU,CAAC,GAAG,EAAE;QACd,IAAI,CAAC,aAAa,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AAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const convertAmountBetweenCurrencies: (amount: Big, fromCurrency: string, toCurrency: string, exchangeRate: number) => number | null;
|
|
1
|
+
export declare const convertAmountBetweenCurrencies: (fromCurrency: string, toCurrency: string, amount: number, exchangeRate: number) => number | undefined;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import Big from 'big.js';
|
|
2
2
|
import { Logger } from '../helpers';
|
|
3
|
-
export const convertAmountBetweenCurrencies = (
|
|
3
|
+
export const convertAmountBetweenCurrencies = (fromCurrency, toCurrency, amount, exchangeRate) => {
|
|
4
4
|
try {
|
|
5
|
-
if (
|
|
6
|
-
Logger.error('Amount and exchange rate must be numbers', { amount, fromCurrency, toCurrency, exchangeRate });
|
|
7
|
-
return
|
|
5
|
+
if (isNaN(amount) || isNaN(exchangeRate) || !isFinite(amount) || !isFinite(exchangeRate)) {
|
|
6
|
+
Logger.error('Amount and exchange rate must be valid numbers', { amount, fromCurrency, toCurrency, exchangeRate });
|
|
7
|
+
return undefined;
|
|
8
8
|
}
|
|
9
9
|
const exchangeRateBig = Big(exchangeRate);
|
|
10
|
-
return amount.times(exchangeRateBig).round(2).toNumber();
|
|
10
|
+
return Big(amount).times(exchangeRateBig).round(2).toNumber();
|
|
11
11
|
}
|
|
12
12
|
catch (error) {
|
|
13
13
|
Logger.error('Failed to convert currency', { error, amount, fromCurrency, toCurrency, exchangeRate });
|
|
14
|
-
return
|
|
14
|
+
return undefined;
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
//# sourceMappingURL=currency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/libs/currency.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/libs/currency.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAC;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,YAAoB,EAAE,UAAkB,EAAE,MAAc,EAAE,YAAoB,EAAsB,EAAE;IACnJ,IAAI;QACF,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YACxF,MAAM,CAAC,KAAK,CAAC,gDAAgD,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;YACnH,OAAO,SAAS,CAAC;SAClB;QACD,MAAM,eAAe,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC;QAC1C,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;KAC/D;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;QACtG,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAA"}
|