diff --git a/src/transaction/transaction.controller.spec.ts b/src/transaction/transaction.controller.spec.ts index a8bf324..3fb3aa1 100644 --- a/src/transaction/transaction.controller.spec.ts +++ b/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', - client_id: 1, - }; + { + const result = await transactionController.applyRules( + [ + transactionController.discountRule, + transactionController.turnoverRule, + ], + { + base_amount: 1000, + client_id: 1, + }, + ); - const result = await transactionController.applyRules( - [transactionController.discountRule, transactionController.turnoverRule], - mockTransactionInput, - ); + expect(result).to.eql(5); + } + + { + const result = await transactionController.applyRules( + [ + transactionController.discountRule, + transactionController.turnoverRule, + ], + { + base_amount: 1, + client_id: 1, + }, + ); + + 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(5); + expect(result).to.eql(0.03); + } }); it('calling commission method correct commission should be got', async () => {