|
|
|
@ -20,7 +20,7 @@ describe('TransactionController Unit Tests', () => { |
|
|
|
|
Promise.reject(new Error('DatabaseNotReachable')), |
|
|
|
|
), |
|
|
|
|
findByClientIdWithinActualMonth: jest.fn((clientId) => { |
|
|
|
|
if (clientId === 42) { |
|
|
|
|
if (clientId === 42 || clientId === 99) { |
|
|
|
|
return [{ base_amount: 1500 }]; |
|
|
|
|
} |
|
|
|
|
return []; |
|
|
|
@ -70,19 +70,95 @@ describe('TransactionController Unit Tests', () => { |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('calling applyRules method minimum result of applied rules should be got', async () => { |
|
|
|
|
const mockTransactionInput = { |
|
|
|
|
date: '2021-01-05', |
|
|
|
|
base_amount: 1000.0, |
|
|
|
|
currency: 'EUR', |
|
|
|
|
{ |
|
|
|
|
const result = await transactionController.applyRules( |
|
|
|
|
[ |
|
|
|
|
transactionController.discountRule, |
|
|
|
|
transactionController.turnoverRule, |
|
|
|
|
], |
|
|
|
|
{ |
|
|
|
|
base_amount: 1000, |
|
|
|
|
client_id: 1, |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(result).to.eql(5); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
const result = await transactionController.applyRules( |
|
|
|
|
[transactionController.discountRule, transactionController.turnoverRule], |
|
|
|
|
mockTransactionInput, |
|
|
|
|
[ |
|
|
|
|
transactionController.discountRule, |
|
|
|
|
transactionController.turnoverRule, |
|
|
|
|
], |
|
|
|
|
{ |
|
|
|
|
base_amount: 1, |
|
|
|
|
client_id: 1, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(result).to.eql(5); |
|
|
|
|
expect(result).to.eql(0.05); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
const result = await transactionController.applyRules( |
|
|
|
|
[ |
|
|
|
|
transactionController.discountRule, |
|
|
|
|
transactionController.turnoverRule, |
|
|
|
|
], |
|
|
|
|
{ |
|
|
|
|
base_amount: 1000, |
|
|
|
|
client_id: 42, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(result).to.eql(0.03); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
const result = await transactionController.applyRules( |
|
|
|
|
[ |
|
|
|
|
transactionController.discountRule, |
|
|
|
|
transactionController.turnoverRule, |
|
|
|
|
], |
|
|
|
|
{ |
|
|
|
|
base_amount: 1, |
|
|
|
|
client_id: 42, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(result).to.eql(0.03); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
const result = await transactionController.applyRules( |
|
|
|
|
[ |
|
|
|
|
transactionController.discountRule, |
|
|
|
|
transactionController.turnoverRule, |
|
|
|
|
], |
|
|
|
|
{ |
|
|
|
|
base_amount: 1000, |
|
|
|
|
client_id: 99, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(result).to.eql(0.03); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
const result = await transactionController.applyRules( |
|
|
|
|
[ |
|
|
|
|
transactionController.discountRule, |
|
|
|
|
transactionController.turnoverRule, |
|
|
|
|
], |
|
|
|
|
{ |
|
|
|
|
base_amount: 1, |
|
|
|
|
client_id: 99, |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
expect(result).to.eql(0.03); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('calling commission method correct commission should be got', async () => { |
|
|
|
|