feat: implemented tests checking rules precedence (closes #13)

pull/18/head
Inga 🏳‍🌈 10 months ago
parent bb14f3238e
commit 108a7cce47
  1. 94
      src/transaction/transaction.controller.spec.ts

@ -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 () => {

Loading…
Cancel
Save