-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeeCalculator.test.js
executable file
·133 lines (119 loc) · 3.24 KB
/
FeeCalculator.test.js
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
const FeeCalculator = require('./FeeCalculator.js');
const configuration = {
cashIn: { percents: 0.03, max: { amount: 5, currency: 'EUR' } },
cashOutNatural: {
percents: 0.3,
week_limit: { amount: 1000, currency: 'EUR' },
},
cashOutJuridical: { percents: 0.3, min: { amount: 0.5, currency: 'EUR' } },
};
const cashInOperations = [
{
date: '2016-01-05',
user_id: 1,
user_type: 'natural',
type: 'cash_in',
operation: { amount: 200.0, currency: 'EUR' },
},
{
date: '2016-01-10',
user_id: 2,
user_type: 'juridical',
type: 'cash_in',
operation: {
amount: 1000000.0,
currency: 'EUR',
},
},
];
const cashOutJuridicalOperations = [
{
date: '2016-01-06',
user_id: 2,
user_type: 'juridical',
type: 'cash_out',
operation: { amount: 300.0, currency: 'EUR' },
},
{
date: '2016-01-06',
user_id: 2,
user_type: 'juridical',
type: 'cash_out',
operation: { amount: 100.0, currency: 'EUR' },
},
];
// same week cashouts
const cashOutNaturalSame = [
{
date: '2016-01-10',
user_id: 1,
user_type: 'natural',
type: 'cash_out',
operation: {
amount: 1000.0,
currency: 'EUR',
},
},
{
date: '2016-01-07',
user_id: 1,
user_type: 'natural',
type: 'cash_out',
operation: { amount: 100.0, currency: 'EUR' },
},
];
// different week cashouts (sunday and monday)
const cashOutNaturalDifferent = [
{
date: '2016-01-10',
user_id: 1,
user_type: 'natural',
type: 'cash_out',
operation: {
amount: 1000.0,
currency: 'EUR',
},
},
{
date: '2016-01-11',
user_id: 1,
user_type: 'natural',
type: 'cash_out',
operation: { amount: 100.0, currency: 'EUR' },
},
];
describe('Fee Calculator', () => {
let commissionFees;
beforeEach(() => {
commissionFees = new FeeCalculator(configuration);
});
describe('cash ins', () => {
test('for cash in 200 should return 0.06', () => {
expect(commissionFees.getFee(cashInOperations[0])).toBe('0.06');
});
test('for cash in 1000000 should return 5.00 (max fee)', () => {
expect(commissionFees.getFee(cashInOperations[1])).toBe('5.00');
});
});
describe('juridical cash outs', () => {
test('for juridical cash out 300 should return 0.90', () => {
expect(commissionFees.getFee(cashOutJuridicalOperations[0])).toBe('0.90');
});
test('for juridical cash out 100 should return 0.50 (min fee)', () => {
expect(commissionFees.getFee(cashOutJuridicalOperations[1])).toBe('0.50');
});
});
describe('natural cash outs', () => {
test('same week first cashout of 1000 (week limit) should return 0.00, second should return 0.03', () => {
expect(commissionFees.getAllFees(cashOutNaturalSame)).toEqual(['0.00', '0.30']);
});
test('different week cashouts not exceeding 1000 both should return 0.00', () => {
expect(commissionFees.getAllFees(cashOutNaturalDifferent)).toEqual(['0.00', '0.00']);
});
test('first weekly cashOut of 1200 (over 1000), should return 0.60', () => {
const singleCashOut = { ...cashOutNaturalSame[0] };
singleCashOut.operation.amount = 1200;
expect(commissionFees.getFee(singleCashOut)).toBe('0.60');
});
});
});