This is a Command Line Interface (CLI) program to simulate an interaction of an ATM with a user.
This project is developed with:
- Node 18
login [name]
- Log in the customer and create the customer if not existdeposit [amount]
- Deposit this amount to the logged in customerwithdraw [amount]
- Withdraw this amount from the logged in customertransfer [target] [amount]
- Transfer this amount from the logged in customer to the target customerlogout
- Log out the logged in customer
- Login a user.
- If there's an active session in
session.json
, throw an error if user tries to login. - Create the user if the user does not exist in
accounts.json
.
- Logout the current active session.
- Make a deposit for the current active session.
- Throw an error if the amount is not a number.
- Throw an error if the current active session is empty.
- Throw an error if the account does not exist. (For some reason after you login, the account data is missing in the database).
- Make a transfer from the current active session to the destination account.
- Throw an error if the amount is not a number.
- Throw an error if the current active session is empty.
- Throw an error if the original account does not exist (For some reason after you login, the original account is missing in the database).
- Throw an error if the destination account does not exist (If the destination account is missing in the database).
- Throw an error if the destination account is the same with the current session (You cannot transfer to yourself).
- Make a withdrawal for the current active session.
- Throw an error if the amount is not a number.
- Throw an error if the current active session is empty.
- Throw an error if the account does not exist. (For some reason after you login, the account data is lost in the database).
$ node app login Alice
Hello Alice. Your balance is $0.
$ node app deposit 200
Your balance is $200
$ node app withdraw 100
You withdraw $100. Your balance is $100
$ node app login Bob
Error: Account Alice is currently logged in.
$ node app logout
Goodbye, Alice
$ node app login Bob
Hello Bob. Your balance is $0.
$ node app deposit 200
Your balance is $200
$ node app transfer Alice 50
Transferred $50 to Alice. Your balance is $150
$ node app transfer Alice 1000
Error: Your account has not enough balance.
$ node app logout
Goodbye, Bob
$ node app login Alice
Hello Alice. Your balance is $150.
$ node app transfer Alice 100
Error: You cannot transfer to yourself.
$ node app transfer Bob 100
Transferred $100 to Bob. Your balance is $50
$ node app logout
Goodbye, Alice
We're simulating bank account data in the file accounts.json
. For the session, session.json
. When running the test, we're using accounts_test.json
and session_test.json
instead.
To test the service, run
npm test
Example:
$ npm test
> [email protected] test
> NODE_ENV=test mocha --timeout 10000 --exit './test/**/*.test.js'
Service Unit Test
✔ login
✔ throws an error when logging in with existing session still active
✔ logout
✔ deposit
✔ throws an error when making a deposit without login
✔ throws an error when making a deposit with an invalid amount
✔ transfer
✔ throws an error when making a transfer without login
✔ throws an error when making a transfer with an invalid amount
✔ throws an error when making a transfer to the same account
✔ withdraw
✔ throws an error when making a withdrawal without login
✔ throws an error when making a withdrawal with an invalid amount
Test isNumber
✔ number: 123 should be true
✔ string: 'abc' should be false
✔ string numeric: '123' should be false
✔ boolean: true should be false
✔ boolean: false should be false
✔ array should be false
✔ object should be false
✔ NaN should be false
✔ null should be false
✔ undefined should be false
Test moneyFormatter
✔ zero
✔ positive number
✔ negative number
✔ string to throw error
✔ array to throw error
✔ object to throw error
✔ null to throw error
✔ undefined to throw error
31 passing (43ms)