Account with Tests
Create a new repo on your github account. A possible name might be “account-tests”
Using git bash navigate to the /c/work folder
Clone this project down using this command
git clone https://livingwater@bitbucket.org/living-water-js/mocha-test-acc.git
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)In Visual Studio Code open the folder mocha-test-acc
Under the test folder open the file below account-test.js
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
Write a new test that verifies the behaviour of the credit method
Task - modify the Account class (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
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)
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
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