From 27998c3a51a5f8dd0db3f8bd27dd028f0173afb5 Mon Sep 17 00:00:00 2001 From: ipaullly Date: Fri, 25 Jan 2019 16:34:01 +0300 Subject: [PATCH 01/27] remove typo in landing page text --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 8608223..0e9a579 100644 --- a/index.html +++ b/index.html @@ -27,7 +27,7 @@

Send-IT

Welcome to Send-IT

-

Conviniently place an order with the relevant details. We strive to ensure that your package arrives to the destination with haste.

+

Conveniently place an order with the relevant details. We strive to ensure that your package arrives to the destination with haste.

From 9762c84054f504b16400229c2cae4b0a65bad9f2 Mon Sep 17 00:00:00 2001 From: ipaullly Date: Fri, 25 Jan 2019 16:43:41 +0300 Subject: [PATCH 02/27] make the README.md more descriptive --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5f9f5ce..3ee50e8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ [![Build Status](https://travis-ci.com/ipaullly/sendIT.svg?branch=ch-test-user-interactions-163458249)](https://travis-ci.com/ipaullly/sendIT) This is an app that allows users to create accounts and make delivery orders. The front-end was built using vanilla javaScript and consumed endpoints built with python/flask. - +The app is live on the github-pages [link](https://ipaullly.github.io/sendIT/index.html) for this repo. + ## Installation Clone the repository to your local machine ``` @@ -31,7 +32,10 @@ npm start ## Testing Tests run using **jest** and **puppeteer**. run the following command within the project folder to see the test coverage -> npm test +``` +npm test +``` +Alternatively view the [Travis-CI](https://travis-ci.com/ipaullly/sendIT) build report to view coverage. ## App features - [ ] Users can create an account and log in. @@ -41,10 +45,6 @@ Tests run using **jest** and **puppeteer**. run the following command within the - [ ] Users can see the details of a delivery order. - [ ] Admin can change the **status** and **Current-location** of a parcel delivery order. -## User Interface -The interface is available at -> [Welcome Page](https://ipaullly.github.io/sendIT/index.html) - ## Built Using 1.HTML 2.CSS From ff3363bf693ed5e262457f4e093d509e0372b02c Mon Sep 17 00:00:00 2001 From: ipaullly Date: Fri, 25 Jan 2019 16:53:09 +0300 Subject: [PATCH 03/27] remove redundant files from project folder --- .gitignore | 3 ++- config.json | 11 ----------- 2 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 config.json diff --git a/.gitignore b/.gitignore index c929f1a..440ee22 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ app/ .env node_modules/ npm-debug.log -coverage/ \ No newline at end of file +coverage/ +build/ \ No newline at end of file diff --git a/config.json b/config.json deleted file mode 100644 index b6088ac..0000000 --- a/config.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "testMatch": ["/tests/unit/*.js"], - "setupFiles": ["/tests/setup.js"], - "transform": {".*": "/node_modules/babel-jest"}, - "moduleFileExtensions": ["js"], - "collectCoverageFrom": [ - "src/*.js", - "!src/main.js" - ] - } - \ No newline at end of file From 368edc1cfd84e0123f27c3c3615a24a9a14e0c3e Mon Sep 17 00:00:00 2001 From: ipaullly Date: Fri, 25 Jan 2019 16:54:21 +0300 Subject: [PATCH 04/27] remove redundant build folder --- .gitignore | 1 - build/main.bundle.js | 20 -------------------- 2 files changed, 21 deletions(-) delete mode 100644 build/main.bundle.js diff --git a/.gitignore b/.gitignore index 440ee22..f89f94b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,3 @@ app/ node_modules/ npm-debug.log coverage/ -build/ \ No newline at end of file diff --git a/build/main.bundle.js b/build/main.bundle.js deleted file mode 100644 index 051e6fd..0000000 --- a/build/main.bundle.js +++ /dev/null @@ -1,20 +0,0 @@ -'use strict'; - -document.getElementById('signupbutton').addEventListener('click', signUp); - -function signUp() { - var email = document.getElementById('signemail').nodeValue; - var password = document.getElementById('signpassword').nodeValue; - - fetch('https://sendit-versiontwo.herokuapp.com/auth/v2/signup', { - method: 'POST', - headers: { - 'Content-type': 'application/json' - }, - body: JSON.stringify({ email: email, password: password }) - }).then(function (res) { - return res.json(); - }).then(function (data) { - return console.log(data); - }); -} From 93e1b9e8539b09fffd67e6aaccd598cbae7eadff Mon Sep 17 00:00:00 2001 From: ipaullly Date: Thu, 31 Jan 2019 12:37:55 +0300 Subject: [PATCH 05/27] integrate codacy to repo --- .travis.yml | 2 +- README.md | 5 +++-- order_display_page.html | 2 +- package.json | 6 +++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e1c23a8..c23ae34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ cache: - "node_modules" script: - npm start & -- npm test +- npm run test-with-coverage --token services: - http-server diff --git a/README.md b/README.md index 3ee50e8..dd48970 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ -# Send-IT -[![Build Status](https://travis-ci.com/ipaullly/sendIT.svg?branch=ch-test-user-interactions-163458249)](https://travis-ci.com/ipaullly/sendIT) +# Send-IT +[![Build Status](https://travis-ci.com/ipaullly/sendIT.svg?branch=ch-test-user-interactions-163458249)](https://travis-ci.com/ipaullly/sendIT)[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d5026cb302e349d7b08580df620e7ecd)](https://www.codacy.com/app/ipaullly/sendIT?utm_source=github.com&utm_medium=referral&utm_content=ipaullly/sendIT&utm_campaign=Badge_Grade) +The project was done while participating in the Andela Developer Challenge simulated sprint of the application bootcamp. This is an app that allows users to create accounts and make delivery orders. The front-end was built using vanilla javaScript and consumed endpoints built with python/flask. The app is live on the github-pages [link](https://ipaullly.github.io/sendIT/index.html) for this repo. diff --git a/order_display_page.html b/order_display_page.html index f4b18a3..671faea 100644 --- a/order_display_page.html +++ b/order_display_page.html @@ -48,7 +48,7 @@

Order

  • -

    Enter Order ID and Click 'Search' to display information on single order.

    +

    Enter Order ID and Click 'Search' to display information on single order.

    Parcel Name

    Order id: Parcel ID

    Sent from: Pickup Location

    diff --git a/package.json b/package.json index 4acf731..54faa27 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "babel": "babel --presets es2015 js/main.js -o build/main.bundle.js", "start": "http-server", - "test": "jest" + "test": "jest", + "test-with-coverage": "jest --coverage && cat ./coverage/lcov.info | codacy-coverage" }, "repository": { "type": "git", @@ -29,5 +30,8 @@ "http-server": "^0.11.1", "jest": "^23.6.0", "puppeteer": "^1.11.0" + }, + "dependencies": { + "codacy-coverage": "^3.4.0" } } From a1050777c1ff595f28aa7772d0d2e11c45d81d75 Mon Sep 17 00:00:00 2001 From: ipaullly Date: Thu, 31 Jan 2019 12:53:56 +0300 Subject: [PATCH 06/27] edit codacy badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd48970..019a38e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Send-IT -[![Build Status](https://travis-ci.com/ipaullly/sendIT.svg?branch=ch-test-user-interactions-163458249)](https://travis-ci.com/ipaullly/sendIT)[![Codacy Badge](https://api.codacy.com/project/badge/Grade/d5026cb302e349d7b08580df620e7ecd)](https://www.codacy.com/app/ipaullly/sendIT?utm_source=github.com&utm_medium=referral&utm_content=ipaullly/sendIT&utm_campaign=Badge_Grade) +[![Build Status](https://travis-ci.com/ipaullly/sendIT.svg?branch=ch-test-user-interactions-163458249)](https://travis-ci.com/ipaullly/sendIT) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d5026cb302e349d7b08580df620e7ecd)](https://www.codacy.com/app/ipaullly/sendIT?utm_source=github.com&utm_medium=referral&utm_content=ipaullly/sendIT&utm_campaign=Badge_Grade) The project was done while participating in the Andela Developer Challenge simulated sprint of the application bootcamp. This is an app that allows users to create accounts and make delivery orders. The front-end was built using vanilla javaScript and consumed endpoints built with python/flask. From 8edf227886164b207a507fc9c05bb1ba3e79b70b Mon Sep 17 00:00:00 2001 From: ipaullly Date: Thu, 31 Jan 2019 13:33:58 +0300 Subject: [PATCH 07/27] debug travis.yml --- .travis.yml | 4 +++- package.json | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c23ae34..569adb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,9 @@ cache: - "node_modules" script: - npm start & -- npm run test-with-coverage --token +- npm test +after_script: +- npm run test-with-coverage services: - http-server diff --git a/package.json b/package.json index 54faa27..cfdf4d8 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "scripts": { "babel": "babel --presets es2015 js/main.js -o build/main.bundle.js", "start": "http-server", - "test": "jest", - "test-with-coverage": "jest --coverage && cat ./coverage/lcov.info | codacy-coverage" + "test": "jest --coverage", + "test-with-coverage": "cat ./coverage/lcov.info | codacy-coverage --accountToken 5T5GEx9t2TIWXVXOdeUc --username Morogo --projectName sendIT" }, "repository": { "type": "git", From 7ac9589df0d4f4661993261ce03fc36215e04fb9 Mon Sep 17 00:00:00 2001 From: ipaullly Date: Wed, 20 Feb 2019 23:00:47 +0300 Subject: [PATCH 08/27] [starts #164121365] improve javascript in tandem with issues raised by codacy --- README.md | 22 ++-- js/main.js | 234 ++++++++++++++++++------------------ order_display_page.html | 10 +- package.json | 3 +- test/index.spec.js | 260 ++++++++++++++++++++++------------------ 5 files changed, 273 insertions(+), 256 deletions(-) diff --git a/README.md b/README.md index 019a38e..03905f8 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -# Send-IT +#Send-IT [![Build Status](https://travis-ci.com/ipaullly/sendIT.svg?branch=ch-test-user-interactions-163458249)](https://travis-ci.com/ipaullly/sendIT) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d5026cb302e349d7b08580df620e7ecd)](https://www.codacy.com/app/ipaullly/sendIT?utm_source=github.com&utm_medium=referral&utm_content=ipaullly/sendIT&utm_campaign=Badge_Grade) The project was done while participating in the Andela Developer Challenge simulated sprint of the application bootcamp. This is an app that allows users to create accounts and make delivery orders. The front-end was built using vanilla javaScript and consumed endpoints built with python/flask. The app is live on the github-pages [link](https://ipaullly.github.io/sendIT/index.html) for this repo. -## Installation +#Installation Clone the repository to your local machine ``` git clone https://github.com/ipaullly/sendIT.git @@ -31,22 +31,22 @@ To run the project on your local server npm start ``` -## Testing +#Testing Tests run using **jest** and **puppeteer**. run the following command within the project folder to see the test coverage ``` npm test ``` Alternatively view the [Travis-CI](https://travis-ci.com/ipaullly/sendIT) build report to view coverage. -## App features -- [ ] Users can create an account and log in. -- [ ] Users can create a parcel delivery order. -- [ ] Users can change the destination of a parcel delivery order. -- [ ] Users can cancel parcel delivery order. -- [ ] Users can see the details of a delivery order. -- [ ] Admin can change the **status** and **Current-location** of a parcel delivery order. +#App features + - [ ] Users can create an account and log in. + - [ ] Users can create a parcel delivery order. + - [ ] Users can change the destination of a parcel delivery order. + - [ ] Users can cancel parcel delivery order. + - [ ] Users can see the details of a delivery order. + - [ ] Admin can change the **status** and **Current-location** of a parcel delivery order. -## Built Using +#Built Using 1.HTML 2.CSS 3.JAVASCRIPT diff --git a/js/main.js b/js/main.js index 5c57651..ef5218e 100644 --- a/js/main.js +++ b/js/main.js @@ -1,13 +1,13 @@ -const registerButton = document.getElementById('signUpButton'); -const loginButton = document.getElementById('logInButton'); -const createOrderButton = document.getElementById('createParcel'); -const userOrderButton = document.getElementById('userOrders'); -const singleParcelIdButton = document.getElementById('singleordersearch'); -const updateDestinationButton = document.getElementById('updateorderdestination'); -const cancelOrderButton = document.getElementById('cancelorderbut'); -const allOrdersButton = document.getElementById('allordersbut'); -const updateLocationButton = document.getElementById('updatelocationbut'); -const changeStatusButton = document.getElementById('changestatusbut'); +const registerButton = document.getElementById("signUpButton"); +const loginButton = document.getElementById("logInButton"); +const createOrderButton = document.getElementById("createParcel"); +const userOrderButton = document.getElementById("userOrders"); +const singleParcelIdButton = document.getElementById("singleordersearch"); +const updateDestinationButton = document.getElementById("updateorderdestination"); +const cancelOrderButton = document.getElementById("cancelorderbut"); +const allOrdersButton = document.getElementById("allordersbut"); +const updateLocationButton = document.getElementById("updatelocationbut"); +const changeStatusButton = document.getElementById("changestatusbut"); function decodeJwt (token) { let base64Url = token.split('.')[1]; @@ -16,36 +16,36 @@ function decodeJwt (token) { } function loginResponse(){ - let response = sessionStorage.getItem( 'loginResponse' ); + let response = sessionStorage.getItem( "loginResponse" ); let output = `

    ${response}

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; + return document.getElementById("redirectedLogIn").innerHTML = output; } function signUp(){ let output; - fetch('https://sendit-versiontwo.herokuapp.com/auth/v2/signup', { - mode: 'cors', - method: 'POST', + fetch("https://sendit-versiontwo.herokuapp.com/auth/v2/signup", { + mode: "cors", + method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json; charset=UTF-8" }, body: JSON.stringify({ - email: document.getElementById('signEmail').value, - password: document.getElementById('signPassword').value + email: document.getElementById("signEmail").value, + password: document.getElementById("signPassword").value }) }) .then((res) => { if (res.ok){ return res.json().then((data) => { output = `

    ${data.message}

    `; - return document.getElementById('signUpResponse').innerHTML = output; + return document.getElementById("signUpResponse").innerHTML = output; }); } if (res.status == 400){ return res.json().then((data) => { output = `

    ${data.message}

    `; - return document.getElementById('signUpResponse').innerHTML = output; + return document.getElementById("signUpResponse").innerHTML = output; }); } }); @@ -53,30 +53,29 @@ function signUp(){ function logIn(){ let output; - fetch('https://sendit-versiontwo.herokuapp.com/auth/v2/login', { - mode: 'cors', - method: 'POST', + fetch("https://sendit-versiontwo.herokuapp.com/auth/v2/login", { + mode: "cors", + method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json; charset=UTF-8" }, body: JSON.stringify({ - email: document.getElementById('logInEmail').value, - password: document.getElementById('logInPass').value + email: document.getElementById("logInEmail").value, + password: document.getElementById("logInPass").value }) }) .then((res) => { if (res.ok){ return res.json().then((myJson) => { - sessionStorage.setItem( 'token', myJson.data ); - sessionStorage.setItem( 'loginResponse', myJson.message ); + sessionStorage.setItem( "token", myJson.data ); + sessionStorage.setItem( "loginResponse", myJson.message ); - let token = sessionStorage.getItem( 'token' ).replace("'", ""); + let token = sessionStorage.getItem( "token" ).replace("'", ""); token = token.substr(0, token.length-1); let decodedToken = decodeJwt(token); decodedTokenId = Object.values(decodedToken)[2]; - console.log(decodedTokenId); - if (decodedTokenId == 1){ + if (decodedTokenId === 1){ redirect: window.location.assign("./orders_display_admin.html"); }else{ redirect: window.location.assign("./orders_display_users.html"); @@ -86,13 +85,13 @@ function logIn(){ if (res.status == 400){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('logInResponse').innerHTML = output; + return document.getElementById("logInResponse").innerHTML = output; }); } if (res.status == 401){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('logInResponse').innerHTML = output; + return document.getElementById("logInResponse").innerHTML = output; }); } }); @@ -100,11 +99,11 @@ function logIn(){ function createParcel(){ let output; - let token = sessionStorage.getItem( 'token' ).replace("'", ""); + let token = sessionStorage.getItem( "token" ).replace("'", ""); token = token.substr(0, token.length-1); - fetch('https://sendit-versiontwo.herokuapp.com/api/v2/parcels', { - mode: 'cors', - method: 'POST', + fetch("https://sendit-versiontwo.herokuapp.com/api/v2/parcels", { + mode: "cors", + method: "POST", headers: { Accept: "application/json", "Access-Control-Allow-Origin": null, @@ -112,37 +111,37 @@ function createParcel(){ "Authorization": "Bearer " + token }, body: JSON.stringify({ - item: document.getElementById('parcelName').value, - pickup: document.getElementById('parcelPickUp').value, - dest: document.getElementById('parcelDestination').value, - pricing: document.getElementById('parcelPrice').value, + item: document.getElementById("parcelName").value, + pickup: document.getElementById("parcelPickUp").value, + dest: document.getElementById("parcelDestination").value, + pricing: document.getElementById("parcelPrice").value, }) }) .then((res) => { if (res.ok){ return res.json().then((myJson) => { let output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; + return document.getElementById("redirectedLogIn").innerHTML = output; }) } if (res.status == 400){ return res.json().then((myJson) => { - output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; + output = `

    ${myJson.message}

    `; + return document.getElementById("redirectedLogIn").innerHTML = output; }) } }); } -let orderList = ''; +let orderList = ""; function retrieveUserOrders(){ - let token = sessionStorage.getItem( 'token' ).replace("'", ""); + let token = sessionStorage.getItem( "token" ).replace("'", ""); token = token.substr(0, token.length-1); let decodedToken = decodeJwt(token); decodedTokenId = Object.values(decodedToken)[2]; - fetch('https://sendit-versiontwo.herokuapp.com/api/v2/users/'+decodedTokenId+'/parcels', { - mode: 'cors', - method: 'GET', + fetch("https://sendit-versiontwo.herokuapp.com/api/v2/users/"+decodedTokenId+"/parcels", { + mode: "cors", + method: "GET", headers: { Accept: "application/json", "Access-Control-Allow-Origin": null, @@ -167,16 +166,15 @@ function retrieveUserOrders(){ `; }); let message = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = message, - document.getElementById('singleUserOrders').innerHTML = output, orderList; - - }) + return document.getElementById("redirectedLogIn").innerHTML = message, + document.getElementById("singleUserOrders").innerHTML = output, orderList; + }); } if (res.status == 400){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; - }) + return document.getElementById("redirectedLogIn").innerHTML = output; + }); } }); @@ -192,11 +190,11 @@ function hasNumber(myString) { function singleParcelSearch(){ let output; - let orderId = document.getElementById('parcelorderid').value; + let orderId = document.getElementById("parcelorderid").value; if (hasNumber(orderId)) { - fetch('https://sendit-versiontwo.herokuapp.com/api/v2/parcels/'+orderId+'', { - mode: 'cors', - method: 'GET', + fetch("https://sendit-versiontwo.herokuapp.com/api/v2/parcels/"+orderId+"", { + mode: "cors", + method: "GET", headers: { Accept: "application/json", "Access-Control-Allow-Origin": null, @@ -207,10 +205,9 @@ function singleParcelSearch(){ if (res.ok){ return res.json().then((myJson) => { orderList = myJson.order; - output += `
  • -

    ${orderList.item_name}

    +

    ${orderList.item_name}

    Present Location: ${orderList.current_location}

    Destination: ${orderList.destination}

    Order Id: ${orderList.order_id}

    @@ -218,37 +215,37 @@ function singleParcelSearch(){
  • `; let message = `

    ${myJson.message}

    `; - return document.getElementById('redirectedorderpage').innerHTML = message, - document.getElementById('singleorderinformation').innerHTML = output; + return document.getElementById("redirectedorderpage").innerHTML = message, + document.getElementById("singleorderinformation").innerHTML = output; }); } if (res.status == 400){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedorderpage').innerHTML = output; + return document.getElementById("redirectedorderpage").innerHTML = output; }); } }); } else { output = `

    Order Id can only be numeric

    `; - return document.getElementById('redirectedorderpage').innerHTML = output; + return document.getElementById("redirectedorderpage").innerHTML = output; } } function updateParcelDestination (){ let output; - let orderId = document.getElementById('parcelorderid').value; - let updateDestination = document.getElementById('parcelupdatedestination').value; + let orderId = document.getElementById("parcelorderid").value; + let updateDestination = document.getElementById("parcelupdatedestination").value; if (hasNumber(updateDestination)){ output = `

    Order destination can only be a string

    `; - return document.getElementById('redirectedorderpage').innerHTML = output; + return document.getElementById("redirectedorderpage").innerHTML = output; } else{ - let token = sessionStorage.getItem( 'token' ).replace("'", ""); + let token = sessionStorage.getItem( "token" ).replace("'", ""); token = token.substr(0, token.length-1); - fetch('https://sendit-versiontwo.herokuapp.com/api/v2/parcels/'+orderId+'/destination', { - mode: 'cors', - method: 'PUT', + fetch("https://sendit-versiontwo.herokuapp.com/api/v2/parcels/"+orderId+"/destination", { + mode: "cors", + method: "PUT", headers: { Accept: "application/json", "Access-Control-Allow-Origin": null, @@ -263,20 +260,19 @@ function updateParcelDestination (){ .then((res) => { if (res.ok){ return res.json().then((myJson) => { - let newDestination = myJson.data; - + let newDestination = myJson.data; output += `

    Destination: ${newDestination.updated_destination}

    `; - let message = `

    ${myJson.message}

    `; - return document.getElementById('redirectedorderpage').innerHTML = message, - document.getElementById('generateupdatedestination').innerHTML = output; + let message = `

    ${myJson.message}

    `; + return document.getElementById("redirectedorderpage").innerHTML = message, + document.getElementById("generateupdatedestination").innerHTML = output; }); } if (res.status == 400){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedorderpage').innerHTML = output; + return document.getElementById("redirectedorderpage").innerHTML = output; }); } }); @@ -285,12 +281,12 @@ function updateParcelDestination (){ function cancelOrder(){ let output; - let orderId = document.getElementById('parcelorderid').value; - let token = sessionStorage.getItem( 'token' ).replace("'", ""); + let orderId = document.getElementById("parcelorderid").value; + let token = sessionStorage.getItem( "token" ).replace("'", ""); token = token.substr(0, token.length-1); - fetch('https://sendit-versiontwo.herokuapp.com/api/v2/parcels/'+orderId+'/cancel', { - mode: 'cors', - method: 'PUT', + fetch("https://sendit-versiontwo.herokuapp.com/api/v2/parcels/"+orderId+"/cancel", { + mode: "cors", + method: "PUT", headers: { Accept: "application/json", "Access-Control-Allow-Origin": null, @@ -305,23 +301,23 @@ function cancelOrder(){

    Status: cancelled

    `; let message = `

    ${myJson.message}

    `; - return document.getElementById('redirectedorderpage').innerHTML = message, - document.getElementById('generatestatus').innerHTML = output; + return document.getElementById("redirectedorderpage").innerHTML = message, + document.getElementById("generatestatus").innerHTML = output; }); } if (res.status == 400){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedorderpage').innerHTML = output; + return document.getElementById("redirectedorderpage").innerHTML = output; }); } }); } function retrieveAllOrders(){ let output; - fetch('https://sendit-versiontwo.herokuapp.com/api/v2/parcels', { - mode: 'cors', - method: 'GET', + fetch("https://sendit-versiontwo.herokuapp.com/api/v2/parcels", { + mode: "cors", + method: "GET", headers: { Accept: "application/json", "Access-Control-Allow-Origin": null, @@ -344,14 +340,14 @@ function retrieveAllOrders(){ `; }); let message = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = message, - document.getElementById('alldeliveryorders').innerHTML = output; + return document.getElementById("redirectedLogIn").innerHTML = message, + document.getElementById("alldeliveryorders").innerHTML = output; }); } if (res.status == 400){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; + return document.getElementById("redirectedLogIn").innerHTML = output; }); } }); @@ -359,18 +355,18 @@ function retrieveAllOrders(){ function presentLocation(){ let output; - let orderId = document.getElementById('deliveryorderid').value; - let presentDestination = document.getElementById('parcelpresentlocation').value; + let orderId = document.getElementById("deliveryorderid").value; + let presentDestination = document.getElementById("parcelpresentlocation").value; if (hasNumber(presentDestination)){ output = `

    Order destination can only be a string

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; + return document.getElementById("redirectedLogIn").innerHTML = output; } else{ - let token = sessionStorage.getItem( 'token' ).replace("'", ""); + let token = sessionStorage.getItem( "token" ).replace("'", ""); token = token.substr(0, token.length-1); - fetch('https://sendit-versiontwo.herokuapp.com/api/v2/parcels/'+orderId+'/presentLocation', { - mode: 'cors', - method: 'PUT', + fetch("https://sendit-versiontwo.herokuapp.com/api/v2/parcels/"+orderId+"/presentLocation", { + mode: "cors", + method: "PUT", headers: { Accept: "application/json", "Access-Control-Allow-Origin": null, @@ -391,7 +387,7 @@ function presentLocation(){

    Destination: ${newDestination}

    `; let message = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = message; + return document.getElementById("redirectedLogIn").innerHTML = message; //document.getElementById('generatepresentdestination').innerHTML = output; }); @@ -399,7 +395,7 @@ function presentLocation(){ if (res.status == 400){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; + return document.getElementById("redirectedLogIn").innerHTML = output; }); } }); @@ -407,18 +403,18 @@ function presentLocation(){ } function changeStatus(){ let output; - let orderId = document.getElementById('deliveryorderid').value; - let changeStatus = document.getElementById('changeparcelstatus').value; + let orderId = document.getElementById("deliveryorderid").value; + let changeStatus = document.getElementById("changeparcelstatus").value; if (hasNumber(changeStatus)){ output = `

    status can only be a string

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; + return document.getElementById("redirectedLogIn").innerHTML = output; } else{ - let token = sessionStorage.getItem( 'token' ).replace("'", ""); + let token = sessionStorage.getItem( "token" ).replace("'", ""); token = token.substr(0, token.length-1); - fetch('https://sendit-versiontwo.herokuapp.com/api/v2/parcels/'+orderId+'/status', { - mode: 'cors', - method: 'PUT', + fetch("https://sendit-versiontwo.herokuapp.com/api/v2/parcels/"+orderId+"/status", { + mode: "cors", + method: "PUT", headers: { Accept: "application/json", "Access-Control-Allow-Origin": null, @@ -428,52 +424,50 @@ function changeStatus(){ body: JSON.stringify({ status: changeStatus }) - }) .then((res) => { if (res.ok){ return res.json().then((myJson) => { let message = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = message; - + return document.getElementById("redirectedLogIn").innerHTML = message; }); } if (res.status == 400){ return res.json().then((myJson) => { output = `

    ${myJson.message}

    `; - return document.getElementById('redirectedLogIn').innerHTML = output; + return document.getElementById("redirectedLogIn").innerHTML = output; }); } }); } } if (registerButton){ - registerButton.addEventListener('click', signUp); + registerButton.addEventListener("click", signUp); } if (loginButton){ - loginButton.addEventListener('click', logIn); + loginButton.addEventListener("click", logIn); } if (createOrderButton){ - createOrderButton.addEventListener('click', createParcel); + createOrderButton.addEventListener("click", createParcel); } if (userOrderButton){ - userOrderButton.addEventListener('click', retrieveUserOrders); + userOrderButton.addEventListener("click", retrieveUserOrders); } if (singleParcelIdButton){ - singleParcelIdButton.addEventListener('click', singleParcelSearch); + singleParcelIdButton.addEventListener("click", singleParcelSearch); } if (updateDestinationButton){ - updateDestinationButton.addEventListener('click', updateParcelDestination); + updateDestinationButton.addEventListener("click", updateParcelDestination); } if (cancelOrderButton){ - cancelOrderButton.addEventListener('click', cancelOrder); + cancelOrderButton.addEventListener("click", cancelOrder); } if (allOrdersButton){ - allOrdersButton.addEventListener('click', retrieveAllOrders); + allOrdersButton.addEventListener("click", retrieveAllOrders); } if (updateLocationButton){ - updateLocationButton.addEventListener('click', presentLocation); + updateLocationButton.addEventListener("click", presentLocation); } if (changeStatusButton){ - changeStatusButton.addEventListener('click', changeStatus); + changeStatusButton.addEventListener("click", changeStatus); } \ No newline at end of file diff --git a/order_display_page.html b/order_display_page.html index 671faea..611825d 100644 --- a/order_display_page.html +++ b/order_display_page.html @@ -28,16 +28,16 @@

    SingleOrderdetails

    diff --git a/test/index.spec.js b/test/index.spec.js index 15009b3..f841e25 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -146,17 +146,17 @@ describe("User dashboard", () => { await page.waitForSelector('[data-testid="generatedUserOrders"]'); }); test("assert user can submit delivery order fields", async () => { - await page.waitForSelector('[data-testid="parcelCreationForm"]') - await page.click('[data-testid="orderNameInput"]') - await page.type('[data-testid="orderNameInput"]', dummyParcel.name) - await page.click('[data-testid="orderPickUpInput"]') - await page.type('[data-testid="orderPickUpInput"]', parcel.pickup) - await page.click('[data-testid="orderDestInput"]') - await page.type('[data-testid="orderDestInput"]', parcel.dest) - await page.click('[data-testid="orderPriceInput"]') - await page.type('[data-testid="orderPriceInput"]', parcel.price) - await page.click('[data-testid="createParcelSubmitButton"]') - await page.waitForSelector('[data-testid="createOrderFailResponse"]') + await page.waitForSelector('[data-testid="parcelCreationForm"]'); + await page.click('[data-testid="orderNameInput"]'); + await page.type('[data-testid="orderNameInput"]', dummyParcel.name); + await page.click('[data-testid="orderPickUpInput"]'); + await page.type('[data-testid="orderPickUpInput"]', parcel.pickup); + await page.click('[data-testid="orderDestInput"]'); + await page.type('[data-testid="orderDestInput"]', parcel.dest); + await page.click('[data-testid="orderPriceInput"]'); + await page.type('[data-testid="orderPriceInput"]', parcel.price); + await page.click('[data-testid="createParcelSubmitButton"]'); + await page.waitForSelector('[data-testid="createOrderFailResponse"]'); }); test("assert user can redirect to single order info page", async () => { await page.waitForSelector('[data-testid="generatedUserOrders"]'); @@ -182,6 +182,13 @@ describe("User dashboard", () => { const updatedOrderDestination = await page.$eval('[data-testid="updatedDestination"]', el => el.textContent); expect(updatedOrderDestination).toEqual("New destination updated"); }); + test("assert user can cancel order", async () => { + await page.waitForSelector('[data-testid="singleOrderForm"]'); + await page.click('[data-testid="cancelOrder"]'); + await page.waitForSelector('[data-testid="cancelResponse"]'); + const cancelOrderResponse = await page.$eval('[data-testid="cancelResponse"]', el => el.textContent); + expect(cancelOrderResponse).toEqual("order is cancelled"); + }); }); /* From 6e3d0dc3d42369ce503b8652aed65f4b63f001aa Mon Sep 17 00:00:00 2001 From: ipaullly Date: Sun, 24 Feb 2019 22:28:08 +0300 Subject: [PATCH 19/27] [finishes #164191738] add tests for admin interactions --- js/main.js | 6 +++--- orders_display_admin.html | 12 ++++++------ test/index.spec.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/js/main.js b/js/main.js index 3d54572..7cd50c4 100644 --- a/js/main.js +++ b/js/main.js @@ -330,7 +330,7 @@ function retrieveAllOrders(){ orderList = myJson.data; orderList.forEach((order) => { output += ` -
  • +
  • ${order.item_name}

    Present Location: ${order.current_location}

    Destination: ${order.destination}

    @@ -386,7 +386,7 @@ function presentLocation(){ output = `

    Destination: ${newDestination}

    `; - let message = `

    ${myJson.message}

    `; + let message = `

    ${myJson.message}

    `; return document.getElementById("redirectedLogIn").innerHTML = message; //document.getElementById('generatepresentdestination').innerHTML = output; @@ -428,7 +428,7 @@ function changeStatus(){ .then((res) => { if (res.ok){ return res.json().then((myJson) => { - let message = `

    ${myJson.message}

    `; + let message = `

    ${myJson.message}

    `; return document.getElementById("redirectedLogIn").innerHTML = message; }); } diff --git a/orders_display_admin.html b/orders_display_admin.html index e874eb3..80e3ea5 100644 --- a/orders_display_admin.html +++ b/orders_display_admin.html @@ -28,20 +28,20 @@

    AdminOrders List

    diff --git a/test/index.spec.js b/test/index.spec.js index f841e25..35ca889 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -191,6 +191,38 @@ describe("User dashboard", () => { }); }); +describe("Admin dashboard", () => { + test("assert admin can view all orders made by all users", async () => { + await page.goto(routes.public.login); + await page.waitForSelector('[data-testid="logInForm"]'); + await page.click('[data-testid="logInEmailInput"]'); + await page.type('[data-testid="logInEmailInput"]', admin.email); + await page.click('[data-testid="logInPasswordInput"]'); + await page.type('[data-testid="logInPasswordInput"]', admin.password); + await page.click('[data-testid="loginSubmitButton"]'); + await page.waitForNavigation({waitUntil: "networkidle2"}); + await page.waitForSelector('[data-testid="allOrdersAdmin"]'); + await page.click('[data-testid="allOrdersAdmin"]'); + await page.waitForSelector('[data-testid="generatedAllOrders"]'); + }); + test("assert admin can update the current location of a parcel", async () => { + await page.waitForSelector('[data-testid="updateLocationForm"]'); + await page.click('[data-testid="parcelIdInput"]'); + await page.type('[data-testid="parcelIdInput"]', "1"); + await page.click('[data-testid="parcelLocationInput"]'); + await page.type('[data-testid="parcelLocationInput"]', "Homabay"); + await page.click('[data-testid="updateLocationButton"]'); + await page.waitForSelector('[data-testid="updateLocationResponse"]'); + }); + test("assert admin can update status of a parcel", async () => { + await page.waitForSelector('[data-testid="updateOrderStatus"]'); + await page.click('[data-testid="updateOrderStatus"]'); + await page.type('[data-testid="updateOrderStatus"]', "Arrived"); + await page.click('[data-testid="orderStatusButton"]'); + await page.waitForSelector('[data-testid="orderStatusResponse"]'); + }); +}); + /* describe('User parcel creation', () => { From dcb97ef0500c04e83eeb38c342d055cb705f208c Mon Sep 17 00:00:00 2001 From: ipaullly Date: Sun, 24 Feb 2019 22:40:23 +0300 Subject: [PATCH 20/27] update README.md headings --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 03905f8..23c5dca 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -#Send-IT +# Send-IT [![Build Status](https://travis-ci.com/ipaullly/sendIT.svg?branch=ch-test-user-interactions-163458249)](https://travis-ci.com/ipaullly/sendIT) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d5026cb302e349d7b08580df620e7ecd)](https://www.codacy.com/app/ipaullly/sendIT?utm_source=github.com&utm_medium=referral&utm_content=ipaullly/sendIT&utm_campaign=Badge_Grade) The project was done while participating in the Andela Developer Challenge simulated sprint of the application bootcamp. This is an app that allows users to create accounts and make delivery orders. The front-end was built using vanilla javaScript and consumed endpoints built with python/flask. The app is live on the github-pages [link](https://ipaullly.github.io/sendIT/index.html) for this repo. -#Installation +## Installation Clone the repository to your local machine ``` git clone https://github.com/ipaullly/sendIT.git @@ -31,14 +31,14 @@ To run the project on your local server npm start ``` -#Testing +## Testing Tests run using **jest** and **puppeteer**. run the following command within the project folder to see the test coverage ``` npm test ``` Alternatively view the [Travis-CI](https://travis-ci.com/ipaullly/sendIT) build report to view coverage. -#App features +## App features - [ ] Users can create an account and log in. - [ ] Users can create a parcel delivery order. - [ ] Users can change the destination of a parcel delivery order. @@ -46,7 +46,7 @@ Alternatively view the [Travis-CI](https://travis-ci.com/ipaullly/sendIT) build - [ ] Users can see the details of a delivery order. - [ ] Admin can change the **status** and **Current-location** of a parcel delivery order. -#Built Using +## Built Using 1.HTML 2.CSS 3.JAVASCRIPT From b0c33d6e0e136aa5c39fb6ab96b337704d06bcc2 Mon Sep 17 00:00:00 2001 From: Morogo Date: Fri, 11 Oct 2019 16:06:55 +0300 Subject: [PATCH 21/27] Update style.css --- css/style.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/css/style.css b/css/style.css index 593640d..d08083e 100644 --- a/css/style.css +++ b/css/style.css @@ -114,6 +114,7 @@ header a:hover{ /* squares */ #squares{ margin-top: 20px; + padding-bottom: 6rem; } #squares .box{ @@ -228,4 +229,4 @@ span.assord { display: block; float: none; } -} \ No newline at end of file +} From e8802235f8d4b7d6a7c3bed39a50911c69a8f18c Mon Sep 17 00:00:00 2001 From: Morogo Date: Mon, 6 Jan 2020 11:35:07 +0300 Subject: [PATCH 22/27] Update index.html --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 0e9a579..599fc0e 100644 --- a/index.html +++ b/index.html @@ -52,8 +52,8 @@

    Sign up in under a minute

    -

    Send-IT, Copyright © 2019

    +

    Send-IT, Copyright © 2020

    - \ No newline at end of file + From 362c3f77a63d25b7c4a5510294faf456e788f05f Mon Sep 17 00:00:00 2001 From: Morogo Date: Mon, 6 Jan 2020 11:35:37 +0300 Subject: [PATCH 23/27] Update about.html --- about.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/about.html b/about.html index 9b42377..2649b14 100644 --- a/about.html +++ b/about.html @@ -54,8 +54,8 @@

    Behold our presence on social platforms

    -

    Send-IT, Copyright © 2019

    +

    Send-IT, Copyright © 2020

    - \ No newline at end of file + From b2d22c2de3d4047f52c789d31f6833e0fee6b56e Mon Sep 17 00:00:00 2001 From: Morogo Date: Mon, 6 Jan 2020 11:36:13 +0300 Subject: [PATCH 24/27] Update login.html --- login.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/login.html b/login.html index 68523f5..6716043 100644 --- a/login.html +++ b/login.html @@ -56,8 +56,8 @@

    Login

    -

    Send-IT, Copyright © 2019

    +

    Send-IT, Copyright © 2020

    - \ No newline at end of file + From 93e8d96c1378a4a6e19cb3f5540763e92fa22eec Mon Sep 17 00:00:00 2001 From: Morogo Date: Mon, 6 Jan 2020 11:36:58 +0300 Subject: [PATCH 25/27] Update register_page.html --- register_page.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/register_page.html b/register_page.html index 2a5a014..a0157bb 100644 --- a/register_page.html +++ b/register_page.html @@ -59,8 +59,8 @@

    REGISTER TO SEND-IT

    -

    Send-IT, Copyright © 2019

    +

    Send-IT, Copyright © 2020

    - \ No newline at end of file + From d465efd4e69f697b2656a23c7f115e944e82b819 Mon Sep 17 00:00:00 2001 From: Morogo Date: Fri, 17 Jan 2020 17:55:18 +0300 Subject: [PATCH 26/27] Update order_display_page.html --- order_display_page.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/order_display_page.html b/order_display_page.html index 9f81988..1bf59f7 100644 --- a/order_display_page.html +++ b/order_display_page.html @@ -62,8 +62,8 @@

    Parcel Name

    -

    Send-IT, Copyright © 2019

    +

    Send-IT, Copyright © 2020

    - \ No newline at end of file + From 38dc92c8877797a8d6d2682189c88d2356e31422 Mon Sep 17 00:00:00 2001 From: Morogo Date: Fri, 17 Jan 2020 17:55:46 +0300 Subject: [PATCH 27/27] Update orders_display_admin.html --- orders_display_admin.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/orders_display_admin.html b/orders_display_admin.html index 80e3ea5..4487e07 100644 --- a/orders_display_admin.html +++ b/orders_display_admin.html @@ -77,8 +77,8 @@

    Orders

    -

    Send-IT, Copyright © 2019

    +

    Send-IT, Copyright © 2020

    - \ No newline at end of file +