From 2f66c5a9623133cdad766cd658e8d16522fba98e Mon Sep 17 00:00:00 2001 From: Chidi Orji Date: Tue, 21 May 2019 21:54:30 +0100 Subject: [PATCH] chore(UI js): improve code coverage - configure codeclimate reporting --- .travis.yml | 2 +- UI/js/loan.js | 31 +++++++++++++++---------------- UI/js/user.js | 35 +++++++++++++++++------------------ package.json | 2 +- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index fbfd6f9..e6a0cf7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ before_script: - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build after_script: - - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT + - ./cc-test-reporter after-build -t lcov --exit-code $TRAVIS_TEST_RESULT before_install: - sudo sed -i -e '/local.*peer/s/postgres/all/' -e 's/peer\|md5/trust/g' /etc/postgresql/*/main/pg_hba.conf - sudo service postgresql restart diff --git a/UI/js/loan.js b/UI/js/loan.js index 1daba60..b22451f 100644 --- a/UI/js/loan.js +++ b/UI/js/loan.js @@ -5,31 +5,30 @@ const reject_loan_application = document.getElementById( 'reject_loan_application' ); -approve_loan_application.addEventListener('click', e => { - e.preventDefault(); - const cont = prompt( - 'Confirm loan approval', - 'Click okay to approve this loan request'); - +const promptUser = (text, defaultText, msg) => { + const cont = prompt(text, defaultText); if (cont !== null) { - alert('Loan application was approved'); - // send email notification + alert(msg); } +}; +approve_loan_application.addEventListener('click', e => { + e.preventDefault(); + promptUser( + 'Confirm loan approval', + 'Click okay to approve this loan request', + 'Loan application was approved' + ); return; }); reject_loan_application.addEventListener('click', e => { e.preventDefault(); - const cont = prompt( + promptUser( 'Confirm loan rejection', - 'Click okay to reject this loan request'); - - if (cont !== null) { - alert('Loan application was rejected'); - // send email notification - } - + 'Click okay to reject this loan request', + 'Loan application was rejected' + ); return; }); diff --git a/UI/js/user.js b/UI/js/user.js index c205f29..8b0794f 100644 --- a/UI/js/user.js +++ b/UI/js/user.js @@ -1,32 +1,31 @@ const verify_user = document.getElementById('verify_user'); const un_verify_user = document.getElementById('un_verify_user'); -verify_user.addEventListener('click', e => { - e.preventDefault(); - const cont = prompt( - 'Please confirm if you want to verify this user', - 'Click okay to reject this loan request'); - +const promptUser = (text, defaultText, msg) => { + const cont = prompt(text, defaultText); if (cont !== null) { - // verify user - alert('User was verified.'); - // Send email notification + alert(msg); } +}; +verify_user.addEventListener('click', e => { + e.preventDefault(); + + promptUser( + 'Confirm user verification', + 'Click okay to verify this user', + 'User was verified.' + ); return; }); un_verify_user.addEventListener('click', e => { e.preventDefault(); - const cont = prompt( - "Please confirm if you want to verify revoke this user's verification", - "Click okay to revoke this user's verification"); - - if (cont !== null) { - // revoke verification - alert("User's verification was revoked."); - // Send email notification - } + promptUser( + 'Confirm revoking user verification', + "Click okay to revoke this user's verification", + "User's verification was revoked." + ); return; }); diff --git a/package.json b/package.json index 895109b..42b6558 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "lint": "./node_modules/.bin/eslint ./", "test": "set NODE_ENV=test&set DEBUG=test&set DBNAME=testdb&nyc --reporter=html --reporter=text mocha -r @babel/register -r should", "cover": "nyc report --reporter=text-lcov | coveralls", - "coverage": "nyc report --reporter=text-lcov | coveralls && rm -rf ./.nyc_output && rm -rf coverage/" + "coverage": "nyc report --reporter=text-lcov | coveralls && rm -rf ./.nyc_output" }, "bugs": { "url": "https://github.com/chidimo/Quick-Credit/issues"