Account with Tests

  1. Create a new repo on your github account. A possible name might be “account-tests”

  2. Using git bash navigate to the /c/work folder

  3. Clone this project down using this command git clone https://livingwater@bitbucket.org/living-water-js/mocha-test-acc.git

  4. Change the remote location to your repo using the command git remote set-url origin <remote_url> (where <remote_url> is the url of your new repo)

  5. In Visual Studio Code open the folder mocha-test-acc

  6. Under the test folder open the file below account-test.js

  7. Study the class Account and the test, then perform the tasks below

account-test.js

var assert = require("assert"); class BankAccount { constructor(amount) { this.balance = amount; } debit( amt ) { this.balance -= amt; return this.balance; } credit( amt ) { this.balance += amt; return this.balance; } queryBalance() { return this.balance; } } describe('Is object constructed properly', function() { it('Balance should be same as init value', function() { // arrange... var cut = new BankAccount(50); var expectedResult = 50; // act... var actualResult = cut.queryBalance(); // assert... assert.strictEqual(actualResult, expectedResult); assert.strictEqual(cut.queryBalance(), expectedResult); }); }); describe('Is object debited properly', function() { it('Balance should be reduced', function() { // arrange... var cut = new BankAccount(50); var expectedResult = 20; var debitAmount = 30; // act... var actualResult = cut.debit(debitAmount); // assert... assert.strictEqual(actualResult, expectedResult); assert.strictEqual(cut.queryBalance(), expectedResult); }); });

Task - credit behaviour

  1. Write a new test that verifies the behaviour of the credit method

Task - modify the Account class (1)

  1. modify the debit method so that you cannot go overdrawn. If the amount to debit to is larger than the balance, the balance should not be modified

  2. write a test to support your code, do NOT modify the original test that was given above, write a new test specifically targeting this new requirement

Task - modify the Account class (2)

  1. modify the debit method so that if the amount to debit is greater than 20 a charge of 1 should be added to amount debited from the account i.e. debit amount is 23, the amount debited should be 24

  2. write a test to support your code, do NOT modify the original test that was given above, write a new test specifically targeting this new requirement