-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts
207 lines (152 loc) · 5.6 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import test from "ava";
import zeroDecimalCurrencies, { display } from "./src/index";
test("Real case", (t) => {
const zeroDecimal = zeroDecimalCurrencies(175459.09, "JPY");
t.is(zeroDecimal, "175459");
t.pass();
});
test("Test with zero decimal currency", (t) => {
const zeroDecimal = zeroDecimalCurrencies(1003.01, "JPY");
t.is(zeroDecimal, "1003");
t.pass();
});
test("Test with zero decimal currency 2", (t) => {
const zeroDecimal = zeroDecimalCurrencies(99, "JPY");
t.is(zeroDecimal, "99");
t.pass();
});
test("Test with zero decimal currency 3", (t) => {
const zeroDecimal = zeroDecimalCurrencies(100.0000000052, "JPY");
t.is(zeroDecimal, "100");
t.pass();
});
test("Test with zero decimal currency and display option", (t) => {
const zeroDecimal = zeroDecimalCurrencies(100.0000000052, "JPY", true);
t.is(zeroDecimal, "100");
t.pass();
});
test("Test with zero decimal currency and no rounding up", (t) => {
const zeroDecimal = zeroDecimalCurrencies(100.5100000052, "JPY", false, true);
t.is(zeroDecimal, "100");
t.pass();
});
test("Test with zero decimal currency and rounding up", (t) => {
const zeroDecimal = zeroDecimalCurrencies(100.5100000052, "JPY", false);
t.is(zeroDecimal, "101");
t.pass();
});
test("Test with zero decimal currency and display option rounding up", (t) => {
const zeroDecimal = zeroDecimalCurrencies(100.5100000052, "JPY", true);
t.is(zeroDecimal, "101");
t.pass();
});
test("Test with no zero decimal currency", (t) => {
const zeroDecimal = zeroDecimalCurrencies(1003.01, "EUR");
t.is(zeroDecimal, "100301");
t.pass();
});
test("Test with no zero decimal currency no round", (t) => {
const zeroDecimal = zeroDecimalCurrencies(15.7784514, "EUR", false, true);
t.is(zeroDecimal, "1577");
t.pass();
});
test("Test with no zero decimal currency no round and display to customer", (t) => {
const zeroDecimal = zeroDecimalCurrencies(15.7784514, "EUR", true, true);
t.is(zeroDecimal, "15.77");
t.pass();
});
test("Test with no zero decimal currency with round", (t) => {
const zeroDecimal = zeroDecimalCurrencies(15.7784514, "EUR");
t.is(zeroDecimal, "1578");
t.pass();
});
test("Test with no zero decimal currency with roundand display to customer", (t) => {
const zeroDecimal = zeroDecimalCurrencies(15.7784514, "EUR", true);
t.is(zeroDecimal, "15.78");
t.pass();
});
test("Test with no zero decimal currency cientific notation long number no round", (t) => {
const zeroDecimal = zeroDecimalCurrencies(0.0000000052, "EUR");
t.is(zeroDecimal, "0");
t.pass();
});
test("Test with no zero decimal currency cientific notation long number no round and display to customer", (t) => {
const zeroDecimal = zeroDecimalCurrencies(0.0000000052, "EUR", true);
t.is(zeroDecimal, "0.00");
t.pass();
});
test("Test with no zero decimal currency cientific notation long number no round 2", (t) => {
const zeroDecimal = zeroDecimalCurrencies(1.0000000052, "EUR");
t.is(zeroDecimal, "100");
t.pass();
});
test("Test with no zero decimal currency cientific notation long number no round 3", (t) => {
const zeroDecimal = zeroDecimalCurrencies(14.1000000052, "EUR");
t.is(zeroDecimal, "1410");
t.pass();
});
test("Test display with no zero decimal currency", (t) => {
const zeroDecimal = zeroDecimalCurrencies(14.1000000052, "EUR");
const disp = display(zeroDecimal, "EUR");
t.is(disp, "14.10");
t.pass();
});
test("Test display with zero decimal currency", (t) => {
const zeroDecimal = zeroDecimalCurrencies(100.5100000052, "JPY");
const disp = display(zeroDecimal, "JPY");
t.is(disp, "101");
t.pass();
});
//for stripe, the least significant number needs to be zero for
//compatibilities
test("Test with three decimal currency", (t) => {
const zeroDecimal = zeroDecimalCurrencies(1003.01, "IQD");
t.is(zeroDecimal, "1003010");
t.pass();
});
test("Test with three decimal currency no round", (t) => {
const zeroDecimal = zeroDecimalCurrencies(15.7784514, "IQD", false, true);
t.is(zeroDecimal, "15770");
t.pass();
});
test("Test with three decimal currency no round and display to customer", (t) => {
const zeroDecimal = zeroDecimalCurrencies(15.7784514, "IQD", true, true);
t.is(zeroDecimal, "15.778");
t.pass();
});
test("Test with three decimal currency with round", (t) => {
const zeroDecimal = zeroDecimalCurrencies(15.7784514, "IQD");
t.is(zeroDecimal, "15780");
t.pass();
});
test("Test with three decimal currency with roundand display to customer", (t) => {
const zeroDecimal = zeroDecimalCurrencies(15.7784514, "IQD", true);
t.is(zeroDecimal, "15.778");
t.pass();
});
test("Test with three decimal currency cientific notation long number no round", (t) => {
const zeroDecimal = zeroDecimalCurrencies(0.0000000052, "IQD");
t.is(zeroDecimal, "0");
t.pass();
});
test("Test with three decimal currency cientific notation long number no round and display to customer", (t) => {
const zeroDecimal = zeroDecimalCurrencies(0.0000000052, "IQD", true);
t.is(zeroDecimal, "0.000");
t.pass();
});
test("Test with three decimal currency cientific notation long number no round 2", (t) => {
const zeroDecimal = zeroDecimalCurrencies(1.0000000052, "IQD");
t.is(zeroDecimal, "1000");
t.pass();
});
test("Test with three decimal currency cientific notation long number no round 3", (t) => {
const zeroDecimal = zeroDecimalCurrencies(14.1000000052, "IQD");
t.is(zeroDecimal, "14100");
t.pass();
});
test("Test display with three decimal currency", (t) => {
const zeroDecimal = zeroDecimalCurrencies(14.1000000052, "IQD");
const disp = display(zeroDecimal, "IQD");
t.is(disp, "14.100");
t.pass();
});