Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created March 15, 2019 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/30e7f8e52def0aa485246de30e20ff20 to your computer and use it in GitHub Desktop.
Save jasongorman/30e7f8e52def0aa485246de30e20ff20 to your computer and use it in GitHub Desktop.
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