Created
March 15, 2019 09:35
-
-
Save jasongorman/30e7f8e52def0aa485246de30e20ff20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {credit, debit} = require("../../src/liskov_substitution/bank_account"); | |
const bankAccountTest = (account, credit, debit) => { | |
it('credit account', () => { | |
const credited = credit({...account, balance: 0}, 50); | |
expect(credited.balance).toBe(50); | |
}) | |
it('debit account with sufficient funds', () => { | |
const debited = debit({...account, balance: 50}, 50); | |
expect(debited.balance).toBe(0); | |
}) | |
it('debit account with insufficient funds', () => { | |
expect(() => debit({...account, balance: 50}, 51)).toThrow('Insufficient funds error'); | |
}) | |
} | |
describe("bank account", () => { | |
const {credit, debit} = require("../../src/liskov_substitution/bank_account"); | |
const account = {id: 1, balance: 0}; | |
bankAccountTest(account, credit, debit); | |
}) | |
describe("bank account with overdraft facility", () => { | |
const overdraft_debit = require("../../src/liskov_substitution/overdraft_account"); | |
const overdraft_account = {id: 1, balance: 0, limit: 1000}; | |
bankAccountTest(overdraft_account, credit, overdraft_debit); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment