SHARE
TWEET

Untitled

a guest Mar 20th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const {credit, debit} = require("../../src/liskov_substitution/bank_account");
  2.  
  3. const bankAccountTest = (account, credit, debit) => {
  4.  
  5.     it('credit account', () => {
  6.         const credited = credit({...account, balance: 0}, 50);
  7.         expect(credited.balance).toBe(50);
  8.     })
  9.  
  10.     it('debit account with sufficient funds', () => {
  11.         const debited = debit({...account, balance: 50}, 50);
  12.         expect(debited.balance).toBe(0);
  13.     })
  14.  
  15.     it('debit account with insufficient funds', () => {
  16.         expect(() => debit({...account, balance: 50}, 51)).toThrow('Insufficient funds error');
  17.     })
  18. }
  19.  
  20. describe("bank account", () => {
  21.     const {credit, debit} = require("../../src/liskov_substitution/bank_account");
  22.     const account = {id: 1, balance: 0};
  23.     bankAccountTest(account, credit, debit);
  24. })
  25.  
  26. describe("bank account with overdraft facility", () => {
  27.     const overdraft_debit = require("../../src/liskov_substitution/overdraft_account");
  28.     const overdraft_account = {id: 1, balance: 0, limit: 1000};
  29.     bankAccountTest(overdraft_account, credit, overdraft_debit);
  30. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top