From 707d12eb26c8df91ac1f64202344add6778d24cc Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 13:56:31 +0000 Subject: [PATCH 01/31] Create database interaction methods --- server/datalayer/mongo.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/server/datalayer/mongo.js b/server/datalayer/mongo.js index 693ca84..908cf11 100644 --- a/server/datalayer/mongo.js +++ b/server/datalayer/mongo.js @@ -4,6 +4,24 @@ class DataLayer { this.model = model; } + /** + * Find all records in the database. + */ + async findAllAndPopulate(filter, populateFilter) { + return this.model.find(JSON.parse(JSON.stringify(filter))) + .limit(filter.limit) + .skip(filter.offset * filter.limit) + .populate(JSON.parse(JSON.stringify(populateFilter))) + .catch(error => { throw new Error(error.message)}); + } + + /** + * Find a record by property in the database. + */ + async findByProperty(propertyToFind) { + return this.model.find(propertyToFind); + } + /** * Create and save the record to the database. */ @@ -12,10 +30,13 @@ class DataLayer { } /** - * Find a record by property in the database. + * Update and save the record to the database. */ - async findByProperty(propertyToFind) { - return this.model.find(propertyToFind); + async update(recordId, recordToUpdate) { + return this.model.findByIdAndUpdate(recordId, recordToUpdate) + .orFail("Bill can't be found in the database.") + .catch(error => {throw new Error(error.message)}); + } } From 8b2ac241016bf881a62206664938dfdf1bd626e9 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 13:56:47 +0000 Subject: [PATCH 02/31] Create bill business logic --- server/business/bill.business.js | 37 ++++++++++++++++++++++++++++++++ server/business/user.business.js | 3 +-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 server/business/bill.business.js diff --git a/server/business/bill.business.js b/server/business/bill.business.js new file mode 100644 index 0000000..73ab932 --- /dev/null +++ b/server/business/bill.business.js @@ -0,0 +1,37 @@ +const DataLayer = require("../datalayer/mongo"); +const model = require("../database").getModel("user"); +const httpError = require("http-errors"); + +module.exports = class billBusiness { + constructor() { + // Create an instance of the data layer. + this.dataLayer = new DataLayer(model); + } + + /** + * Get all bills. + */ + async getAllBills(queryString) { + const filter = { + driverId: queryString.driverId, + paid: queryString.paid, + limit: queryString.limit ?? Number.MAX_VALUE, + offset: queryString.offset ?? 0 + } + return this.dataLayer + .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'location' }}) + .catch((error) => { throw httpError(404, error.message)}) + } + + /** + * Get a bill by ID. + */ + async payBill(id) { + const record = { + paid: true + } + return this.dataLayer.update(id, record) + .catch((error) => {throw httpError(404, error.message) + }) + } +} \ No newline at end of file diff --git a/server/business/user.business.js b/server/business/user.business.js index 7111eaa..ad32100 100644 --- a/server/business/user.business.js +++ b/server/business/user.business.js @@ -4,7 +4,7 @@ const httpError = require("http-errors"); const jwt = require("jsonwebtoken"); const bcrypt = require("bcryptjs"); -class UserBusiness { +module.exports = class UserBusiness { constructor() { // Create an instance of the data layer. this.dataLayer = new DataLayer(model); @@ -104,7 +104,6 @@ class UserBusiness { }); } } -module.exports = UserBusiness; /** * Validates the data in a User. From 19ec81e9bfc6f2af59dd3d40d2f3160876c61888 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 13:57:05 +0000 Subject: [PATCH 03/31] Update bill model to have paid property --- server/models/bill.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/models/bill.js b/server/models/bill.js index 474f5ed..228c9f8 100644 --- a/server/models/bill.js +++ b/server/models/bill.js @@ -14,6 +14,10 @@ cost: { type: Number, required: [true, "A cost for the bill is required."] + }, + paid: { + type: Boolean, + default: false } }, { From f5613af77f0b6fd231d04862dc84f8c7b2108446 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 13:57:18 +0000 Subject: [PATCH 04/31] Create bill controllers --- server/controllers/bill.controller.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 server/controllers/bill.controller.js diff --git a/server/controllers/bill.controller.js b/server/controllers/bill.controller.js new file mode 100644 index 0000000..9f39e65 --- /dev/null +++ b/server/controllers/bill.controller.js @@ -0,0 +1,20 @@ +const BillBusiness = require("../business/bill.business"); +const billBusiness = new BillBusiness(); + +/** + * Get all bills + */ +exports.getAllBills = async (req, res) => { + billBusiness.getAllBills(req.query) + .then((data) => {res.status(200).send(data)}) + .catch((error) => {res.status(error.status).send({ message: error.message })}) +} + +/** + * Pay bill + */ +exports.payBill = async (req, res) => { + billBusiness.payBill(req.params.id) + .then(() => {res.status(200).send()}) + .catch((error) => {res.status(error.status).send({message: error.message})}) +} \ No newline at end of file From aea9e865efcac543b6ff1dd3db8c96245895aa6f Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 13:57:44 +0000 Subject: [PATCH 05/31] Create bill routes and add to router --- server/app.js | 7 ++++--- server/routes/auth.routes.js | 6 +++--- server/routes/bill.routes.js | 13 +++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 server/routes/bill.routes.js diff --git a/server/app.js b/server/app.js index a8ef318..f4b6b27 100644 --- a/server/app.js +++ b/server/app.js @@ -8,7 +8,7 @@ const cookieParser = require("cookie-parser"); require("./database"); require("dotenv").config(); -var app = express(); +const app = express(); app.use( cookieSession({ @@ -24,8 +24,8 @@ app.use(cors({ origin: "http://localhost:8080", credentials: true })); /** * Router setup */ -var authRouter = require("./routes/auth.routes"); - +const authRouter = require("./routes/auth.routes"); +const billRouter = require("./routes/bill.routes"); /** * View Engine setup */ @@ -40,5 +40,6 @@ app.use(cookieParser()); // Configuring the main routes app.use("/auth", authRouter); +app.use("/bill", billRouter) module.exports = app; diff --git a/server/routes/auth.routes.js b/server/routes/auth.routes.js index a664b36..129ccfd 100644 --- a/server/routes/auth.routes.js +++ b/server/routes/auth.routes.js @@ -1,8 +1,8 @@ -var express = require("express"); -var router = express.Router(); +const express = require("express"); +const router = express.Router(); // Get the Auth controller -var authController = require("../controllers/auth.controller"); +const authController = require("../controllers/auth.controller"); // Log the user in router.post("/login/", authController.login); diff --git a/server/routes/bill.routes.js b/server/routes/bill.routes.js new file mode 100644 index 0000000..22a4f8b --- /dev/null +++ b/server/routes/bill.routes.js @@ -0,0 +1,13 @@ +const express = require("express"); +const router = express.Router(); + +// Get the Bill controller +const billController = require("../controllers/bill.controller"); + +// Get All Bills +router.get("/", billController.getAllBills); + +// Pay for bill +router.put("/{id}", billController.payBill); + +module.exports = router; From 17cf974ced9af463ec9489f1745273c743bef01d Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 13:58:36 +0000 Subject: [PATCH 06/31] Add package-lock.json --- package-lock.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..13e7197 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "CSSD-Assignment", + "lockfileVersion": 2, + "requires": true, + "packages": {} +} From e5e08b6fe6eb81bc38cbfd848f9b0eae8b83bf52 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 15:06:58 +0000 Subject: [PATCH 07/31] Fix bugs with bill endpoints --- server/business/bill.business.js | 6 +++--- server/models/bill.js | 10 +--------- server/models/journey.js | 8 +------- server/routes/bill.routes.js | 2 +- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/server/business/bill.business.js b/server/business/bill.business.js index 73ab932..83b4c1f 100644 --- a/server/business/bill.business.js +++ b/server/business/bill.business.js @@ -1,5 +1,5 @@ const DataLayer = require("../datalayer/mongo"); -const model = require("../database").getModel("user"); +const model = require("../database").getModel("bill"); const httpError = require("http-errors"); module.exports = class billBusiness { @@ -19,8 +19,8 @@ module.exports = class billBusiness { offset: queryString.offset ?? 0 } return this.dataLayer - .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'location' }}) - .catch((error) => { throw httpError(404, error.message)}) + .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }}) + .catch((error) => {throw httpError(404, error.message)}) } /** diff --git a/server/models/bill.js b/server/models/bill.js index 228c9f8..b0e9bb2 100644 --- a/server/models/bill.js +++ b/server/models/bill.js @@ -19,16 +19,8 @@ type: Boolean, default: false } - }, - { - toJSON: {virtuals: true}, - toObject: {virtuals: true} } ) - - billSchema.virtual('billReferenceNumber', { - billReferenceNumber: this._id - }) - + return mongoose.model("bill", billSchema) } \ No newline at end of file diff --git a/server/models/journey.js b/server/models/journey.js index 481b3f1..d2a69b2 100644 --- a/server/models/journey.js +++ b/server/models/journey.js @@ -1,6 +1,4 @@ -const haversine = require('haversine-distance') - -module.exports = mongoose => { +module.exports = mongoose => { const journeySchema = mongoose.Schema( { regNumber: { @@ -23,9 +21,5 @@ module.exports = mongoose => { } ) - journeySchema.methods.getJourneyDistance = function() { - return haversine(this.entryLocation.coordinates, this.exitLocation.coordinates) - } - return mongoose.model("journey", journeySchema) } \ No newline at end of file diff --git a/server/routes/bill.routes.js b/server/routes/bill.routes.js index 22a4f8b..46e3986 100644 --- a/server/routes/bill.routes.js +++ b/server/routes/bill.routes.js @@ -8,6 +8,6 @@ const billController = require("../controllers/bill.controller"); router.get("/", billController.getAllBills); // Pay for bill -router.put("/{id}", billController.payBill); +router.put("/:id", billController.payBill); module.exports = router; From 3796b39a368e7b747ed839f28bcd0404f5836f51 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 16:28:07 +0000 Subject: [PATCH 08/31] Add tests for bill endpoints --- .gitignore | 1 - server/.env | 1 + server/.nyc_output/processinfo/index.json | 2 +- server/business/bill.business.js | 3 +- server/business/user.business.js | 9 +- server/controllers/bill.controller.js | 3 +- server/database/seed.js | 67 ++++++- server/datalayer/mongo.js | 3 +- server/middleware/auth/authJwt.js | 6 +- .../test/integration/auth.controller.test.js | 6 +- .../test/integration/bill.controller.test.js | 188 ++++++++++++++++++ 11 files changed, 266 insertions(+), 23 deletions(-) create mode 100644 server/.env create mode 100644 server/test/integration/bill.controller.test.js diff --git a/.gitignore b/.gitignore index 382f01b..e822182 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,3 @@ pnpm-debug.log* *.njsproj *.sln *.sw? -*.env diff --git a/server/.env b/server/.env new file mode 100644 index 0000000..3fff465 --- /dev/null +++ b/server/.env @@ -0,0 +1 @@ +TOKEN_SECRET=test \ No newline at end of file diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index 83b4e73..dd7ed80 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"ecd4285b-d9dc-4104-b850-fcf81a763c89":{"parent":null,"children":[]}},"files":{"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\app.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\database\\index.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\config\\db.config.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\models\\user.model.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\routes\\auth.routes.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\controllers\\auth.controller.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\business\\user.business.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"],"C:\\Users\\Jarrod\\Documents\\AAF\\CSSD\\server\\datalayer\\mongo.js":["ecd4285b-d9dc-4104-b850-fcf81a763c89"]},"externalIds":{}} \ No newline at end of file +{"processes":{"6ff6e946-dd21-4349-8139-df010a261ab1":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["6ff6e946-dd21-4349-8139-df010a261ab1"]},"externalIds":{}} \ No newline at end of file diff --git a/server/business/bill.business.js b/server/business/bill.business.js index 83b4c1f..a5b5823 100644 --- a/server/business/bill.business.js +++ b/server/business/bill.business.js @@ -13,14 +13,13 @@ module.exports = class billBusiness { */ async getAllBills(queryString) { const filter = { - driverId: queryString.driverId, + driver: queryString.driver, paid: queryString.paid, limit: queryString.limit ?? Number.MAX_VALUE, offset: queryString.offset ?? 0 } return this.dataLayer .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }}) - .catch((error) => {throw httpError(404, error.message)}) } /** diff --git a/server/business/user.business.js b/server/business/user.business.js index ad32100..51ac094 100644 --- a/server/business/user.business.js +++ b/server/business/user.business.js @@ -47,8 +47,7 @@ module.exports = class UserBusiness { id: user._id, }; }) - .catch(() => { - throw httpError(400, "Your email or password is incorrect."); + .catch(() => {throw httpError(400, "Your email or password is incorrect."); }); } @@ -109,9 +108,5 @@ module.exports = class UserBusiness { * Validates the data in a User. */ function isUserDataValid(user) { - if (!user || !user.username || !user.email || !user.password) { - return false; - } else { - return true; - } + return !(!user || !user.username || !user.email || !user.password); } diff --git a/server/controllers/bill.controller.js b/server/controllers/bill.controller.js index 9f39e65..e3935eb 100644 --- a/server/controllers/bill.controller.js +++ b/server/controllers/bill.controller.js @@ -7,7 +7,6 @@ const billBusiness = new BillBusiness(); exports.getAllBills = async (req, res) => { billBusiness.getAllBills(req.query) .then((data) => {res.status(200).send(data)}) - .catch((error) => {res.status(error.status).send({ message: error.message })}) } /** @@ -15,6 +14,6 @@ exports.getAllBills = async (req, res) => { */ exports.payBill = async (req, res) => { billBusiness.payBill(req.params.id) - .then(() => {res.status(200).send()}) + .then(() => {res.status(200).send({message: "Bill paid."})}) .catch((error) => {res.status(error.status).send({message: error.message})}) } \ No newline at end of file diff --git a/server/database/seed.js b/server/database/seed.js index 200149a..0438f4a 100644 --- a/server/database/seed.js +++ b/server/database/seed.js @@ -1,5 +1,8 @@ const mongoose = require("mongoose"); mongoose.users = require("../models/user.model")(mongoose); +mongoose.locations = require("../models/location")(mongoose); +mongoose.journeys = require("../models/journey")(mongoose); +mongoose.bills = require("../models/bill")(mongoose); const bcrypt = require("bcryptjs"); mongoose @@ -18,13 +21,73 @@ const users = [ { username: "test_username", email: "test@email.com", - password: bcrypt.hashSync("admin", 8), + password: bcrypt.hashSync("test1", 8), type: "Driver", }, ]; + +const locations = [ + { + _id: "123456789101", + name: "test_location_1", + coordinates: { + longitude: 10, + latitude: 10 + } + }, + { + _id: "123456789102", + name: "test_location_2", + coordinates: { + longitude: 10, + latitude: 10 + } + } +] + +const journeys = [ + { + _id: "123456789103", + regNumber: "test_reg_number", + entryLocation: "123456789101", + exitLocation: "123456789102", + journeyDateTime: "2022-02-01T15:50:51.039Z" + }, + { + _id: "123456789104", + regNumber: "test_reg_number2", + entryLocation: "123456789101", + exitLocation: "123456789102", + journeyDateTime: "2022-02-01T15:50:51.038Z" + }, +] + +const bills = [ + { + _id: "123456789105", + journey: "123456789103", + driver: "test_driver", + cost: 5, + paid: false + }, + { + _id: "123456789106", + journey: "123456789104", + driver: "test_driver2", + cost: 5, + paid: true + } +] + const seedDB = async () => { - await mongoose.users.deleteMany(); + for(collection in mongoose.connection.collections){ + await mongoose.connection.collections[collection].deleteMany() + } + await mongoose.users.insertMany(users); + await mongoose.locations.insertMany(locations); + await mongoose.journeys.insertMany(journeys); + await mongoose.bills.insertMany(bills) }; seedDB() diff --git a/server/datalayer/mongo.js b/server/datalayer/mongo.js index 908cf11..a6138ce 100644 --- a/server/datalayer/mongo.js +++ b/server/datalayer/mongo.js @@ -12,7 +12,6 @@ class DataLayer { .limit(filter.limit) .skip(filter.offset * filter.limit) .populate(JSON.parse(JSON.stringify(populateFilter))) - .catch(error => { throw new Error(error.message)}); } /** @@ -34,7 +33,7 @@ class DataLayer { */ async update(recordId, recordToUpdate) { return this.model.findByIdAndUpdate(recordId, recordToUpdate) - .orFail("Bill can't be found in the database.") + .orFail(new Error("Bill can't be found in the database.")) .catch(error => {throw new Error(error.message)}); } diff --git a/server/middleware/auth/authJwt.js b/server/middleware/auth/authJwt.js index 45f9f37..09faa78 100644 --- a/server/middleware/auth/authJwt.js +++ b/server/middleware/auth/authJwt.js @@ -1,7 +1,7 @@ const jwt = require("jsonwebtoken"); // Check if token is valid -checkJwtToken = (req, res, next) => { +const checkJwtToken = (req, res, next) => { if (!req.session || !req.session.token) { return res.status(401).send({ message: "Unauthorized: No token provided.", @@ -24,10 +24,10 @@ checkJwtToken = (req, res, next) => { }); }; -isOperator = (req, res, next) => { +const isOperator = (req, res, next) => { const type = req.type; - if (type != "Toll Operator") { + if (type !== "Toll Operator") { return res.status(403).send({ message: "Unauthorized: You not do have permission to view this page.", diff --git a/server/test/integration/auth.controller.test.js b/server/test/integration/auth.controller.test.js index 1369ef4..dc87a1b 100644 --- a/server/test/integration/auth.controller.test.js +++ b/server/test/integration/auth.controller.test.js @@ -33,7 +33,7 @@ describe("Testing /auth paths", () => { it("user should be able to login", (done) => { // Arrange const request = { - email: "test@test.com", + email: "test@email.com", password: "test1", }; @@ -48,7 +48,7 @@ describe("Testing /auth paths", () => { res.body.should.have.property("message"); res.body.message.should.be.eql("Successfully logged in."); res.should.have.cookie("highwayTracker-token"); - + done(); }); }); @@ -56,7 +56,7 @@ describe("Testing /auth paths", () => { it("user shouldn't be able to login with invalid credentials", (done) => { // Act const request = { - email: "test@test.com", + email: "test@email.com", password: "test2", }; diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js new file mode 100644 index 0000000..5c1755b --- /dev/null +++ b/server/test/integration/bill.controller.test.js @@ -0,0 +1,188 @@ +let chai = require("chai"); +let chaiHttp = require("chai-http"); +let server = require("../../app"); +let should = chai.should(); +chai.use(chaiHttp); + +describe("Testing /bill paths", () => { + it("Should get all bills", (done) => { + // Arrange + const url = "/bill/" + + // Act + chai.request(server) + .get(url) + .send() + .end((err, res) => { + // Assert + res.should.have.status(200); + res.should.be.a("object"); + res.body.should.have.lengthOf(2); + res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('driver', 'test_driver') + res.body[0].should.haveOwnProperty('paid', false) + res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') + res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') + res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + + done(); + }) + }) + + it("Should get all bills which match the driver ID", (done) => { + // Arrange + const driverId = "test_driver" + const url = `/bill?driver=${driverId}` + + // Act + chai.request(server) + .get(url) + .send() + .end((err, res) => { + // Assert + res.should.have.status(200); + res.should.be.a("object"); + res.body.should.have.lengthOf(1); + res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('driver', 'test_driver') + res.body[0].should.haveOwnProperty('paid', false) + res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') + res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') + res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + + done(); + }) + }) + + it("Should get all bills which match the paid", (done) => { + // Arrange + const paid = true + const url = `/bill?paid=${paid}` + + // Act + chai.request(server) + .get(url) + .send() + .end((err, res) => { + // Assert + res.should.have.status(200); + res.should.be.a("object"); + res.body.should.have.lengthOf(1); + res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('driver', 'test_driver2') + res.body[0].should.haveOwnProperty('paid', true) + res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number2') + res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.038Z') + res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + + done(); + }) + }) + + it("Should get one bill when pagination limit is one", (done) => { + // Arrange + const limit = 1 + const url = `/bill?limit=${limit}` + + // Act + chai.request(server) + .get(url) + .send() + .end((err, res) => { + // Assert + res.should.have.status(200); + res.should.be.a("object"); + res.body.should.have.lengthOf(1); + res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('driver', 'test_driver') + res.body[0].should.haveOwnProperty('paid', false) + res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') + res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') + res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + + done(); + }) + }) + + it("Should get no bills when pagination offset is one", (done) => { + // Arrange + const offset = 1 + const url = `/bill?offset=${offset}` + + // Act + chai.request(server) + .get(url) + .send() + .end((err, res) => { + // Assert + res.should.have.status(200); + res.should.be.a("object"); + res.body.should.have.lengthOf(0); + + done(); + }) + }) + + it("Should update paid to true", (done) => { + // Arrange + const requestBody = { + paid: true + } + const url = `/bill/123456789105` + + // Act + chai.request(server) + .put(url) + .send(requestBody) + .end((err, res) => { + // Assert + res.should.have.status(200); + res.should.be.a("object"); + res.body.message.should.be.eql("Bill paid."); + + done(); + }) + }) + + it("Should throw error if bill doesnt exist", (done) => { + // Arrange + const fakeId = '111111111111' + const requestBody = { + paid: true + } + const url = `/bill/${fakeId}` + + // Act + chai.request(server) + .put(url) + .send(requestBody) + .end((err, res) => { + // Assert + res.should.have.status(404); + res.body.message.should.be.eql("Bill can't be found in the database."); + + done(); + }) + }) + +}) \ No newline at end of file From 0af299ec270b11624d0376c3ad742313729e5aba Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 16:36:09 +0000 Subject: [PATCH 09/31] Add console logs to debug pipeline --- server/.nyc_output/processinfo/index.json | 2 +- server/controllers/bill.controller.js | 1 + server/test/integration/bill.controller.test.js | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index dd7ed80..ce434a7 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"6ff6e946-dd21-4349-8139-df010a261ab1":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["6ff6e946-dd21-4349-8139-df010a261ab1"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["6ff6e946-dd21-4349-8139-df010a261ab1"]},"externalIds":{}} \ No newline at end of file +{"processes":{"668d7d53-4590-4a6c-b3d7-699e5279e027":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"]},"externalIds":{}} \ No newline at end of file diff --git a/server/controllers/bill.controller.js b/server/controllers/bill.controller.js index e3935eb..175b61e 100644 --- a/server/controllers/bill.controller.js +++ b/server/controllers/bill.controller.js @@ -5,6 +5,7 @@ const billBusiness = new BillBusiness(); * Get all bills */ exports.getAllBills = async (req, res) => { + console.log("CONTROLLER") billBusiness.getAllBills(req.query) .then((data) => {res.status(200).send(data)}) } diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js index 5c1755b..09e0672 100644 --- a/server/test/integration/bill.controller.test.js +++ b/server/test/integration/bill.controller.test.js @@ -128,13 +128,15 @@ describe("Testing /bill paths", () => { // Arrange const offset = 1 const url = `/bill?offset=${offset}` - + console.log("ARRANGE") // Act chai.request(server) .get(url) .send() .end((err, res) => { // Assert + console.log("ASSERT" + res.body) + res.should.have.status(200); res.should.be.a("object"); res.body.should.have.lengthOf(0); From be78a3604a7732564d5da3167f121a50c241fc7f Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 16:39:17 +0000 Subject: [PATCH 10/31] Add more console logs to debug pipeline --- server/business/bill.business.js | 1 + server/controllers/bill.controller.js | 4 +++- server/datalayer/mongo.js | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/server/business/bill.business.js b/server/business/bill.business.js index a5b5823..bbcd8d7 100644 --- a/server/business/bill.business.js +++ b/server/business/bill.business.js @@ -18,6 +18,7 @@ module.exports = class billBusiness { limit: queryString.limit ?? Number.MAX_VALUE, offset: queryString.offset ?? 0 } + console.log("BUSINESS" + filter) return this.dataLayer .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }}) } diff --git a/server/controllers/bill.controller.js b/server/controllers/bill.controller.js index 175b61e..a9ebed8 100644 --- a/server/controllers/bill.controller.js +++ b/server/controllers/bill.controller.js @@ -7,7 +7,9 @@ const billBusiness = new BillBusiness(); exports.getAllBills = async (req, res) => { console.log("CONTROLLER") billBusiness.getAllBills(req.query) - .then((data) => {res.status(200).send(data)}) + .then((data) => { + console.log(data) + return res.status(200).send(data)}) } /** diff --git a/server/datalayer/mongo.js b/server/datalayer/mongo.js index a6138ce..9e097ae 100644 --- a/server/datalayer/mongo.js +++ b/server/datalayer/mongo.js @@ -8,6 +8,7 @@ class DataLayer { * Find all records in the database. */ async findAllAndPopulate(filter, populateFilter) { + console.log("DATA LAYER") return this.model.find(JSON.parse(JSON.stringify(filter))) .limit(filter.limit) .skip(filter.offset * filter.limit) From 893f6198440fdca0b5b8657069a0c20e2be18ad9 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 16:42:10 +0000 Subject: [PATCH 11/31] Add catch to getall endpoint --- server/controllers/bill.controller.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/controllers/bill.controller.js b/server/controllers/bill.controller.js index a9ebed8..a7accc4 100644 --- a/server/controllers/bill.controller.js +++ b/server/controllers/bill.controller.js @@ -10,6 +10,10 @@ exports.getAllBills = async (req, res) => { .then((data) => { console.log(data) return res.status(200).send(data)}) + .catch((error) => { + res.status(error.status).send({message: error.message}) + }) + } /** From 4b7d7424fcb64e15d4478e09531e9482bb789a04 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 16:46:32 +0000 Subject: [PATCH 12/31] Attempt to fix pipeline #3 --- .../test/integration/bill.controller.test.js | 140 +++++++++--------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js index 09e0672..3152fcc 100644 --- a/server/test/integration/bill.controller.test.js +++ b/server/test/integration/bill.controller.test.js @@ -94,35 +94,35 @@ describe("Testing /bill paths", () => { }) }) - it("Should get one bill when pagination limit is one", (done) => { - // Arrange - const limit = 1 - const url = `/bill?limit=${limit}` - - // Act - chai.request(server) - .get(url) - .send() - .end((err, res) => { - // Assert - res.should.have.status(200); - res.should.be.a("object"); - res.body.should.have.lengthOf(1); - res.body[0].should.haveOwnProperty('cost', 5) - res.body[0].should.haveOwnProperty('driver', 'test_driver') - res.body[0].should.haveOwnProperty('paid', false) - res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') - res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') - res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) - res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) - - done(); - }) - }) + // it("Should get one bill when pagination limit is one", (done) => { + // // Arrange + // const limit = 1 + // const url = `/bill?limit=${limit}` + // + // // Act + // chai.request(server) + // .get(url) + // .send() + // .end((err, res) => { + // // Assert + // res.should.have.status(200); + // res.should.be.a("object"); + // res.body.should.have.lengthOf(1); + // res.body[0].should.haveOwnProperty('cost', 5) + // res.body[0].should.haveOwnProperty('driver', 'test_driver') + // res.body[0].should.haveOwnProperty('paid', false) + // res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') + // res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') + // res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') + // res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) + // res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + // res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') + // res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) + // res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + // + // done(); + // }) + // }) it("Should get no bills when pagination offset is one", (done) => { // Arrange @@ -145,46 +145,46 @@ describe("Testing /bill paths", () => { }) }) - it("Should update paid to true", (done) => { - // Arrange - const requestBody = { - paid: true - } - const url = `/bill/123456789105` - - // Act - chai.request(server) - .put(url) - .send(requestBody) - .end((err, res) => { - // Assert - res.should.have.status(200); - res.should.be.a("object"); - res.body.message.should.be.eql("Bill paid."); - - done(); - }) - }) - - it("Should throw error if bill doesnt exist", (done) => { - // Arrange - const fakeId = '111111111111' - const requestBody = { - paid: true - } - const url = `/bill/${fakeId}` - - // Act - chai.request(server) - .put(url) - .send(requestBody) - .end((err, res) => { - // Assert - res.should.have.status(404); - res.body.message.should.be.eql("Bill can't be found in the database."); - - done(); - }) - }) + // it("Should update paid to true", (done) => { + // // Arrange + // const requestBody = { + // paid: true + // } + // const url = `/bill/123456789105` + // + // // Act + // chai.request(server) + // .put(url) + // .send(requestBody) + // .end((err, res) => { + // // Assert + // res.should.have.status(200); + // res.should.be.a("object"); + // res.body.message.should.be.eql("Bill paid."); + // + // done(); + // }) + // }) + // + // it("Should throw error if bill doesnt exist", (done) => { + // // Arrange + // const fakeId = '111111111111' + // const requestBody = { + // paid: true + // } + // const url = `/bill/${fakeId}` + // + // // Act + // chai.request(server) + // .put(url) + // .send(requestBody) + // .end((err, res) => { + // // Assert + // res.should.have.status(404); + // res.body.message.should.be.eql("Bill can't be found in the database."); + // + // done(); + // }) + // }) }) \ No newline at end of file From d74c6e65fa051b41a147c82f1801e46d1779455d Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 16:52:49 +0000 Subject: [PATCH 13/31] Attempt to fix pipeline #4 --- server/business/bill.business.js | 2 +- .../test/integration/bill.controller.test.js | 140 +++++++++--------- 2 files changed, 71 insertions(+), 71 deletions(-) diff --git a/server/business/bill.business.js b/server/business/bill.business.js index bbcd8d7..3e11576 100644 --- a/server/business/bill.business.js +++ b/server/business/bill.business.js @@ -15,7 +15,7 @@ module.exports = class billBusiness { const filter = { driver: queryString.driver, paid: queryString.paid, - limit: queryString.limit ?? Number.MAX_VALUE, + limit: queryString.limit ?? 10, offset: queryString.offset ?? 0 } console.log("BUSINESS" + filter) diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js index 3152fcc..5c07062 100644 --- a/server/test/integration/bill.controller.test.js +++ b/server/test/integration/bill.controller.test.js @@ -94,35 +94,35 @@ describe("Testing /bill paths", () => { }) }) - // it("Should get one bill when pagination limit is one", (done) => { - // // Arrange - // const limit = 1 - // const url = `/bill?limit=${limit}` - // - // // Act - // chai.request(server) - // .get(url) - // .send() - // .end((err, res) => { - // // Assert - // res.should.have.status(200); - // res.should.be.a("object"); - // res.body.should.have.lengthOf(1); - // res.body[0].should.haveOwnProperty('cost', 5) - // res.body[0].should.haveOwnProperty('driver', 'test_driver') - // res.body[0].should.haveOwnProperty('paid', false) - // res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') - // res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') - // res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') - // res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) - // res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) - // res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') - // res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) - // res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) - // - // done(); - // }) - // }) + it("Should get one bill when pagination limit is one", (done) => { + // Arrange + const limit = 1 + const url = `/bill?limit=${limit}` + + // Act + chai.request(server) + .get(url) + .send() + .end((err, res) => { + // Assert + res.should.have.status(200); + res.should.be.a("object"); + res.body.should.have.lengthOf(1); + res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('driver', 'test_driver') + res.body[0].should.haveOwnProperty('paid', false) + res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') + res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') + res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + + done(); + }) + }) it("Should get no bills when pagination offset is one", (done) => { // Arrange @@ -145,46 +145,46 @@ describe("Testing /bill paths", () => { }) }) - // it("Should update paid to true", (done) => { - // // Arrange - // const requestBody = { - // paid: true - // } - // const url = `/bill/123456789105` - // - // // Act - // chai.request(server) - // .put(url) - // .send(requestBody) - // .end((err, res) => { - // // Assert - // res.should.have.status(200); - // res.should.be.a("object"); - // res.body.message.should.be.eql("Bill paid."); - // - // done(); - // }) - // }) - // - // it("Should throw error if bill doesnt exist", (done) => { - // // Arrange - // const fakeId = '111111111111' - // const requestBody = { - // paid: true - // } - // const url = `/bill/${fakeId}` - // - // // Act - // chai.request(server) - // .put(url) - // .send(requestBody) - // .end((err, res) => { - // // Assert - // res.should.have.status(404); - // res.body.message.should.be.eql("Bill can't be found in the database."); - // - // done(); - // }) - // }) + it("Should update paid to true", (done) => { + // Arrange + const requestBody = { + paid: true + } + const url = `/bill/123456789105` + + // Act + chai.request(server) + .put(url) + .send(requestBody) + .end((err, res) => { + // Assert + res.should.have.status(200); + res.should.be.a("object"); + res.body.message.should.be.eql("Bill paid."); + + done(); + }) + }) + + it("Should throw error if bill doesnt exist", (done) => { + // Arrange + const fakeId = '111111111111' + const requestBody = { + paid: true + } + const url = `/bill/${fakeId}` + + // Act + chai.request(server) + .put(url) + .send(requestBody) + .end((err, res) => { + // Assert + res.should.have.status(404); + res.body.message.should.be.eql("Bill can't be found in the database."); + + done(); + }) + }) }) \ No newline at end of file From 5f9f93301a7a31617fe5f58fe20008c3af73b6a7 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 16:59:00 +0000 Subject: [PATCH 14/31] Remove pipeline debugging and update workflow --- .github/workflows/node.js.yml | 2 +- server/business/bill.business.js | 1 - server/controllers/bill.controller.js | 5 +---- server/database/seed.js | 2 +- server/datalayer/mongo.js | 1 - 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 9e6d9b9..59af930 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -57,4 +57,4 @@ jobs: uses: JamesIves/github-pages-deploy-action@v4.2.3 with: branch: gh-pages - folder: develop \ No newline at end of file + folder: . \ No newline at end of file diff --git a/server/business/bill.business.js b/server/business/bill.business.js index 3e11576..4625cec 100644 --- a/server/business/bill.business.js +++ b/server/business/bill.business.js @@ -18,7 +18,6 @@ module.exports = class billBusiness { limit: queryString.limit ?? 10, offset: queryString.offset ?? 0 } - console.log("BUSINESS" + filter) return this.dataLayer .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }}) } diff --git a/server/controllers/bill.controller.js b/server/controllers/bill.controller.js index a7accc4..07f2c67 100644 --- a/server/controllers/bill.controller.js +++ b/server/controllers/bill.controller.js @@ -5,11 +5,8 @@ const billBusiness = new BillBusiness(); * Get all bills */ exports.getAllBills = async (req, res) => { - console.log("CONTROLLER") billBusiness.getAllBills(req.query) - .then((data) => { - console.log(data) - return res.status(200).send(data)}) + .then((data) => {return res.status(200).send(data)}) .catch((error) => { res.status(error.status).send({message: error.message}) }) diff --git a/server/database/seed.js b/server/database/seed.js index 0438f4a..4db1451 100644 --- a/server/database/seed.js +++ b/server/database/seed.js @@ -80,7 +80,7 @@ const bills = [ ] const seedDB = async () => { - for(collection in mongoose.connection.collections){ + for(const collection in mongoose.connection.collections){ await mongoose.connection.collections[collection].deleteMany() } diff --git a/server/datalayer/mongo.js b/server/datalayer/mongo.js index 9e097ae..a6138ce 100644 --- a/server/datalayer/mongo.js +++ b/server/datalayer/mongo.js @@ -8,7 +8,6 @@ class DataLayer { * Find all records in the database. */ async findAllAndPopulate(filter, populateFilter) { - console.log("DATA LAYER") return this.model.find(JSON.parse(JSON.stringify(filter))) .limit(filter.limit) .skip(filter.offset * filter.limit) From 47a1f50086aa52974f3e11c06c48b384cb8aa1d9 Mon Sep 17 00:00:00 2001 From: Jake Date: Tue, 1 Feb 2022 17:09:51 +0000 Subject: [PATCH 15/31] Add coverage report to build pipeline --- .github/workflows/node.js.yml | 2 +- server/.nyc_output/processinfo/index.json | 2 +- server/coverage/lcov-report/base.css | 224 ++++++++++ .../coverage/lcov-report/block-navigation.js | 87 ++++ server/coverage/lcov-report/favicon.png | Bin 0 -> 540 bytes server/coverage/lcov-report/index.html | 221 +++++++++ server/coverage/lcov-report/prettify.css | 1 + server/coverage/lcov-report/prettify.js | 2 + .../coverage/lcov-report/server/app.js.html | 220 +++++++++ .../server/business/bill.business.js.html | 190 ++++++++ .../lcov-report/server/business/index.html | 131 ++++++ .../server/business/user.business.js.html | 421 ++++++++++++++++++ .../server/config/db.config.js.html | 109 +++++ .../lcov-report/server/config/index.html | 116 +++++ .../controllers/auth.controller.js.html | 241 ++++++++++ .../controllers/bill.controller.js.html | 151 +++++++ .../lcov-report/server/controllers/index.html | 131 ++++++ .../lcov-report/server/database/index.html | 116 +++++ .../lcov-report/server/database/index.js.html | 244 ++++++++++ .../lcov-report/server/datalayer/index.html | 116 +++++ .../server/datalayer/mongo.js.html | 211 +++++++++ server/coverage/lcov-report/server/index.html | 116 +++++ .../lcov-report/server/models/bill.js.html | 160 +++++++ .../lcov-report/server/models/index.html | 161 +++++++ .../lcov-report/server/models/journey.js.html | 157 +++++++ .../server/models/location.js.html | 148 ++++++ .../server/models/user.model.js.html | 178 ++++++++ .../server/routes/auth.routes.js.html | 133 ++++++ .../server/routes/bill.routes.js.html | 124 ++++++ .../lcov-report/server/routes/index.html | 131 ++++++ .../lcov-report/sort-arrow-sprite.png | Bin 0 -> 209 bytes server/coverage/lcov-report/sorter.js | 196 ++++++++ server/coverage/lcov.info | 379 ++++++++++++++++ server/package.json | 2 +- .../test/integration/bill.controller.test.js | 3 +- 35 files changed, 4819 insertions(+), 5 deletions(-) create mode 100644 server/coverage/lcov-report/base.css create mode 100644 server/coverage/lcov-report/block-navigation.js create mode 100644 server/coverage/lcov-report/favicon.png create mode 100644 server/coverage/lcov-report/index.html create mode 100644 server/coverage/lcov-report/prettify.css create mode 100644 server/coverage/lcov-report/prettify.js create mode 100644 server/coverage/lcov-report/server/app.js.html create mode 100644 server/coverage/lcov-report/server/business/bill.business.js.html create mode 100644 server/coverage/lcov-report/server/business/index.html create mode 100644 server/coverage/lcov-report/server/business/user.business.js.html create mode 100644 server/coverage/lcov-report/server/config/db.config.js.html create mode 100644 server/coverage/lcov-report/server/config/index.html create mode 100644 server/coverage/lcov-report/server/controllers/auth.controller.js.html create mode 100644 server/coverage/lcov-report/server/controllers/bill.controller.js.html create mode 100644 server/coverage/lcov-report/server/controllers/index.html create mode 100644 server/coverage/lcov-report/server/database/index.html create mode 100644 server/coverage/lcov-report/server/database/index.js.html create mode 100644 server/coverage/lcov-report/server/datalayer/index.html create mode 100644 server/coverage/lcov-report/server/datalayer/mongo.js.html create mode 100644 server/coverage/lcov-report/server/index.html create mode 100644 server/coverage/lcov-report/server/models/bill.js.html create mode 100644 server/coverage/lcov-report/server/models/index.html create mode 100644 server/coverage/lcov-report/server/models/journey.js.html create mode 100644 server/coverage/lcov-report/server/models/location.js.html create mode 100644 server/coverage/lcov-report/server/models/user.model.js.html create mode 100644 server/coverage/lcov-report/server/routes/auth.routes.js.html create mode 100644 server/coverage/lcov-report/server/routes/bill.routes.js.html create mode 100644 server/coverage/lcov-report/server/routes/index.html create mode 100644 server/coverage/lcov-report/sort-arrow-sprite.png create mode 100644 server/coverage/lcov-report/sorter.js create mode 100644 server/coverage/lcov.info diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 59af930..3b870ab 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -52,7 +52,7 @@ jobs: - name: Code Coverage uses: romeovs/lcov-reporter-action@v0.2.16 with: - lcov-file: ./coverage/lcov.info + lcov-file: ./server/coverage/lcov.info - name: Deploy uses: JamesIves/github-pages-deploy-action@v4.2.3 with: diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index ce434a7..0c53470 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"668d7d53-4590-4a6c-b3d7-699e5279e027":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["668d7d53-4590-4a6c-b3d7-699e5279e027"]},"externalIds":{}} \ No newline at end of file +{"processes":{"7b3978e8-85aa-46d2-9a25-1b740367f6cb":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"]},"externalIds":{}} \ No newline at end of file diff --git a/server/coverage/lcov-report/base.css b/server/coverage/lcov-report/base.css new file mode 100644 index 0000000..f418035 --- /dev/null +++ b/server/coverage/lcov-report/base.css @@ -0,0 +1,224 @@ +body, html { + margin:0; padding: 0; + height: 100%; +} +body { + font-family: Helvetica Neue, Helvetica, Arial; + font-size: 14px; + color:#333; +} +.small { font-size: 12px; } +*, *:after, *:before { + -webkit-box-sizing:border-box; + -moz-box-sizing:border-box; + box-sizing:border-box; + } +h1 { font-size: 20px; margin: 0;} +h2 { font-size: 14px; } +pre { + font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; + margin: 0; + padding: 0; + -moz-tab-size: 2; + -o-tab-size: 2; + tab-size: 2; +} +a { color:#0074D9; text-decoration:none; } +a:hover { text-decoration:underline; } +.strong { font-weight: bold; } +.space-top1 { padding: 10px 0 0 0; } +.pad2y { padding: 20px 0; } +.pad1y { padding: 10px 0; } +.pad2x { padding: 0 20px; } +.pad2 { padding: 20px; } +.pad1 { padding: 10px; } +.space-left2 { padding-left:55px; } +.space-right2 { padding-right:20px; } +.center { text-align:center; } +.clearfix { display:block; } +.clearfix:after { + content:''; + display:block; + height:0; + clear:both; + visibility:hidden; + } +.fl { float: left; } +@media only screen and (max-width:640px) { + .col3 { width:100%; max-width:100%; } + .hide-mobile { display:none!important; } +} + +.quiet { + color: #7f7f7f; + color: rgba(0,0,0,0.5); +} +.quiet a { opacity: 0.7; } + +.fraction { + font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; + font-size: 10px; + color: #555; + background: #E8E8E8; + padding: 4px 5px; + border-radius: 3px; + vertical-align: middle; +} + +div.path a:link, div.path a:visited { color: #333; } +table.coverage { + border-collapse: collapse; + margin: 10px 0 0 0; + padding: 0; +} + +table.coverage td { + margin: 0; + padding: 0; + vertical-align: top; +} +table.coverage td.line-count { + text-align: right; + padding: 0 5px 0 20px; +} +table.coverage td.line-coverage { + text-align: right; + padding-right: 10px; + min-width:20px; +} + +table.coverage td span.cline-any { + display: inline-block; + padding: 0 5px; + width: 100%; +} +.missing-if-branch { + display: inline-block; + margin-right: 5px; + border-radius: 3px; + position: relative; + padding: 0 4px; + background: #333; + color: yellow; +} + +.skip-if-branch { + display: none; + margin-right: 10px; + position: relative; + padding: 0 4px; + background: #ccc; + color: white; +} +.missing-if-branch .typ, .skip-if-branch .typ { + color: inherit !important; +} +.coverage-summary { + border-collapse: collapse; + width: 100%; +} +.coverage-summary tr { border-bottom: 1px solid #bbb; } +.keyline-all { border: 1px solid #ddd; } +.coverage-summary td, .coverage-summary th { padding: 10px; } +.coverage-summary tbody { border: 1px solid #bbb; } +.coverage-summary td { border-right: 1px solid #bbb; } +.coverage-summary td:last-child { border-right: none; } +.coverage-summary th { + text-align: left; + font-weight: normal; + white-space: nowrap; +} +.coverage-summary th.file { border-right: none !important; } +.coverage-summary th.pct { } +.coverage-summary th.pic, +.coverage-summary th.abs, +.coverage-summary td.pct, +.coverage-summary td.abs { text-align: right; } +.coverage-summary td.file { white-space: nowrap; } +.coverage-summary td.pic { min-width: 120px !important; } +.coverage-summary tfoot td { } + +.coverage-summary .sorter { + height: 10px; + width: 7px; + display: inline-block; + margin-left: 0.5em; + background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; +} +.coverage-summary .sorted .sorter { + background-position: 0 -20px; +} +.coverage-summary .sorted-desc .sorter { + background-position: 0 -10px; +} +.status-line { height: 10px; } +/* yellow */ +.cbranch-no { background: yellow !important; color: #111; } +/* dark red */ +.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } +.low .chart { border:1px solid #C21F39 } +.highlighted, +.highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{ + background: #C21F39 !important; +} +/* medium red */ +.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } +/* light red */ +.low, .cline-no { background:#FCE1E5 } +/* light green */ +.high, .cline-yes { background:rgb(230,245,208) } +/* medium green */ +.cstat-yes { background:rgb(161,215,106) } +/* dark green */ +.status-line.high, .high .cover-fill { background:rgb(77,146,33) } +.high .chart { border:1px solid rgb(77,146,33) } +/* dark yellow (gold) */ +.status-line.medium, .medium .cover-fill { background: #f9cd0b; } +.medium .chart { border:1px solid #f9cd0b; } +/* light yellow */ +.medium { background: #fff4c2; } + +.cstat-skip { background: #ddd; color: #111; } +.fstat-skip { background: #ddd; color: #111 !important; } +.cbranch-skip { background: #ddd !important; color: #111; } + +span.cline-neutral { background: #eaeaea; } + +.coverage-summary td.empty { + opacity: .5; + padding-top: 4px; + padding-bottom: 4px; + line-height: 1; + color: #888; +} + +.cover-fill, .cover-empty { + display:inline-block; + height: 12px; +} +.chart { + line-height: 0; +} +.cover-empty { + background: white; +} +.cover-full { + border-right: none !important; +} +pre.prettyprint { + border: none !important; + padding: 0 !important; + margin: 0 !important; +} +.com { color: #999 !important; } +.ignore-none { color: #999; font-weight: normal; } + +.wrapper { + min-height: 100%; + height: auto !important; + height: 100%; + margin: 0 auto -48px; +} +.footer, .push { + height: 48px; +} diff --git a/server/coverage/lcov-report/block-navigation.js b/server/coverage/lcov-report/block-navigation.js new file mode 100644 index 0000000..cc12130 --- /dev/null +++ b/server/coverage/lcov-report/block-navigation.js @@ -0,0 +1,87 @@ +/* eslint-disable */ +var jumpToCode = (function init() { + // Classes of code we would like to highlight in the file view + var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no']; + + // Elements to highlight in the file listing view + var fileListingElements = ['td.pct.low']; + + // We don't want to select elements that are direct descendants of another match + var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > ` + + // Selecter that finds elements on the page to which we can jump + var selector = + fileListingElements.join(', ') + + ', ' + + notSelector + + missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b` + + // The NodeList of matching elements + var missingCoverageElements = document.querySelectorAll(selector); + + var currentIndex; + + function toggleClass(index) { + missingCoverageElements + .item(currentIndex) + .classList.remove('highlighted'); + missingCoverageElements.item(index).classList.add('highlighted'); + } + + function makeCurrent(index) { + toggleClass(index); + currentIndex = index; + missingCoverageElements.item(index).scrollIntoView({ + behavior: 'smooth', + block: 'center', + inline: 'center' + }); + } + + function goToPrevious() { + var nextIndex = 0; + if (typeof currentIndex !== 'number' || currentIndex === 0) { + nextIndex = missingCoverageElements.length - 1; + } else if (missingCoverageElements.length > 1) { + nextIndex = currentIndex - 1; + } + + makeCurrent(nextIndex); + } + + function goToNext() { + var nextIndex = 0; + + if ( + typeof currentIndex === 'number' && + currentIndex < missingCoverageElements.length - 1 + ) { + nextIndex = currentIndex + 1; + } + + makeCurrent(nextIndex); + } + + return function jump(event) { + if ( + document.getElementById('fileSearch') === document.activeElement && + document.activeElement != null + ) { + // if we're currently focused on the search input, we don't want to navigate + return; + } + + switch (event.which) { + case 78: // n + case 74: // j + goToNext(); + break; + case 66: // b + case 75: // k + case 80: // p + goToPrevious(); + break; + } + }; +})(); +window.addEventListener('keydown', jumpToCode); diff --git a/server/coverage/lcov-report/favicon.png b/server/coverage/lcov-report/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..6691817834a957c938e7f09640a37a645fb31457 GIT binary patch literal 540 zcmV+%0^|LOP)wSzy{h>9elhJ=8GnBQmf?)AI(^#wDA_`!QTxaXXE&bjxo zTGCc%V|W`}Lwz0rDO*qBbGY-M@aNENIZ1rK?nOAibaC*vb%CF;I_~lkJawax%_+1J zLn(#pv_v{f0`v`Cfp6()7MB(>IoTAiQdKxgxX?VyV&KVZ7b$vn<8|Z<9$35C+G_8SH0x6Y(xB&~bmn%r}ceRwbc0000 + + + + Code coverage report for All files + + + + + + + + + +
+
+

All files

+
+ +
+ 91.83% + Statements + 135/147 +
+ + +
+ 83.33% + Branches + 15/18 +
+ + +
+ 86.36% + Functions + 38/44 +
+ + +
+ 91.83% + Lines + 135/147 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
server +
+
100%24/24100%0/0100%0/0100%24/24
server/business +
+
92.3%36/3987.5%14/1693.75%15/1692.3%36/39
server/config +
+
100%1/1100%0/0100%0/0100%1/1
server/controllers +
+
88.88%24/27100%0/084.61%11/1388.88%24/27
server/database +
+
75%18/2450%1/240%2/575%18/24
server/datalayer +
+
100%7/7100%0/0100%6/6100%7/7
server/models +
+
100%12/12100%0/0100%4/4100%12/12
server/routes +
+
100%13/13100%0/0100%0/0100%13/13
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/prettify.css b/server/coverage/lcov-report/prettify.css new file mode 100644 index 0000000..b317a7c --- /dev/null +++ b/server/coverage/lcov-report/prettify.css @@ -0,0 +1 @@ +.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} diff --git a/server/coverage/lcov-report/prettify.js b/server/coverage/lcov-report/prettify.js new file mode 100644 index 0000000..b322523 --- /dev/null +++ b/server/coverage/lcov-report/prettify.js @@ -0,0 +1,2 @@ +/* eslint-disable */ +window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); diff --git a/server/coverage/lcov-report/server/app.js.html b/server/coverage/lcov-report/server/app.js.html new file mode 100644 index 0000000..8d4c6e4 --- /dev/null +++ b/server/coverage/lcov-report/server/app.js.html @@ -0,0 +1,220 @@ + + + + + + Code coverage report for server/app.js + + + + + + + + + +
+
+

All files / server app.js

+
+ +
+ 100% + Statements + 24/24 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 24/24 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +461x +1x +1x +1x +1x +1x +  +1x +1x +  +1x +  +1x +  +  +  +  +  +  +  +  +1x +  +  +  +  +1x +1x +  +  +  +1x +1x +1x +1x +1x +1x +1x +1x +  +  +1x +1x +  +1x + 
const express = require("express");
+const path = require("path");
+const bodyParser = require("body-parser");
+const cors = require("cors");
+const cookieSession = require("cookie-session");
+const cookieParser = require("cookie-parser");
+ 
+require("./database");
+require("dotenv").config();
+ 
+const app = express();
+ 
+app.use(
+    cookieSession({
+        name: "highwayTracker-token",
+        secret: process.env.TOKEN_SECRET,
+        httpOnly: true,
+        keys: [process.env.TOKEN_SECRET],
+    })
+);
+ 
+app.use(cors({ origin: "http://localhost:8080", credentials: true }));
+ 
+/**
+ * Router setup
+ */
+const authRouter = require("./routes/auth.routes");
+const billRouter = require("./routes/bill.routes");
+/**
+ * View Engine setup
+ */
+app.set("views", path.join(__dirname, "views"));
+app.set("trust proxy", 1);
+app.use(express.json());
+app.use(express.urlencoded({ extended: false }));
+app.use(bodyParser.json());
+app.use(bodyParser.urlencoded({ extended: true }));
+app.use(express.static(path.join(__dirname, "public")));
+app.use(cookieParser());
+ 
+// Configuring the main routes
+app.use("/auth", authRouter);
+app.use("/bill", billRouter)
+ 
+module.exports = app;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/business/bill.business.js.html b/server/coverage/lcov-report/server/business/bill.business.js.html new file mode 100644 index 0000000..ded6863 --- /dev/null +++ b/server/coverage/lcov-report/server/business/bill.business.js.html @@ -0,0 +1,190 @@ + + + + + + Code coverage report for server/business/bill.business.js + + + + + + + + + +
+
+

All files / server/business bill.business.js

+
+ +
+ 100% + Statements + 10/10 +
+ + +
+ 100% + Branches + 4/4 +
+ + +
+ 100% + Functions + 4/4 +
+ + +
+ 100% + Lines + 10/10 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +361x +1x +1x +  +1x +  +  +1x +  +  +  +  +  +  +5x +  +  +  +  +  +5x +  +  +  +  +  +  +  +2x +  +  +2x +1x +  +  + 
const DataLayer = require("../datalayer/mongo");
+const model = require("../database").getModel("bill");
+const httpError = require("http-errors");
+ 
+module.exports = class billBusiness {
+ constructor() {
+  // Create an instance of the data layer.
+  this.dataLayer = new DataLayer(model);
+ }
+ 
+ /**
+  *  Get all bills.
+  */
+ async getAllBills(queryString) {
+  const filter = {
+   driver: queryString.driver,
+   paid: queryString.paid,
+   limit: queryString.limit ?? 10,
+   offset: queryString.offset ?? 0
+  }
+  return this.dataLayer
+      .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }})
+ }
+ 
+ /**
+  *  Get a bill by ID.
+  */
+ async payBill(id) {
+  const record = {
+   paid: true
+  }
+  return this.dataLayer.update(id, record)
+    .catch((error) => {throw httpError(404, error.message)
+  })
+ }
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/business/index.html b/server/coverage/lcov-report/server/business/index.html new file mode 100644 index 0000000..62df32c --- /dev/null +++ b/server/coverage/lcov-report/server/business/index.html @@ -0,0 +1,131 @@ + + + + + + Code coverage report for server/business + + + + + + + + + +
+
+

All files server/business

+
+ +
+ 92.3% + Statements + 36/39 +
+ + +
+ 87.5% + Branches + 14/16 +
+ + +
+ 93.75% + Functions + 15/16 +
+ + +
+ 92.3% + Lines + 36/39 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
bill.business.js +
+
100%10/10100%4/4100%4/4100%10/10
user.business.js +
+
89.65%26/2983.33%10/1291.66%11/1289.65%26/29
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/business/user.business.js.html b/server/coverage/lcov-report/server/business/user.business.js.html new file mode 100644 index 0000000..a23501c --- /dev/null +++ b/server/coverage/lcov-report/server/business/user.business.js.html @@ -0,0 +1,421 @@ + + + + + + Code coverage report for server/business/user.business.js + + + + + + + + + +
+
+

All files / server/business user.business.js

+
+ +
+ 89.65% + Statements + 26/29 +
+ + +
+ 83.33% + Branches + 10/12 +
+ + +
+ 91.66% + Functions + 11/12 +
+ + +
+ 89.65% + Lines + 26/29 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +1131x +1x +1x +1x +1x +  +1x +  +  +1x +  +  +  +  +  +  +2x +  +2x +  +  +  +  +2x +1x +  +  +  +  +  +1x +  +  +  +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +1x +  +  +  +  +  +  +  +3x +  +  +  +  +  +2x +  +  +  +  +  +  +  +3x +  +  +3x +  +  +  +  +  +  +3x +2x +1x +1x +1x +  +  +  +  +  +  +  +  +2x +  +  +  +2x +  +  +  +  +  +  +  +  +  +  +  +3x +  + 
const DataLayer = require("../datalayer/mongo");
+const model = require("../database").getModel("user");
+const httpError = require("http-errors");
+const jwt = require("jsonwebtoken");
+const bcrypt = require("bcryptjs");
+ 
+module.exports = class UserBusiness {
+    constructor() {
+        // Create an instance of the data layer.
+        this.dataLayer = new DataLayer(model);
+    }
+ 
+    /**
+     *  Login a user.
+     */
+    async login(email, password) {
+        return this.findUserByEmail(email)
+            .then((user) => {
+                const passwordIsValid = bcrypt.compareSync(
+                    password,
+                    user.password
+                );
+                // Invalid password, return 401
+                if (!passwordIsValid) {
+                    throw httpError(
+                        401,
+                        "Your email or password is incorrect."
+                    );
+                }
+                // Create token and store in the session cookie
+                const token = jwt.sign(
+                    {
+                        id: user._id,
+                        type: user.type,
+                        email: user.email,
+                        username: user.username,
+                    },
+                    process.env.TOKEN_SECRET,
+                    {
+                        expiresIn: 3600, // 1 hour
+                    }
+                );
+                return {
+                    token: token,
+                    username: user.username,
+                    type: user.type,
+                    id: user._id,
+                };
+            })
+            .catch(() => {throw httpError(400, "Your email or password is incorrect.");
+            });
+    }
+ 
+    /**
+     *  Register a user.
+     */
+    async register(user) {
+        return this.createUser({
+            username: user.username,
+            email: user.email,
+            password: user.password,
+            type: "Driver",
+        }).catch((error) => {
+            throw httpError(400, error.message);
+        });
+    }
+ 
+    /**
+     *  Create a user and save it to the User collection.
+     */
+    async createUser(userToCreate) {
+        Iif (!isUserDataValid(userToCreate)) {
+            throw httpError(400, "User data is invalid.");
+        }
+        const user = {
+            username: userToCreate.username,
+            email: userToCreate.email,
+            type: userToCreate.type,
+            password: bcrypt.hashSync(userToCreate.password, 8),
+        };
+ 
+        return this.dataLayer.create(user).catch((error) => {
+            if (error.message.includes("username"))
+                throw httpError(400, "Username is already in use.");
+            Eif (error.message.includes("email"))
+                throw httpError(400, "Email is already in use.");
+            throw httpError(404, error.message);
+        });
+    }
+ 
+    /**
+     *  Find a user by email
+     */
+    async findUserByEmail(email) {
+        return this.dataLayer
+            .findByProperty({ email: email })
+            .then((users) => {
+                // Email is unique so only 1 can be returned.
+                return users[0];
+            })
+            .catch((error) => {
+                throw httpError(404, error.message);
+            });
+    }
+}
+ 
+/**
+ *  Validates the data in a User.
+ */
+function isUserDataValid(user) {
+    return !(!user || !user.username || !user.email || !user.password);
+}
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/config/db.config.js.html b/server/coverage/lcov-report/server/config/db.config.js.html new file mode 100644 index 0000000..b44167d --- /dev/null +++ b/server/coverage/lcov-report/server/config/db.config.js.html @@ -0,0 +1,109 @@ + + + + + + Code coverage report for server/config/db.config.js + + + + + + + + + +
+
+

All files / server/config db.config.js

+
+ +
+ 100% + Statements + 1/1 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 1/1 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +91x +  +  +  +  +  +  +  + 
module.exports = {
+    dev: {
+        url: "mongodb://localhost:27017/highwaytrackerdb",
+    },
+    test: {
+        url: "mongodb://localhost:27017/highwaytrackerdb_testing",
+    },
+};
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/config/index.html b/server/coverage/lcov-report/server/config/index.html new file mode 100644 index 0000000..1e64ab4 --- /dev/null +++ b/server/coverage/lcov-report/server/config/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for server/config + + + + + + + + + +
+
+

All files server/config

+
+ +
+ 100% + Statements + 1/1 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 1/1 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
db.config.js +
+
100%1/1100%0/0100%0/0100%1/1
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/auth.controller.js.html b/server/coverage/lcov-report/server/controllers/auth.controller.js.html new file mode 100644 index 0000000..3dfd9bf --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/auth.controller.js.html @@ -0,0 +1,241 @@ + + + + + + Code coverage report for server/controllers/auth.controller.js + + + + + + + + + +
+
+

All files / server/controllers auth.controller.js

+
+ +
+ 88.23% + Statements + 15/17 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 85.71% + Functions + 6/7 +
+ + +
+ 88.23% + Lines + 15/17 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +531x +1x +  +  +  +  +1x +2x +  +  +1x +1x +1x +1x +  +1x +  +  +  +  +  +  +  +1x +  +  +  +  +  +  +1x +3x +  +  +1x +  +  +  +  +2x +  +  +  +  +  +  +1x +  +  +  +  +  + 
const UserBusiness = require("../business/user.business");
+const userBusiness = new UserBusiness();
+ 
+/**
+ * Login the user
+ */
+exports.login = async (req, res) => {
+    userBusiness
+        .login(req.body.email, req.body.password)
+        .then((data) => {
+            req.session.token = data.token;
+            req.session.username = data.username;
+            req.session.role = data.role;
+            req.session.id = data.id;
+ 
+            res.status(200).send({
+                message: "Successfully logged in.",
+                username: data.username,
+                role: data.role,
+                id: data.id,
+            });
+        })
+        .catch((error) => {
+            res.status(error.status).send({ message: error.message });
+        });
+};
+ 
+/**
+ * Register the user
+ */
+exports.register = (req, res) => {
+    userBusiness
+        .register(req.body)
+        .then(() => {
+            res.status(201).send({
+                message: "User was successfully created.",
+            });
+        })
+        .catch((error) => {
+            res.status(error.status).send({ message: error.message });
+        });
+};
+ 
+/**
+ * Logs the user out
+ */
+exports.logout = (req, res) => {
+    req.session = null;
+    res.status(200).send({
+        message: "User was successfully logged out.",
+    });
+};
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/bill.controller.js.html b/server/coverage/lcov-report/server/controllers/bill.controller.js.html new file mode 100644 index 0000000..b786cbe --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/bill.controller.js.html @@ -0,0 +1,151 @@ + + + + + + Code coverage report for server/controllers/bill.controller.js + + + + + + + + + +
+
+

All files / server/controllers bill.controller.js

+
+ +
+ 90% + Statements + 9/10 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 83.33% + Functions + 5/6 +
+ + +
+ 90% + Lines + 9/10 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +231x +1x +  +  +  +  +1x +5x +5x +  +  +  +  +  +  +  +  +  +1x +2x +1x +1x + 
const BillBusiness = require("../business/bill.business");
+const billBusiness = new BillBusiness();
+ 
+/**
+ * Get all bills
+ */
+exports.getAllBills = async (req, res) => {
+ billBusiness.getAllBills(req.query)
+   .then((data) => {return res.status(200).send(data)})
+   .catch((error) => {
+    res.status(error.status).send({message: error.message})
+   })
+ 
+}
+ 
+/**
+ * Pay bill
+ */
+exports.payBill = async (req, res) => {
+ billBusiness.payBill(req.params.id)
+   .then(() => {res.status(200).send({message: "Bill paid."})})
+   .catch((error) => {res.status(error.status).send({message: error.message})})
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/index.html b/server/coverage/lcov-report/server/controllers/index.html new file mode 100644 index 0000000..d69bc26 --- /dev/null +++ b/server/coverage/lcov-report/server/controllers/index.html @@ -0,0 +1,131 @@ + + + + + + Code coverage report for server/controllers + + + + + + + + + +
+
+

All files server/controllers

+
+ +
+ 88.88% + Statements + 24/27 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 84.61% + Functions + 11/13 +
+ + +
+ 88.88% + Lines + 24/27 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
auth.controller.js +
+
88.23%15/17100%0/085.71%6/788.23%15/17
bill.controller.js +
+
90%9/10100%0/083.33%5/690%9/10
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/database/index.html b/server/coverage/lcov-report/server/database/index.html new file mode 100644 index 0000000..1210d29 --- /dev/null +++ b/server/coverage/lcov-report/server/database/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for server/database + + + + + + + + + +
+
+

All files server/database

+
+ +
+ 75% + Statements + 18/24 +
+ + +
+ 50% + Branches + 1/2 +
+ + +
+ 40% + Functions + 2/5 +
+ + +
+ 75% + Lines + 18/24 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
index.js +
+
75%18/2450%1/240%2/575%18/24
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/database/index.js.html b/server/coverage/lcov-report/server/database/index.js.html new file mode 100644 index 0000000..6dd9c1e --- /dev/null +++ b/server/coverage/lcov-report/server/database/index.js.html @@ -0,0 +1,244 @@ + + + + + + Code coverage report for server/database/index.js + + + + + + + + + +
+
+

All files / server/database index.js

+
+ +
+ 75% + Statements + 18/24 +
+ + +
+ 50% + Branches + 1/2 +
+ + +
+ 40% + Functions + 2/5 +
+ + +
+ 75% + Lines + 18/24 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54  +1x +1x +1x +1x +  +1x +1x +1x +1x +  +  +1x +1x +  +  +1x +  +  +  +  +  +1x +  +1x +  +  +  +  +  +  +  +  +1x +  +  +  +  +  +1x +  +  +  +  +  +  +1x +  +1x +  +2x +  +  + 
// Get database config
+const mongoose = require("mongoose");
+mongoose.Promise = global.Promise;
+const environment = process.env.NODE_ENV;
+let dbConfig = require("../config/db.config.js")[environment];
+ 
+const journey = require("../models/journey")(mongoose);
+const bill = require("../models/bill")(mongoose);
+const location = require("../models/location")(mongoose);
+const user = require("../models/user.model.js")(mongoose);
+ 
+// Create mongoose and read in config
+const db = { journey: journey, bill: bill, location: location, user: user };
+db.mongoose = mongoose;
+ 
+// For GITHUB ACTIONS - if null set it to testing
+Iif (!dbConfig) {
+    dbConfig = {
+        url: "mongodb://localhost:27017/highwaytrackerdb_testing",
+    };
+}
+ 
+db.url = dbConfig.url;
+ 
+db.mongoose.plugin((schema) => {
+    schema.pre("updateOne", setRunValidators);
+    schema.pre("findByIdAndUpdate", setRunValidators);
+});
+function setRunValidators() {
+    this.setOptions({ runValidators: true });
+}
+ 
+// Using the mongoose object, start the database
+db.mongoose
+    .connect(db.url, {
+        useNewUrlParser: true,
+        useUnifiedTopology: true,
+    })
+    .then(() => {
+        console.log("Connected to the database (" + environment + ")");
+    })
+    .catch((err) => {
+        console.log("Cannot connect to the database.", err);
+        process.exit();
+    });
+ 
+module.exports = db;
+ 
+module.exports = {
+    getModel: (modelName) => {
+        return db.mongoose.model(modelName);
+    },
+};
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/datalayer/index.html b/server/coverage/lcov-report/server/datalayer/index.html new file mode 100644 index 0000000..9583563 --- /dev/null +++ b/server/coverage/lcov-report/server/datalayer/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for server/datalayer + + + + + + + + + +
+
+

All files server/datalayer

+
+ +
+ 100% + Statements + 7/7 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 6/6 +
+ + +
+ 100% + Lines + 7/7 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
mongo.js +
+
100%7/7100%0/0100%6/6100%7/7
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/datalayer/mongo.js.html b/server/coverage/lcov-report/server/datalayer/mongo.js.html new file mode 100644 index 0000000..cc5354d --- /dev/null +++ b/server/coverage/lcov-report/server/datalayer/mongo.js.html @@ -0,0 +1,211 @@ + + + + + + Code coverage report for server/datalayer/mongo.js + + + + + + + + + +
+
+

All files / server/datalayer mongo.js

+
+ +
+ 100% + Statements + 7/7 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 6/6 +
+ + +
+ 100% + Lines + 7/7 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43  +  +  +2x +  +  +  +  +  +  +5x +  +  +  +  +  +  +  +  +  +2x +  +  +  +  +  +  +3x +  +  +  +  +  +  +2x +  +1x +  +  +  +  +1x + 
class DataLayer {
+    constructor(model) {
+        // Set the collections model to use.
+        this.model = model;
+    }
+ 
+    /**
+     * Find all records in the database.
+     */
+    async findAllAndPopulate(filter, populateFilter) {
+        return this.model.find(JSON.parse(JSON.stringify(filter)))
+          .limit(filter.limit)
+          .skip(filter.offset * filter.limit)
+          .populate(JSON.parse(JSON.stringify(populateFilter)))
+    }
+    
+    /**
+     * Find a record by property in the database.
+     */
+    async findByProperty(propertyToFind) {
+        return this.model.find(propertyToFind);
+    }
+    
+    /**
+     * Create and save the record to the database.
+     */
+    async create(recordToCreate) {
+        return this.model.create(recordToCreate);
+    }
+ 
+    /**
+     *  Update and save the record to the database.
+     */
+    async update(recordId, recordToUpdate) {
+        return this.model.findByIdAndUpdate(recordId, recordToUpdate)
+          .orFail(new Error("Bill can't be found in the database."))
+          .catch(error => {throw new Error(error.message)});
+ 
+    }
+}
+ 
+module.exports = DataLayer;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/index.html b/server/coverage/lcov-report/server/index.html new file mode 100644 index 0000000..89aa816 --- /dev/null +++ b/server/coverage/lcov-report/server/index.html @@ -0,0 +1,116 @@ + + + + + + Code coverage report for server + + + + + + + + + +
+
+

All files server

+
+ +
+ 100% + Statements + 24/24 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 24/24 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
app.js +
+
100%24/24100%0/0100%0/0100%24/24
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/bill.js.html b/server/coverage/lcov-report/server/models/bill.js.html new file mode 100644 index 0000000..5953d55 --- /dev/null +++ b/server/coverage/lcov-report/server/models/bill.js.html @@ -0,0 +1,160 @@ + + + + + + Code coverage report for server/models/bill.js + + + + + + + + + +
+
+

All files / server/models bill.js

+
+ +
+ 100% + Statements + 3/3 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 1/1 +
+ + +
+ 100% + Lines + 3/3 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +261x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x + 
module.exports = mongoose => {
+ const billSchema = mongoose.Schema(
+   {
+    journey: { 
+     type: mongoose.Schema.Types.ObjectId, 
+     ref: "journey",
+     required: [true, "A journey must be attached to a bill."],
+     unique: true
+    },
+    driver: { 
+     type: String,
+     required: [true, "A driver must be assigned to a bill."]
+    },
+    cost: {
+     type: Number,
+     required: [true, "A cost for the bill is required."]
+    },
+    paid: {
+     type: Boolean,
+     default: false
+    }
+   }
+ )
+ 
+ return mongoose.model("bill", billSchema)
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/index.html b/server/coverage/lcov-report/server/models/index.html new file mode 100644 index 0000000..b538f7b --- /dev/null +++ b/server/coverage/lcov-report/server/models/index.html @@ -0,0 +1,161 @@ + + + + + + Code coverage report for server/models + + + + + + + + + +
+
+

All files server/models

+
+ +
+ 100% + Statements + 12/12 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 4/4 +
+ + +
+ 100% + Lines + 12/12 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
bill.js +
+
100%3/3100%0/0100%1/1100%3/3
journey.js +
+
100%3/3100%0/0100%1/1100%3/3
location.js +
+
100%3/3100%0/0100%1/1100%3/3
user.model.js +
+
100%3/3100%0/0100%1/1100%3/3
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/journey.js.html b/server/coverage/lcov-report/server/models/journey.js.html new file mode 100644 index 0000000..bc8396e --- /dev/null +++ b/server/coverage/lcov-report/server/models/journey.js.html @@ -0,0 +1,157 @@ + + + + + + Code coverage report for server/models/journey.js + + + + + + + + + +
+
+

All files / server/models journey.js

+
+ +
+ 100% + Statements + 3/3 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 1/1 +
+ + +
+ 100% + Lines + 3/3 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +251x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x + 
module.exports = mongoose => {
+ const journeySchema = mongoose.Schema(
+   {
+    regNumber: {
+     type: "String",
+     required: [true, "A car registration number is required"]
+    },
+    entryLocation: {
+     type: mongoose.Schema.Types.ObjectId, 
+     ref: "location",
+     required: [true, "A entry location is required."]
+    },
+    exitLocation: {
+     type: mongoose.Schema.Types.ObjectId, 
+     ref: "location",
+     required: [true, "A exit location is required."]
+    },
+    journeyDateTime: {
+     type: Date
+    }
+   }
+ )
+ 
+ return mongoose.model("journey", journeySchema)
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/location.js.html b/server/coverage/lcov-report/server/models/location.js.html new file mode 100644 index 0000000..74a2bc2 --- /dev/null +++ b/server/coverage/lcov-report/server/models/location.js.html @@ -0,0 +1,148 @@ + + + + + + Code coverage report for server/models/location.js + + + + + + + + + +
+
+

All files / server/models location.js

+
+ +
+ 100% + Statements + 3/3 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 1/1 +
+ + +
+ 100% + Lines + 3/3 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +221x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x + 
module.exports = mongoose => {
+ const locationSchema = mongoose.Schema(
+   {
+    name: {
+     type: "String",
+     required: [true, "A location name is required"]
+    },
+    coordinates: {
+      longitude: {
+       type: "Number",
+       required: [true, "A longitude is required"]
+      },
+      latitude: {
+       type: "Number",
+       required: [true, "A latitude is required"]
+      }
+    }
+   }
+ )
+ 
+ return mongoose.model("location", locationSchema)
+}
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/user.model.js.html b/server/coverage/lcov-report/server/models/user.model.js.html new file mode 100644 index 0000000..6402aa1 --- /dev/null +++ b/server/coverage/lcov-report/server/models/user.model.js.html @@ -0,0 +1,178 @@ + + + + + + Code coverage report for server/models/user.model.js + + + + + + + + + +
+
+

All files / server/models user.model.js

+
+ +
+ 100% + Statements + 3/3 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 1/1 +
+ + +
+ 100% + Lines + 3/3 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32  +1x +1x +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +  +1x +  + 
// Model for the User
+module.exports = (mongoose) => {
+    var UserSchema = mongoose.Schema({
+        username: {
+            type: String,
+            required: [true, "You must supply the user's username."],
+            minlength: [5, "Your username must be at least 5 letters."],
+            unique: true,
+        },
+        email: {
+            type: String,
+            required: [true, "You must supply the user's email."],
+            unique: true,
+        },
+        password: {
+            type: String,
+            required: [true, "You must supply the user's password"],
+            minlength: [5, "Your password must be at least 8 letters."],
+        },
+        type: {
+            type: String,
+            required: [true, "You must supply the user's role."],
+            enum: {
+                values: ["Driver", "Toll Operator"],
+                message: "Type is not valid. Must be 'Driver'.",
+            },
+        },
+    });
+ 
+    return mongoose.model("user", UserSchema);
+};
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/routes/auth.routes.js.html b/server/coverage/lcov-report/server/routes/auth.routes.js.html new file mode 100644 index 0000000..6c109b7 --- /dev/null +++ b/server/coverage/lcov-report/server/routes/auth.routes.js.html @@ -0,0 +1,133 @@ + + + + + + Code coverage report for server/routes/auth.routes.js + + + + + + + + + +
+
+

All files / server/routes auth.routes.js

+
+ +
+ 100% + Statements + 7/7 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 7/7 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +171x +1x +  +  +1x +  +  +1x +  +  +1x +  +  +1x +  +1x + 
const express = require("express");
+const router = express.Router();
+ 
+// Get the Auth controller
+const authController = require("../controllers/auth.controller");
+ 
+// Log the user in
+router.post("/login/", authController.login);
+ 
+// Register the user
+router.post("/register/", authController.register);
+ 
+// Log the user out
+router.post("/logout/", authController.logout);
+ 
+module.exports = router;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/routes/bill.routes.js.html b/server/coverage/lcov-report/server/routes/bill.routes.js.html new file mode 100644 index 0000000..6257856 --- /dev/null +++ b/server/coverage/lcov-report/server/routes/bill.routes.js.html @@ -0,0 +1,124 @@ + + + + + + Code coverage report for server/routes/bill.routes.js + + + + + + + + + +
+
+

All files / server/routes bill.routes.js

+
+ +
+ 100% + Statements + 6/6 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 6/6 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+

+
1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +141x +1x +  +  +1x +  +  +1x +  +  +1x +  +1x + 
const express = require("express");
+const router = express.Router();
+ 
+// Get the Bill controller
+const billController = require("../controllers/bill.controller");
+ 
+// Get All Bills
+router.get("/", billController.getAllBills);
+ 
+// Pay for bill
+router.put("/:id", billController.payBill);
+ 
+module.exports = router;
+ 
+ +
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/server/routes/index.html b/server/coverage/lcov-report/server/routes/index.html new file mode 100644 index 0000000..e5a4ed9 --- /dev/null +++ b/server/coverage/lcov-report/server/routes/index.html @@ -0,0 +1,131 @@ + + + + + + Code coverage report for server/routes + + + + + + + + + +
+
+

All files server/routes

+
+ +
+ 100% + Statements + 13/13 +
+ + +
+ 100% + Branches + 0/0 +
+ + +
+ 100% + Functions + 0/0 +
+ + +
+ 100% + Lines + 13/13 +
+ + +
+

+ Press n or j to go to the next uncovered block, b, p or k for the previous block. +

+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
FileStatementsBranchesFunctionsLines
auth.routes.js +
+
100%7/7100%0/0100%0/0100%7/7
bill.routes.js +
+
100%6/6100%0/0100%0/0100%6/6
+
+
+
+ + + + + + + + \ No newline at end of file diff --git a/server/coverage/lcov-report/sort-arrow-sprite.png b/server/coverage/lcov-report/sort-arrow-sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..03f704a609c6fd0dbfdac63466a7d7c958b5cbf3 GIT binary patch literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^>_9Bd!3HEZxJ@+%Qj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jii$m5978H@?Fn+^JD|Y9yzj{W`447Gxa{7*dM7nnnD-Lb z6^}Hx2)'; + } + } + return cols; + } + // attaches a data attribute to every tr element with an object + // of data values keyed by column name + function loadRowData(tableRow) { + var tableCols = tableRow.querySelectorAll('td'), + colNode, + col, + data = {}, + i, + val; + for (i = 0; i < tableCols.length; i += 1) { + colNode = tableCols[i]; + col = cols[i]; + val = colNode.getAttribute('data-value'); + if (col.type === 'number') { + val = Number(val); + } + data[col.key] = val; + } + return data; + } + // loads all row data + function loadData() { + var rows = getTableBody().querySelectorAll('tr'), + i; + + for (i = 0; i < rows.length; i += 1) { + rows[i].data = loadRowData(rows[i]); + } + } + // sorts the table using the data for the ith column + function sortByIndex(index, desc) { + var key = cols[index].key, + sorter = function(a, b) { + a = a.data[key]; + b = b.data[key]; + return a < b ? -1 : a > b ? 1 : 0; + }, + finalSorter = sorter, + tableBody = document.querySelector('.coverage-summary tbody'), + rowNodes = tableBody.querySelectorAll('tr'), + rows = [], + i; + + if (desc) { + finalSorter = function(a, b) { + return -1 * sorter(a, b); + }; + } + + for (i = 0; i < rowNodes.length; i += 1) { + rows.push(rowNodes[i]); + tableBody.removeChild(rowNodes[i]); + } + + rows.sort(finalSorter); + + for (i = 0; i < rows.length; i += 1) { + tableBody.appendChild(rows[i]); + } + } + // removes sort indicators for current column being sorted + function removeSortIndicators() { + var col = getNthColumn(currentSort.index), + cls = col.className; + + cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); + col.className = cls; + } + // adds sort indicators for current column being sorted + function addSortIndicators() { + getNthColumn(currentSort.index).className += currentSort.desc + ? ' sorted-desc' + : ' sorted'; + } + // adds event listeners for all sorter widgets + function enableUI() { + var i, + el, + ithSorter = function ithSorter(i) { + var col = cols[i]; + + return function() { + var desc = col.defaultDescSort; + + if (currentSort.index === i) { + desc = !currentSort.desc; + } + sortByIndex(i, desc); + removeSortIndicators(); + currentSort.index = i; + currentSort.desc = desc; + addSortIndicators(); + }; + }; + for (i = 0; i < cols.length; i += 1) { + if (cols[i].sortable) { + // add the click event handler on the th so users + // dont have to click on those tiny arrows + el = getNthColumn(i).querySelector('.sorter').parentElement; + if (el.addEventListener) { + el.addEventListener('click', ithSorter(i)); + } else { + el.attachEvent('onclick', ithSorter(i)); + } + } + } + } + // adds sorting functionality to the UI + return function() { + if (!getTable()) { + return; + } + cols = loadColumns(); + loadData(); + addSearchBox(); + addSortIndicators(); + enableUI(); + }; +})(); + +window.addEventListener('load', addSorting); diff --git a/server/coverage/lcov.info b/server/coverage/lcov.info new file mode 100644 index 0000000..5e328df --- /dev/null +++ b/server/coverage/lcov.info @@ -0,0 +1,379 @@ +TN: +SF:app.js +FNF:0 +FNH:0 +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:6,1 +DA:8,1 +DA:9,1 +DA:11,1 +DA:13,1 +DA:22,1 +DA:27,1 +DA:28,1 +DA:32,1 +DA:33,1 +DA:34,1 +DA:35,1 +DA:36,1 +DA:37,1 +DA:38,1 +DA:39,1 +DA:42,1 +DA:43,1 +DA:45,1 +LF:24 +LH:24 +BRF:0 +BRH:0 +end_of_record +TN: +SF:business\bill.business.js +FN:6,(anonymous_0) +FN:14,(anonymous_1) +FN:28,(anonymous_2) +FN:33,(anonymous_3) +FNF:4 +FNH:4 +FNDA:1,(anonymous_0) +FNDA:5,(anonymous_1) +FNDA:2,(anonymous_2) +FNDA:1,(anonymous_3) +DA:1,1 +DA:2,1 +DA:3,1 +DA:5,1 +DA:8,1 +DA:15,5 +DA:21,5 +DA:29,2 +DA:32,2 +DA:33,1 +LF:10 +LH:10 +BRDA:18,0,0,5 +BRDA:18,0,1,4 +BRDA:19,1,0,5 +BRDA:19,1,1,4 +BRF:4 +BRH:4 +end_of_record +TN: +SF:business\user.business.js +FN:8,(anonymous_0) +FN:16,(anonymous_1) +FN:18,(anonymous_2) +FN:50,(anonymous_3) +FN:57,(anonymous_4) +FN:63,(anonymous_5) +FN:71,(anonymous_6) +FN:82,(anonymous_7) +FN:94,(anonymous_8) +FN:97,(anonymous_9) +FN:101,(anonymous_10) +FN:110,isUserDataValid +FNF:12 +FNH:11 +FNDA:1,(anonymous_0) +FNDA:2,(anonymous_1) +FNDA:2,(anonymous_2) +FNDA:1,(anonymous_3) +FNDA:3,(anonymous_4) +FNDA:2,(anonymous_5) +FNDA:3,(anonymous_6) +FNDA:2,(anonymous_7) +FNDA:2,(anonymous_8) +FNDA:2,(anonymous_9) +FNDA:0,(anonymous_10) +FNDA:3,isUserDataValid +DA:1,1 +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:7,1 +DA:10,1 +DA:17,2 +DA:19,2 +DA:24,2 +DA:25,1 +DA:31,1 +DA:43,1 +DA:50,1 +DA:58,3 +DA:64,2 +DA:72,3 +DA:73,0 +DA:75,3 +DA:82,3 +DA:83,2 +DA:84,1 +DA:85,1 +DA:86,1 +DA:87,0 +DA:95,2 +DA:99,2 +DA:102,0 +DA:111,3 +LF:29 +LH:26 +BRDA:24,0,0,1 +BRDA:24,0,1,1 +BRDA:72,1,0,0 +BRDA:72,1,1,3 +BRDA:83,2,0,1 +BRDA:83,2,1,1 +BRDA:85,3,0,1 +BRDA:85,3,1,0 +BRDA:111,4,0,3 +BRDA:111,4,1,3 +BRDA:111,4,2,3 +BRDA:111,4,3,3 +BRF:12 +BRH:10 +end_of_record +TN: +SF:config\db.config.js +FNF:0 +FNH:0 +DA:1,1 +LF:1 +LH:1 +BRF:0 +BRH:0 +end_of_record +TN: +SF:controllers\auth.controller.js +FN:7,(anonymous_0) +FN:10,(anonymous_1) +FN:23,(anonymous_2) +FN:31,(anonymous_3) +FN:34,(anonymous_4) +FN:39,(anonymous_5) +FN:47,(anonymous_6) +FNF:7 +FNH:6 +FNDA:2,(anonymous_0) +FNDA:1,(anonymous_1) +FNDA:1,(anonymous_2) +FNDA:3,(anonymous_3) +FNDA:1,(anonymous_4) +FNDA:2,(anonymous_5) +FNDA:0,(anonymous_6) +DA:1,1 +DA:2,1 +DA:7,1 +DA:8,2 +DA:11,1 +DA:12,1 +DA:13,1 +DA:14,1 +DA:16,1 +DA:24,1 +DA:31,1 +DA:32,3 +DA:35,1 +DA:40,2 +DA:47,1 +DA:48,0 +DA:49,0 +LF:17 +LH:15 +BRF:0 +BRH:0 +end_of_record +TN: +SF:controllers\bill.controller.js +FN:7,(anonymous_0) +FN:9,(anonymous_1) +FN:10,(anonymous_2) +FN:19,(anonymous_3) +FN:21,(anonymous_4) +FN:22,(anonymous_5) +FNF:6 +FNH:5 +FNDA:5,(anonymous_0) +FNDA:5,(anonymous_1) +FNDA:0,(anonymous_2) +FNDA:2,(anonymous_3) +FNDA:1,(anonymous_4) +FNDA:1,(anonymous_5) +DA:1,1 +DA:2,1 +DA:7,1 +DA:8,5 +DA:9,5 +DA:11,0 +DA:19,1 +DA:20,2 +DA:21,1 +DA:22,1 +LF:10 +LH:9 +BRF:0 +BRH:0 +end_of_record +TN: +SF:database\index.js +FN:25,(anonymous_0) +FN:29,setRunValidators +FN:39,(anonymous_2) +FN:42,(anonymous_3) +FN:50,(anonymous_4) +FNF:5 +FNH:2 +FNDA:0,(anonymous_0) +FNDA:0,setRunValidators +FNDA:1,(anonymous_2) +FNDA:0,(anonymous_3) +FNDA:2,(anonymous_4) +DA:2,1 +DA:3,1 +DA:4,1 +DA:5,1 +DA:7,1 +DA:8,1 +DA:9,1 +DA:10,1 +DA:13,1 +DA:14,1 +DA:17,1 +DA:18,0 +DA:23,1 +DA:25,1 +DA:26,0 +DA:27,0 +DA:30,0 +DA:34,1 +DA:40,1 +DA:43,0 +DA:44,0 +DA:47,1 +DA:49,1 +DA:51,2 +LF:24 +LH:18 +BRDA:17,0,0,0 +BRDA:17,0,1,1 +BRF:2 +BRH:1 +end_of_record +TN: +SF:datalayer\mongo.js +FN:2,(anonymous_0) +FN:10,(anonymous_1) +FN:20,(anonymous_2) +FN:27,(anonymous_3) +FN:34,(anonymous_4) +FN:37,(anonymous_5) +FNF:6 +FNH:6 +FNDA:2,(anonymous_0) +FNDA:5,(anonymous_1) +FNDA:2,(anonymous_2) +FNDA:3,(anonymous_3) +FNDA:2,(anonymous_4) +FNDA:1,(anonymous_5) +DA:4,2 +DA:11,5 +DA:21,2 +DA:28,3 +DA:35,2 +DA:37,1 +DA:42,1 +LF:7 +LH:7 +BRF:0 +BRH:0 +end_of_record +TN: +SF:models\bill.js +FN:1,(anonymous_0) +FNF:1 +FNH:1 +FNDA:1,(anonymous_0) +DA:1,1 +DA:2,1 +DA:25,1 +LF:3 +LH:3 +BRF:0 +BRH:0 +end_of_record +TN: +SF:models\journey.js +FN:1,(anonymous_0) +FNF:1 +FNH:1 +FNDA:1,(anonymous_0) +DA:1,1 +DA:2,1 +DA:24,1 +LF:3 +LH:3 +BRF:0 +BRH:0 +end_of_record +TN: +SF:models\location.js +FN:1,(anonymous_0) +FNF:1 +FNH:1 +FNDA:1,(anonymous_0) +DA:1,1 +DA:2,1 +DA:21,1 +LF:3 +LH:3 +BRF:0 +BRH:0 +end_of_record +TN: +SF:models\user.model.js +FN:2,(anonymous_0) +FNF:1 +FNH:1 +FNDA:1,(anonymous_0) +DA:2,1 +DA:3,1 +DA:30,1 +LF:3 +LH:3 +BRF:0 +BRH:0 +end_of_record +TN: +SF:routes\auth.routes.js +FNF:0 +FNH:0 +DA:1,1 +DA:2,1 +DA:5,1 +DA:8,1 +DA:11,1 +DA:14,1 +DA:16,1 +LF:7 +LH:7 +BRF:0 +BRH:0 +end_of_record +TN: +SF:routes\bill.routes.js +FNF:0 +FNH:0 +DA:1,1 +DA:2,1 +DA:5,1 +DA:8,1 +DA:11,1 +DA:13,1 +LF:6 +LH:6 +BRF:0 +BRH:0 +end_of_record diff --git a/server/package.json b/server/package.json index 8a85949..d249be5 100644 --- a/server/package.json +++ b/server/package.json @@ -1,7 +1,7 @@ { "scripts": { "start": "set NODE_ENV=dev&& node ./bin/www", - "test": "set NODE_ENV=test&& node ./database/seed.js && nyc mocha --recursive --timeout 5000 --exit" + "test": "set NODE_ENV=test&& node ./database/seed.js && nyc --reporter lcov mocha --recursive --timeout 5000 --exit" }, "dependencies": { "bcryptjs": "^2.4.3", diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js index 5c07062..eec3c14 100644 --- a/server/test/integration/bill.controller.test.js +++ b/server/test/integration/bill.controller.test.js @@ -128,14 +128,13 @@ describe("Testing /bill paths", () => { // Arrange const offset = 1 const url = `/bill?offset=${offset}` - console.log("ARRANGE") + // Act chai.request(server) .get(url) .send() .end((err, res) => { // Assert - console.log("ASSERT" + res.body) res.should.have.status(200); res.should.be.a("object"); From 9732dd12cb89ee6fafc2e63d2abaaaae85ee75ef Mon Sep 17 00:00:00 2001 From: jarrodback Date: Tue, 1 Feb 2022 17:20:26 +0000 Subject: [PATCH 16/31] HT-14 Update yml to authenticate coverage report --- .github/workflows/node.js.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 3b870ab..8aa4790 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -53,6 +53,7 @@ jobs: uses: romeovs/lcov-reporter-action@v0.2.16 with: lcov-file: ./server/coverage/lcov.info + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Deploy uses: JamesIves/github-pages-deploy-action@v4.2.3 with: From a9e6c504a519b5f2407c6e3b5da681e0501b7dca Mon Sep 17 00:00:00 2001 From: jarrodback Date: Tue, 1 Feb 2022 17:31:57 +0000 Subject: [PATCH 17/31] HT-14 Attempt to fix sonar and deployment --- .github/workflows/node.js.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 8aa4790..7ce03a5 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -58,4 +58,4 @@ jobs: uses: JamesIves/github-pages-deploy-action@v4.2.3 with: branch: gh-pages - folder: . \ No newline at end of file + folder: ./ui/dist/ \ No newline at end of file From ea707b33698fc73ecfa9e9e0adb1e58d6c3e4c10 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Tue, 1 Feb 2022 17:40:53 +0000 Subject: [PATCH 18/31] HT-14 Rename action --- .github/workflows/node.js.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 7ce03a5..a6269aa 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -1,7 +1,7 @@ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions -name: Node.js CI +name: Build-Test-Deploy Pipeline on: push: @@ -36,15 +36,15 @@ jobs: cd server npm ci npm run build --if-present - - name: Server - run tests - run: | - cd server - npm test - name: UI - run build run: | cd ui npm ci npm run build --if-present + - name: Server - run tests + run: | + cd server + npm test - name: UI - run tests run: | cd ui From 58b4fd64f04153c06e6186711f9ef1d601045879 Mon Sep 17 00:00:00 2001 From: jarrodback Date: Tue, 1 Feb 2022 17:47:56 +0000 Subject: [PATCH 19/31] HT-14 Run pipeline on every commit --- .github/workflows/node.js.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index a6269aa..9ecbe25 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -4,8 +4,6 @@ name: Build-Test-Deploy Pipeline on: - push: - branches: [ develop ] pull_request: branches: [ develop ] From 1b8e315946de31752b4304f4c2883e9b53326080 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 10:21:39 +0000 Subject: [PATCH 20/31] Remove lcov folder and add to .gitignore --- .gitignore | 3 +- server/coverage/lcov-report/base.css | 224 ---------- .../coverage/lcov-report/block-navigation.js | 87 ---- server/coverage/lcov-report/favicon.png | Bin 540 -> 0 bytes server/coverage/lcov-report/index.html | 221 --------- server/coverage/lcov-report/prettify.css | 1 - server/coverage/lcov-report/prettify.js | 2 - .../coverage/lcov-report/server/app.js.html | 220 --------- .../server/business/bill.business.js.html | 190 -------- .../lcov-report/server/business/index.html | 131 ------ .../server/business/user.business.js.html | 421 ------------------ .../server/config/db.config.js.html | 109 ----- .../lcov-report/server/config/index.html | 116 ----- .../controllers/auth.controller.js.html | 241 ---------- .../controllers/bill.controller.js.html | 151 ------- .../lcov-report/server/controllers/index.html | 131 ------ .../lcov-report/server/database/index.html | 116 ----- .../lcov-report/server/database/index.js.html | 244 ---------- .../lcov-report/server/datalayer/index.html | 116 ----- .../server/datalayer/mongo.js.html | 211 --------- server/coverage/lcov-report/server/index.html | 116 ----- .../lcov-report/server/models/bill.js.html | 160 ------- .../lcov-report/server/models/index.html | 161 ------- .../lcov-report/server/models/journey.js.html | 157 ------- .../server/models/location.js.html | 148 ------ .../server/models/user.model.js.html | 178 -------- .../server/routes/auth.routes.js.html | 133 ------ .../server/routes/bill.routes.js.html | 124 ------ .../lcov-report/server/routes/index.html | 131 ------ .../lcov-report/sort-arrow-sprite.png | Bin 209 -> 0 bytes server/coverage/lcov-report/sorter.js | 196 -------- 31 files changed, 2 insertions(+), 4437 deletions(-) delete mode 100644 server/coverage/lcov-report/base.css delete mode 100644 server/coverage/lcov-report/block-navigation.js delete mode 100644 server/coverage/lcov-report/favicon.png delete mode 100644 server/coverage/lcov-report/index.html delete mode 100644 server/coverage/lcov-report/prettify.css delete mode 100644 server/coverage/lcov-report/prettify.js delete mode 100644 server/coverage/lcov-report/server/app.js.html delete mode 100644 server/coverage/lcov-report/server/business/bill.business.js.html delete mode 100644 server/coverage/lcov-report/server/business/index.html delete mode 100644 server/coverage/lcov-report/server/business/user.business.js.html delete mode 100644 server/coverage/lcov-report/server/config/db.config.js.html delete mode 100644 server/coverage/lcov-report/server/config/index.html delete mode 100644 server/coverage/lcov-report/server/controllers/auth.controller.js.html delete mode 100644 server/coverage/lcov-report/server/controllers/bill.controller.js.html delete mode 100644 server/coverage/lcov-report/server/controllers/index.html delete mode 100644 server/coverage/lcov-report/server/database/index.html delete mode 100644 server/coverage/lcov-report/server/database/index.js.html delete mode 100644 server/coverage/lcov-report/server/datalayer/index.html delete mode 100644 server/coverage/lcov-report/server/datalayer/mongo.js.html delete mode 100644 server/coverage/lcov-report/server/index.html delete mode 100644 server/coverage/lcov-report/server/models/bill.js.html delete mode 100644 server/coverage/lcov-report/server/models/index.html delete mode 100644 server/coverage/lcov-report/server/models/journey.js.html delete mode 100644 server/coverage/lcov-report/server/models/location.js.html delete mode 100644 server/coverage/lcov-report/server/models/user.model.js.html delete mode 100644 server/coverage/lcov-report/server/routes/auth.routes.js.html delete mode 100644 server/coverage/lcov-report/server/routes/bill.routes.js.html delete mode 100644 server/coverage/lcov-report/server/routes/index.html delete mode 100644 server/coverage/lcov-report/sort-arrow-sprite.png delete mode 100644 server/coverage/lcov-report/sorter.js diff --git a/.gitignore b/.gitignore index e822182..6ae5f2a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ node_modules /dist server/.nyc_output/*.json server/.nyc_output/processinfo/*.json +server/coverage/lcov-report # local env files .env.local @@ -22,4 +23,4 @@ pnpm-debug.log* *.ntvs* *.njsproj *.sln -*.sw? +*.sw? \ No newline at end of file diff --git a/server/coverage/lcov-report/base.css b/server/coverage/lcov-report/base.css deleted file mode 100644 index f418035..0000000 --- a/server/coverage/lcov-report/base.css +++ /dev/null @@ -1,224 +0,0 @@ -body, html { - margin:0; padding: 0; - height: 100%; -} -body { - font-family: Helvetica Neue, Helvetica, Arial; - font-size: 14px; - color:#333; -} -.small { font-size: 12px; } -*, *:after, *:before { - -webkit-box-sizing:border-box; - -moz-box-sizing:border-box; - box-sizing:border-box; - } -h1 { font-size: 20px; margin: 0;} -h2 { font-size: 14px; } -pre { - font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; - margin: 0; - padding: 0; - -moz-tab-size: 2; - -o-tab-size: 2; - tab-size: 2; -} -a { color:#0074D9; text-decoration:none; } -a:hover { text-decoration:underline; } -.strong { font-weight: bold; } -.space-top1 { padding: 10px 0 0 0; } -.pad2y { padding: 20px 0; } -.pad1y { padding: 10px 0; } -.pad2x { padding: 0 20px; } -.pad2 { padding: 20px; } -.pad1 { padding: 10px; } -.space-left2 { padding-left:55px; } -.space-right2 { padding-right:20px; } -.center { text-align:center; } -.clearfix { display:block; } -.clearfix:after { - content:''; - display:block; - height:0; - clear:both; - visibility:hidden; - } -.fl { float: left; } -@media only screen and (max-width:640px) { - .col3 { width:100%; max-width:100%; } - .hide-mobile { display:none!important; } -} - -.quiet { - color: #7f7f7f; - color: rgba(0,0,0,0.5); -} -.quiet a { opacity: 0.7; } - -.fraction { - font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; - font-size: 10px; - color: #555; - background: #E8E8E8; - padding: 4px 5px; - border-radius: 3px; - vertical-align: middle; -} - -div.path a:link, div.path a:visited { color: #333; } -table.coverage { - border-collapse: collapse; - margin: 10px 0 0 0; - padding: 0; -} - -table.coverage td { - margin: 0; - padding: 0; - vertical-align: top; -} -table.coverage td.line-count { - text-align: right; - padding: 0 5px 0 20px; -} -table.coverage td.line-coverage { - text-align: right; - padding-right: 10px; - min-width:20px; -} - -table.coverage td span.cline-any { - display: inline-block; - padding: 0 5px; - width: 100%; -} -.missing-if-branch { - display: inline-block; - margin-right: 5px; - border-radius: 3px; - position: relative; - padding: 0 4px; - background: #333; - color: yellow; -} - -.skip-if-branch { - display: none; - margin-right: 10px; - position: relative; - padding: 0 4px; - background: #ccc; - color: white; -} -.missing-if-branch .typ, .skip-if-branch .typ { - color: inherit !important; -} -.coverage-summary { - border-collapse: collapse; - width: 100%; -} -.coverage-summary tr { border-bottom: 1px solid #bbb; } -.keyline-all { border: 1px solid #ddd; } -.coverage-summary td, .coverage-summary th { padding: 10px; } -.coverage-summary tbody { border: 1px solid #bbb; } -.coverage-summary td { border-right: 1px solid #bbb; } -.coverage-summary td:last-child { border-right: none; } -.coverage-summary th { - text-align: left; - font-weight: normal; - white-space: nowrap; -} -.coverage-summary th.file { border-right: none !important; } -.coverage-summary th.pct { } -.coverage-summary th.pic, -.coverage-summary th.abs, -.coverage-summary td.pct, -.coverage-summary td.abs { text-align: right; } -.coverage-summary td.file { white-space: nowrap; } -.coverage-summary td.pic { min-width: 120px !important; } -.coverage-summary tfoot td { } - -.coverage-summary .sorter { - height: 10px; - width: 7px; - display: inline-block; - margin-left: 0.5em; - background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; -} -.coverage-summary .sorted .sorter { - background-position: 0 -20px; -} -.coverage-summary .sorted-desc .sorter { - background-position: 0 -10px; -} -.status-line { height: 10px; } -/* yellow */ -.cbranch-no { background: yellow !important; color: #111; } -/* dark red */ -.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } -.low .chart { border:1px solid #C21F39 } -.highlighted, -.highlighted .cstat-no, .highlighted .fstat-no, .highlighted .cbranch-no{ - background: #C21F39 !important; -} -/* medium red */ -.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } -/* light red */ -.low, .cline-no { background:#FCE1E5 } -/* light green */ -.high, .cline-yes { background:rgb(230,245,208) } -/* medium green */ -.cstat-yes { background:rgb(161,215,106) } -/* dark green */ -.status-line.high, .high .cover-fill { background:rgb(77,146,33) } -.high .chart { border:1px solid rgb(77,146,33) } -/* dark yellow (gold) */ -.status-line.medium, .medium .cover-fill { background: #f9cd0b; } -.medium .chart { border:1px solid #f9cd0b; } -/* light yellow */ -.medium { background: #fff4c2; } - -.cstat-skip { background: #ddd; color: #111; } -.fstat-skip { background: #ddd; color: #111 !important; } -.cbranch-skip { background: #ddd !important; color: #111; } - -span.cline-neutral { background: #eaeaea; } - -.coverage-summary td.empty { - opacity: .5; - padding-top: 4px; - padding-bottom: 4px; - line-height: 1; - color: #888; -} - -.cover-fill, .cover-empty { - display:inline-block; - height: 12px; -} -.chart { - line-height: 0; -} -.cover-empty { - background: white; -} -.cover-full { - border-right: none !important; -} -pre.prettyprint { - border: none !important; - padding: 0 !important; - margin: 0 !important; -} -.com { color: #999 !important; } -.ignore-none { color: #999; font-weight: normal; } - -.wrapper { - min-height: 100%; - height: auto !important; - height: 100%; - margin: 0 auto -48px; -} -.footer, .push { - height: 48px; -} diff --git a/server/coverage/lcov-report/block-navigation.js b/server/coverage/lcov-report/block-navigation.js deleted file mode 100644 index cc12130..0000000 --- a/server/coverage/lcov-report/block-navigation.js +++ /dev/null @@ -1,87 +0,0 @@ -/* eslint-disable */ -var jumpToCode = (function init() { - // Classes of code we would like to highlight in the file view - var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no']; - - // Elements to highlight in the file listing view - var fileListingElements = ['td.pct.low']; - - // We don't want to select elements that are direct descendants of another match - var notSelector = ':not(' + missingCoverageClasses.join('):not(') + ') > '; // becomes `:not(a):not(b) > ` - - // Selecter that finds elements on the page to which we can jump - var selector = - fileListingElements.join(', ') + - ', ' + - notSelector + - missingCoverageClasses.join(', ' + notSelector); // becomes `:not(a):not(b) > a, :not(a):not(b) > b` - - // The NodeList of matching elements - var missingCoverageElements = document.querySelectorAll(selector); - - var currentIndex; - - function toggleClass(index) { - missingCoverageElements - .item(currentIndex) - .classList.remove('highlighted'); - missingCoverageElements.item(index).classList.add('highlighted'); - } - - function makeCurrent(index) { - toggleClass(index); - currentIndex = index; - missingCoverageElements.item(index).scrollIntoView({ - behavior: 'smooth', - block: 'center', - inline: 'center' - }); - } - - function goToPrevious() { - var nextIndex = 0; - if (typeof currentIndex !== 'number' || currentIndex === 0) { - nextIndex = missingCoverageElements.length - 1; - } else if (missingCoverageElements.length > 1) { - nextIndex = currentIndex - 1; - } - - makeCurrent(nextIndex); - } - - function goToNext() { - var nextIndex = 0; - - if ( - typeof currentIndex === 'number' && - currentIndex < missingCoverageElements.length - 1 - ) { - nextIndex = currentIndex + 1; - } - - makeCurrent(nextIndex); - } - - return function jump(event) { - if ( - document.getElementById('fileSearch') === document.activeElement && - document.activeElement != null - ) { - // if we're currently focused on the search input, we don't want to navigate - return; - } - - switch (event.which) { - case 78: // n - case 74: // j - goToNext(); - break; - case 66: // b - case 75: // k - case 80: // p - goToPrevious(); - break; - } - }; -})(); -window.addEventListener('keydown', jumpToCode); diff --git a/server/coverage/lcov-report/favicon.png b/server/coverage/lcov-report/favicon.png deleted file mode 100644 index 6691817834a957c938e7f09640a37a645fb31457..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 540 zcmV+%0^|LOP)wSzy{h>9elhJ=8GnBQmf?)AI(^#wDA_`!QTxaXXE&bjxo zTGCc%V|W`}Lwz0rDO*qBbGY-M@aNENIZ1rK?nOAibaC*vb%CF;I_~lkJawax%_+1J zLn(#pv_v{f0`v`Cfp6()7MB(>IoTAiQdKxgxX?VyV&KVZ7b$vn<8|Z<9$35C+G_8SH0x6Y(xB&~bmn%r}ceRwbc0000 - - - - Code coverage report for All files - - - - - - - - - -
-
-

All files

-
- -
- 91.83% - Statements - 135/147 -
- - -
- 83.33% - Branches - 15/18 -
- - -
- 86.36% - Functions - 38/44 -
- - -
- 91.83% - Lines - 135/147 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
server -
-
100%24/24100%0/0100%0/0100%24/24
server/business -
-
92.3%36/3987.5%14/1693.75%15/1692.3%36/39
server/config -
-
100%1/1100%0/0100%0/0100%1/1
server/controllers -
-
88.88%24/27100%0/084.61%11/1388.88%24/27
server/database -
-
75%18/2450%1/240%2/575%18/24
server/datalayer -
-
100%7/7100%0/0100%6/6100%7/7
server/models -
-
100%12/12100%0/0100%4/4100%12/12
server/routes -
-
100%13/13100%0/0100%0/0100%13/13
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/prettify.css b/server/coverage/lcov-report/prettify.css deleted file mode 100644 index b317a7c..0000000 --- a/server/coverage/lcov-report/prettify.css +++ /dev/null @@ -1 +0,0 @@ -.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} diff --git a/server/coverage/lcov-report/prettify.js b/server/coverage/lcov-report/prettify.js deleted file mode 100644 index b322523..0000000 --- a/server/coverage/lcov-report/prettify.js +++ /dev/null @@ -1,2 +0,0 @@ -/* eslint-disable */ -window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); diff --git a/server/coverage/lcov-report/server/app.js.html b/server/coverage/lcov-report/server/app.js.html deleted file mode 100644 index 8d4c6e4..0000000 --- a/server/coverage/lcov-report/server/app.js.html +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - Code coverage report for server/app.js - - - - - - - - - -
-
-

All files / server app.js

-
- -
- 100% - Statements - 24/24 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 0/0 -
- - -
- 100% - Lines - 24/24 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -461x -1x -1x -1x -1x -1x -  -1x -1x -  -1x -  -1x -  -  -  -  -  -  -  -  -1x -  -  -  -  -1x -1x -  -  -  -1x -1x -1x -1x -1x -1x -1x -1x -  -  -1x -1x -  -1x - 
const express = require("express");
-const path = require("path");
-const bodyParser = require("body-parser");
-const cors = require("cors");
-const cookieSession = require("cookie-session");
-const cookieParser = require("cookie-parser");
- 
-require("./database");
-require("dotenv").config();
- 
-const app = express();
- 
-app.use(
-    cookieSession({
-        name: "highwayTracker-token",
-        secret: process.env.TOKEN_SECRET,
-        httpOnly: true,
-        keys: [process.env.TOKEN_SECRET],
-    })
-);
- 
-app.use(cors({ origin: "http://localhost:8080", credentials: true }));
- 
-/**
- * Router setup
- */
-const authRouter = require("./routes/auth.routes");
-const billRouter = require("./routes/bill.routes");
-/**
- * View Engine setup
- */
-app.set("views", path.join(__dirname, "views"));
-app.set("trust proxy", 1);
-app.use(express.json());
-app.use(express.urlencoded({ extended: false }));
-app.use(bodyParser.json());
-app.use(bodyParser.urlencoded({ extended: true }));
-app.use(express.static(path.join(__dirname, "public")));
-app.use(cookieParser());
- 
-// Configuring the main routes
-app.use("/auth", authRouter);
-app.use("/bill", billRouter)
- 
-module.exports = app;
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/business/bill.business.js.html b/server/coverage/lcov-report/server/business/bill.business.js.html deleted file mode 100644 index ded6863..0000000 --- a/server/coverage/lcov-report/server/business/bill.business.js.html +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - Code coverage report for server/business/bill.business.js - - - - - - - - - -
-
-

All files / server/business bill.business.js

-
- -
- 100% - Statements - 10/10 -
- - -
- 100% - Branches - 4/4 -
- - -
- 100% - Functions - 4/4 -
- - -
- 100% - Lines - 10/10 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -361x -1x -1x -  -1x -  -  -1x -  -  -  -  -  -  -5x -  -  -  -  -  -5x -  -  -  -  -  -  -  -2x -  -  -2x -1x -  -  - 
const DataLayer = require("../datalayer/mongo");
-const model = require("../database").getModel("bill");
-const httpError = require("http-errors");
- 
-module.exports = class billBusiness {
- constructor() {
-  // Create an instance of the data layer.
-  this.dataLayer = new DataLayer(model);
- }
- 
- /**
-  *  Get all bills.
-  */
- async getAllBills(queryString) {
-  const filter = {
-   driver: queryString.driver,
-   paid: queryString.paid,
-   limit: queryString.limit ?? 10,
-   offset: queryString.offset ?? 0
-  }
-  return this.dataLayer
-      .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }})
- }
- 
- /**
-  *  Get a bill by ID.
-  */
- async payBill(id) {
-  const record = {
-   paid: true
-  }
-  return this.dataLayer.update(id, record)
-    .catch((error) => {throw httpError(404, error.message)
-  })
- }
-}
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/business/index.html b/server/coverage/lcov-report/server/business/index.html deleted file mode 100644 index 62df32c..0000000 --- a/server/coverage/lcov-report/server/business/index.html +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - Code coverage report for server/business - - - - - - - - - -
-
-

All files server/business

-
- -
- 92.3% - Statements - 36/39 -
- - -
- 87.5% - Branches - 14/16 -
- - -
- 93.75% - Functions - 15/16 -
- - -
- 92.3% - Lines - 36/39 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
bill.business.js -
-
100%10/10100%4/4100%4/4100%10/10
user.business.js -
-
89.65%26/2983.33%10/1291.66%11/1289.65%26/29
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/business/user.business.js.html b/server/coverage/lcov-report/server/business/user.business.js.html deleted file mode 100644 index a23501c..0000000 --- a/server/coverage/lcov-report/server/business/user.business.js.html +++ /dev/null @@ -1,421 +0,0 @@ - - - - - - Code coverage report for server/business/user.business.js - - - - - - - - - -
-
-

All files / server/business user.business.js

-
- -
- 89.65% - Statements - 26/29 -
- - -
- 83.33% - Branches - 10/12 -
- - -
- 91.66% - Functions - 11/12 -
- - -
- 89.65% - Lines - 26/29 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -1131x -1x -1x -1x -1x -  -1x -  -  -1x -  -  -  -  -  -  -2x -  -2x -  -  -  -  -2x -1x -  -  -  -  -  -1x -  -  -  -  -  -  -  -  -  -  -  -1x -  -  -  -  -  -  -1x -  -  -  -  -  -  -  -3x -  -  -  -  -  -2x -  -  -  -  -  -  -  -3x -  -  -3x -  -  -  -  -  -  -3x -2x -1x -1x -1x -  -  -  -  -  -  -  -  -2x -  -  -  -2x -  -  -  -  -  -  -  -  -  -  -  -3x -  - 
const DataLayer = require("../datalayer/mongo");
-const model = require("../database").getModel("user");
-const httpError = require("http-errors");
-const jwt = require("jsonwebtoken");
-const bcrypt = require("bcryptjs");
- 
-module.exports = class UserBusiness {
-    constructor() {
-        // Create an instance of the data layer.
-        this.dataLayer = new DataLayer(model);
-    }
- 
-    /**
-     *  Login a user.
-     */
-    async login(email, password) {
-        return this.findUserByEmail(email)
-            .then((user) => {
-                const passwordIsValid = bcrypt.compareSync(
-                    password,
-                    user.password
-                );
-                // Invalid password, return 401
-                if (!passwordIsValid) {
-                    throw httpError(
-                        401,
-                        "Your email or password is incorrect."
-                    );
-                }
-                // Create token and store in the session cookie
-                const token = jwt.sign(
-                    {
-                        id: user._id,
-                        type: user.type,
-                        email: user.email,
-                        username: user.username,
-                    },
-                    process.env.TOKEN_SECRET,
-                    {
-                        expiresIn: 3600, // 1 hour
-                    }
-                );
-                return {
-                    token: token,
-                    username: user.username,
-                    type: user.type,
-                    id: user._id,
-                };
-            })
-            .catch(() => {throw httpError(400, "Your email or password is incorrect.");
-            });
-    }
- 
-    /**
-     *  Register a user.
-     */
-    async register(user) {
-        return this.createUser({
-            username: user.username,
-            email: user.email,
-            password: user.password,
-            type: "Driver",
-        }).catch((error) => {
-            throw httpError(400, error.message);
-        });
-    }
- 
-    /**
-     *  Create a user and save it to the User collection.
-     */
-    async createUser(userToCreate) {
-        Iif (!isUserDataValid(userToCreate)) {
-            throw httpError(400, "User data is invalid.");
-        }
-        const user = {
-            username: userToCreate.username,
-            email: userToCreate.email,
-            type: userToCreate.type,
-            password: bcrypt.hashSync(userToCreate.password, 8),
-        };
- 
-        return this.dataLayer.create(user).catch((error) => {
-            if (error.message.includes("username"))
-                throw httpError(400, "Username is already in use.");
-            Eif (error.message.includes("email"))
-                throw httpError(400, "Email is already in use.");
-            throw httpError(404, error.message);
-        });
-    }
- 
-    /**
-     *  Find a user by email
-     */
-    async findUserByEmail(email) {
-        return this.dataLayer
-            .findByProperty({ email: email })
-            .then((users) => {
-                // Email is unique so only 1 can be returned.
-                return users[0];
-            })
-            .catch((error) => {
-                throw httpError(404, error.message);
-            });
-    }
-}
- 
-/**
- *  Validates the data in a User.
- */
-function isUserDataValid(user) {
-    return !(!user || !user.username || !user.email || !user.password);
-}
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/config/db.config.js.html b/server/coverage/lcov-report/server/config/db.config.js.html deleted file mode 100644 index b44167d..0000000 --- a/server/coverage/lcov-report/server/config/db.config.js.html +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - Code coverage report for server/config/db.config.js - - - - - - - - - -
-
-

All files / server/config db.config.js

-
- -
- 100% - Statements - 1/1 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 0/0 -
- - -
- 100% - Lines - 1/1 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -91x -  -  -  -  -  -  -  - 
module.exports = {
-    dev: {
-        url: "mongodb://localhost:27017/highwaytrackerdb",
-    },
-    test: {
-        url: "mongodb://localhost:27017/highwaytrackerdb_testing",
-    },
-};
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/config/index.html b/server/coverage/lcov-report/server/config/index.html deleted file mode 100644 index 1e64ab4..0000000 --- a/server/coverage/lcov-report/server/config/index.html +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - Code coverage report for server/config - - - - - - - - - -
-
-

All files server/config

-
- -
- 100% - Statements - 1/1 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 0/0 -
- - -
- 100% - Lines - 1/1 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
db.config.js -
-
100%1/1100%0/0100%0/0100%1/1
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/auth.controller.js.html b/server/coverage/lcov-report/server/controllers/auth.controller.js.html deleted file mode 100644 index 3dfd9bf..0000000 --- a/server/coverage/lcov-report/server/controllers/auth.controller.js.html +++ /dev/null @@ -1,241 +0,0 @@ - - - - - - Code coverage report for server/controllers/auth.controller.js - - - - - - - - - -
-
-

All files / server/controllers auth.controller.js

-
- -
- 88.23% - Statements - 15/17 -
- - -
- 100% - Branches - 0/0 -
- - -
- 85.71% - Functions - 6/7 -
- - -
- 88.23% - Lines - 15/17 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -531x -1x -  -  -  -  -1x -2x -  -  -1x -1x -1x -1x -  -1x -  -  -  -  -  -  -  -1x -  -  -  -  -  -  -1x -3x -  -  -1x -  -  -  -  -2x -  -  -  -  -  -  -1x -  -  -  -  -  - 
const UserBusiness = require("../business/user.business");
-const userBusiness = new UserBusiness();
- 
-/**
- * Login the user
- */
-exports.login = async (req, res) => {
-    userBusiness
-        .login(req.body.email, req.body.password)
-        .then((data) => {
-            req.session.token = data.token;
-            req.session.username = data.username;
-            req.session.role = data.role;
-            req.session.id = data.id;
- 
-            res.status(200).send({
-                message: "Successfully logged in.",
-                username: data.username,
-                role: data.role,
-                id: data.id,
-            });
-        })
-        .catch((error) => {
-            res.status(error.status).send({ message: error.message });
-        });
-};
- 
-/**
- * Register the user
- */
-exports.register = (req, res) => {
-    userBusiness
-        .register(req.body)
-        .then(() => {
-            res.status(201).send({
-                message: "User was successfully created.",
-            });
-        })
-        .catch((error) => {
-            res.status(error.status).send({ message: error.message });
-        });
-};
- 
-/**
- * Logs the user out
- */
-exports.logout = (req, res) => {
-    req.session = null;
-    res.status(200).send({
-        message: "User was successfully logged out.",
-    });
-};
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/bill.controller.js.html b/server/coverage/lcov-report/server/controllers/bill.controller.js.html deleted file mode 100644 index b786cbe..0000000 --- a/server/coverage/lcov-report/server/controllers/bill.controller.js.html +++ /dev/null @@ -1,151 +0,0 @@ - - - - - - Code coverage report for server/controllers/bill.controller.js - - - - - - - - - -
-
-

All files / server/controllers bill.controller.js

-
- -
- 90% - Statements - 9/10 -
- - -
- 100% - Branches - 0/0 -
- - -
- 83.33% - Functions - 5/6 -
- - -
- 90% - Lines - 9/10 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -231x -1x -  -  -  -  -1x -5x -5x -  -  -  -  -  -  -  -  -  -1x -2x -1x -1x - 
const BillBusiness = require("../business/bill.business");
-const billBusiness = new BillBusiness();
- 
-/**
- * Get all bills
- */
-exports.getAllBills = async (req, res) => {
- billBusiness.getAllBills(req.query)
-   .then((data) => {return res.status(200).send(data)})
-   .catch((error) => {
-    res.status(error.status).send({message: error.message})
-   })
- 
-}
- 
-/**
- * Pay bill
- */
-exports.payBill = async (req, res) => {
- billBusiness.payBill(req.params.id)
-   .then(() => {res.status(200).send({message: "Bill paid."})})
-   .catch((error) => {res.status(error.status).send({message: error.message})})
-}
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/controllers/index.html b/server/coverage/lcov-report/server/controllers/index.html deleted file mode 100644 index d69bc26..0000000 --- a/server/coverage/lcov-report/server/controllers/index.html +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - Code coverage report for server/controllers - - - - - - - - - -
-
-

All files server/controllers

-
- -
- 88.88% - Statements - 24/27 -
- - -
- 100% - Branches - 0/0 -
- - -
- 84.61% - Functions - 11/13 -
- - -
- 88.88% - Lines - 24/27 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
auth.controller.js -
-
88.23%15/17100%0/085.71%6/788.23%15/17
bill.controller.js -
-
90%9/10100%0/083.33%5/690%9/10
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/database/index.html b/server/coverage/lcov-report/server/database/index.html deleted file mode 100644 index 1210d29..0000000 --- a/server/coverage/lcov-report/server/database/index.html +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - Code coverage report for server/database - - - - - - - - - -
-
-

All files server/database

-
- -
- 75% - Statements - 18/24 -
- - -
- 50% - Branches - 1/2 -
- - -
- 40% - Functions - 2/5 -
- - -
- 75% - Lines - 18/24 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
index.js -
-
75%18/2450%1/240%2/575%18/24
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/database/index.js.html b/server/coverage/lcov-report/server/database/index.js.html deleted file mode 100644 index 6dd9c1e..0000000 --- a/server/coverage/lcov-report/server/database/index.js.html +++ /dev/null @@ -1,244 +0,0 @@ - - - - - - Code coverage report for server/database/index.js - - - - - - - - - -
-
-

All files / server/database index.js

-
- -
- 75% - Statements - 18/24 -
- - -
- 50% - Branches - 1/2 -
- - -
- 40% - Functions - 2/5 -
- - -
- 75% - Lines - 18/24 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54  -1x -1x -1x -1x -  -1x -1x -1x -1x -  -  -1x -1x -  -  -1x -  -  -  -  -  -1x -  -1x -  -  -  -  -  -  -  -  -1x -  -  -  -  -  -1x -  -  -  -  -  -  -1x -  -1x -  -2x -  -  - 
// Get database config
-const mongoose = require("mongoose");
-mongoose.Promise = global.Promise;
-const environment = process.env.NODE_ENV;
-let dbConfig = require("../config/db.config.js")[environment];
- 
-const journey = require("../models/journey")(mongoose);
-const bill = require("../models/bill")(mongoose);
-const location = require("../models/location")(mongoose);
-const user = require("../models/user.model.js")(mongoose);
- 
-// Create mongoose and read in config
-const db = { journey: journey, bill: bill, location: location, user: user };
-db.mongoose = mongoose;
- 
-// For GITHUB ACTIONS - if null set it to testing
-Iif (!dbConfig) {
-    dbConfig = {
-        url: "mongodb://localhost:27017/highwaytrackerdb_testing",
-    };
-}
- 
-db.url = dbConfig.url;
- 
-db.mongoose.plugin((schema) => {
-    schema.pre("updateOne", setRunValidators);
-    schema.pre("findByIdAndUpdate", setRunValidators);
-});
-function setRunValidators() {
-    this.setOptions({ runValidators: true });
-}
- 
-// Using the mongoose object, start the database
-db.mongoose
-    .connect(db.url, {
-        useNewUrlParser: true,
-        useUnifiedTopology: true,
-    })
-    .then(() => {
-        console.log("Connected to the database (" + environment + ")");
-    })
-    .catch((err) => {
-        console.log("Cannot connect to the database.", err);
-        process.exit();
-    });
- 
-module.exports = db;
- 
-module.exports = {
-    getModel: (modelName) => {
-        return db.mongoose.model(modelName);
-    },
-};
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/datalayer/index.html b/server/coverage/lcov-report/server/datalayer/index.html deleted file mode 100644 index 9583563..0000000 --- a/server/coverage/lcov-report/server/datalayer/index.html +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - Code coverage report for server/datalayer - - - - - - - - - -
-
-

All files server/datalayer

-
- -
- 100% - Statements - 7/7 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 6/6 -
- - -
- 100% - Lines - 7/7 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
mongo.js -
-
100%7/7100%0/0100%6/6100%7/7
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/datalayer/mongo.js.html b/server/coverage/lcov-report/server/datalayer/mongo.js.html deleted file mode 100644 index cc5354d..0000000 --- a/server/coverage/lcov-report/server/datalayer/mongo.js.html +++ /dev/null @@ -1,211 +0,0 @@ - - - - - - Code coverage report for server/datalayer/mongo.js - - - - - - - - - -
-
-

All files / server/datalayer mongo.js

-
- -
- 100% - Statements - 7/7 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 6/6 -
- - -
- 100% - Lines - 7/7 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43  -  -  -2x -  -  -  -  -  -  -5x -  -  -  -  -  -  -  -  -  -2x -  -  -  -  -  -  -3x -  -  -  -  -  -  -2x -  -1x -  -  -  -  -1x - 
class DataLayer {
-    constructor(model) {
-        // Set the collections model to use.
-        this.model = model;
-    }
- 
-    /**
-     * Find all records in the database.
-     */
-    async findAllAndPopulate(filter, populateFilter) {
-        return this.model.find(JSON.parse(JSON.stringify(filter)))
-          .limit(filter.limit)
-          .skip(filter.offset * filter.limit)
-          .populate(JSON.parse(JSON.stringify(populateFilter)))
-    }
-    
-    /**
-     * Find a record by property in the database.
-     */
-    async findByProperty(propertyToFind) {
-        return this.model.find(propertyToFind);
-    }
-    
-    /**
-     * Create and save the record to the database.
-     */
-    async create(recordToCreate) {
-        return this.model.create(recordToCreate);
-    }
- 
-    /**
-     *  Update and save the record to the database.
-     */
-    async update(recordId, recordToUpdate) {
-        return this.model.findByIdAndUpdate(recordId, recordToUpdate)
-          .orFail(new Error("Bill can't be found in the database."))
-          .catch(error => {throw new Error(error.message)});
- 
-    }
-}
- 
-module.exports = DataLayer;
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/index.html b/server/coverage/lcov-report/server/index.html deleted file mode 100644 index 89aa816..0000000 --- a/server/coverage/lcov-report/server/index.html +++ /dev/null @@ -1,116 +0,0 @@ - - - - - - Code coverage report for server - - - - - - - - - -
-
-

All files server

-
- -
- 100% - Statements - 24/24 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 0/0 -
- - -
- 100% - Lines - 24/24 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
app.js -
-
100%24/24100%0/0100%0/0100%24/24
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/bill.js.html b/server/coverage/lcov-report/server/models/bill.js.html deleted file mode 100644 index 5953d55..0000000 --- a/server/coverage/lcov-report/server/models/bill.js.html +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - Code coverage report for server/models/bill.js - - - - - - - - - -
-
-

All files / server/models bill.js

-
- -
- 100% - Statements - 3/3 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 1/1 -
- - -
- 100% - Lines - 3/3 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -261x -1x -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -1x - 
module.exports = mongoose => {
- const billSchema = mongoose.Schema(
-   {
-    journey: { 
-     type: mongoose.Schema.Types.ObjectId, 
-     ref: "journey",
-     required: [true, "A journey must be attached to a bill."],
-     unique: true
-    },
-    driver: { 
-     type: String,
-     required: [true, "A driver must be assigned to a bill."]
-    },
-    cost: {
-     type: Number,
-     required: [true, "A cost for the bill is required."]
-    },
-    paid: {
-     type: Boolean,
-     default: false
-    }
-   }
- )
- 
- return mongoose.model("bill", billSchema)
-}
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/index.html b/server/coverage/lcov-report/server/models/index.html deleted file mode 100644 index b538f7b..0000000 --- a/server/coverage/lcov-report/server/models/index.html +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - Code coverage report for server/models - - - - - - - - - -
-
-

All files server/models

-
- -
- 100% - Statements - 12/12 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 4/4 -
- - -
- 100% - Lines - 12/12 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
bill.js -
-
100%3/3100%0/0100%1/1100%3/3
journey.js -
-
100%3/3100%0/0100%1/1100%3/3
location.js -
-
100%3/3100%0/0100%1/1100%3/3
user.model.js -
-
100%3/3100%0/0100%1/1100%3/3
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/journey.js.html b/server/coverage/lcov-report/server/models/journey.js.html deleted file mode 100644 index bc8396e..0000000 --- a/server/coverage/lcov-report/server/models/journey.js.html +++ /dev/null @@ -1,157 +0,0 @@ - - - - - - Code coverage report for server/models/journey.js - - - - - - - - - -
-
-

All files / server/models journey.js

-
- -
- 100% - Statements - 3/3 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 1/1 -
- - -
- 100% - Lines - 3/3 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -251x -1x -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -1x - 
module.exports = mongoose => {
- const journeySchema = mongoose.Schema(
-   {
-    regNumber: {
-     type: "String",
-     required: [true, "A car registration number is required"]
-    },
-    entryLocation: {
-     type: mongoose.Schema.Types.ObjectId, 
-     ref: "location",
-     required: [true, "A entry location is required."]
-    },
-    exitLocation: {
-     type: mongoose.Schema.Types.ObjectId, 
-     ref: "location",
-     required: [true, "A exit location is required."]
-    },
-    journeyDateTime: {
-     type: Date
-    }
-   }
- )
- 
- return mongoose.model("journey", journeySchema)
-}
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/location.js.html b/server/coverage/lcov-report/server/models/location.js.html deleted file mode 100644 index 74a2bc2..0000000 --- a/server/coverage/lcov-report/server/models/location.js.html +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - Code coverage report for server/models/location.js - - - - - - - - - -
-
-

All files / server/models location.js

-
- -
- 100% - Statements - 3/3 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 1/1 -
- - -
- 100% - Lines - 3/3 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -221x -1x -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -1x - 
module.exports = mongoose => {
- const locationSchema = mongoose.Schema(
-   {
-    name: {
-     type: "String",
-     required: [true, "A location name is required"]
-    },
-    coordinates: {
-      longitude: {
-       type: "Number",
-       required: [true, "A longitude is required"]
-      },
-      latitude: {
-       type: "Number",
-       required: [true, "A latitude is required"]
-      }
-    }
-   }
- )
- 
- return mongoose.model("location", locationSchema)
-}
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/models/user.model.js.html b/server/coverage/lcov-report/server/models/user.model.js.html deleted file mode 100644 index 6402aa1..0000000 --- a/server/coverage/lcov-report/server/models/user.model.js.html +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - Code coverage report for server/models/user.model.js - - - - - - - - - -
-
-

All files / server/models user.model.js

-
- -
- 100% - Statements - 3/3 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 1/1 -
- - -
- 100% - Lines - 3/3 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32  -1x -1x -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -1x -  - 
// Model for the User
-module.exports = (mongoose) => {
-    var UserSchema = mongoose.Schema({
-        username: {
-            type: String,
-            required: [true, "You must supply the user's username."],
-            minlength: [5, "Your username must be at least 5 letters."],
-            unique: true,
-        },
-        email: {
-            type: String,
-            required: [true, "You must supply the user's email."],
-            unique: true,
-        },
-        password: {
-            type: String,
-            required: [true, "You must supply the user's password"],
-            minlength: [5, "Your password must be at least 8 letters."],
-        },
-        type: {
-            type: String,
-            required: [true, "You must supply the user's role."],
-            enum: {
-                values: ["Driver", "Toll Operator"],
-                message: "Type is not valid. Must be 'Driver'.",
-            },
-        },
-    });
- 
-    return mongoose.model("user", UserSchema);
-};
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/routes/auth.routes.js.html b/server/coverage/lcov-report/server/routes/auth.routes.js.html deleted file mode 100644 index 6c109b7..0000000 --- a/server/coverage/lcov-report/server/routes/auth.routes.js.html +++ /dev/null @@ -1,133 +0,0 @@ - - - - - - Code coverage report for server/routes/auth.routes.js - - - - - - - - - -
-
-

All files / server/routes auth.routes.js

-
- -
- 100% - Statements - 7/7 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 0/0 -
- - -
- 100% - Lines - 7/7 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -171x -1x -  -  -1x -  -  -1x -  -  -1x -  -  -1x -  -1x - 
const express = require("express");
-const router = express.Router();
- 
-// Get the Auth controller
-const authController = require("../controllers/auth.controller");
- 
-// Log the user in
-router.post("/login/", authController.login);
- 
-// Register the user
-router.post("/register/", authController.register);
- 
-// Log the user out
-router.post("/logout/", authController.logout);
- 
-module.exports = router;
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/routes/bill.routes.js.html b/server/coverage/lcov-report/server/routes/bill.routes.js.html deleted file mode 100644 index 6257856..0000000 --- a/server/coverage/lcov-report/server/routes/bill.routes.js.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - Code coverage report for server/routes/bill.routes.js - - - - - - - - - -
-
-

All files / server/routes bill.routes.js

-
- -
- 100% - Statements - 6/6 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 0/0 -
- - -
- 100% - Lines - 6/6 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-

-
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -141x -1x -  -  -1x -  -  -1x -  -  -1x -  -1x - 
const express = require("express");
-const router = express.Router();
- 
-// Get the Bill controller
-const billController = require("../controllers/bill.controller");
- 
-// Get All Bills
-router.get("/", billController.getAllBills);
- 
-// Pay for bill
-router.put("/:id", billController.payBill);
- 
-module.exports = router;
- 
- -
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/server/routes/index.html b/server/coverage/lcov-report/server/routes/index.html deleted file mode 100644 index e5a4ed9..0000000 --- a/server/coverage/lcov-report/server/routes/index.html +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - Code coverage report for server/routes - - - - - - - - - -
-
-

All files server/routes

-
- -
- 100% - Statements - 13/13 -
- - -
- 100% - Branches - 0/0 -
- - -
- 100% - Functions - 0/0 -
- - -
- 100% - Lines - 13/13 -
- - -
-

- Press n or j to go to the next uncovered block, b, p or k for the previous block. -

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FileStatementsBranchesFunctionsLines
auth.routes.js -
-
100%7/7100%0/0100%0/0100%7/7
bill.routes.js -
-
100%6/6100%0/0100%0/0100%6/6
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/server/coverage/lcov-report/sort-arrow-sprite.png b/server/coverage/lcov-report/sort-arrow-sprite.png deleted file mode 100644 index 03f704a609c6fd0dbfdac63466a7d7c958b5cbf3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 209 zcmeAS@N?(olHy`uVBq!ia0vp^>_9Bd!3HEZxJ@+%Qj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jii$m5978H@?Fn+^JD|Y9yzj{W`447Gxa{7*dM7nnnD-Lb z6^}Hx2)'; - } - } - return cols; - } - // attaches a data attribute to every tr element with an object - // of data values keyed by column name - function loadRowData(tableRow) { - var tableCols = tableRow.querySelectorAll('td'), - colNode, - col, - data = {}, - i, - val; - for (i = 0; i < tableCols.length; i += 1) { - colNode = tableCols[i]; - col = cols[i]; - val = colNode.getAttribute('data-value'); - if (col.type === 'number') { - val = Number(val); - } - data[col.key] = val; - } - return data; - } - // loads all row data - function loadData() { - var rows = getTableBody().querySelectorAll('tr'), - i; - - for (i = 0; i < rows.length; i += 1) { - rows[i].data = loadRowData(rows[i]); - } - } - // sorts the table using the data for the ith column - function sortByIndex(index, desc) { - var key = cols[index].key, - sorter = function(a, b) { - a = a.data[key]; - b = b.data[key]; - return a < b ? -1 : a > b ? 1 : 0; - }, - finalSorter = sorter, - tableBody = document.querySelector('.coverage-summary tbody'), - rowNodes = tableBody.querySelectorAll('tr'), - rows = [], - i; - - if (desc) { - finalSorter = function(a, b) { - return -1 * sorter(a, b); - }; - } - - for (i = 0; i < rowNodes.length; i += 1) { - rows.push(rowNodes[i]); - tableBody.removeChild(rowNodes[i]); - } - - rows.sort(finalSorter); - - for (i = 0; i < rows.length; i += 1) { - tableBody.appendChild(rows[i]); - } - } - // removes sort indicators for current column being sorted - function removeSortIndicators() { - var col = getNthColumn(currentSort.index), - cls = col.className; - - cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); - col.className = cls; - } - // adds sort indicators for current column being sorted - function addSortIndicators() { - getNthColumn(currentSort.index).className += currentSort.desc - ? ' sorted-desc' - : ' sorted'; - } - // adds event listeners for all sorter widgets - function enableUI() { - var i, - el, - ithSorter = function ithSorter(i) { - var col = cols[i]; - - return function() { - var desc = col.defaultDescSort; - - if (currentSort.index === i) { - desc = !currentSort.desc; - } - sortByIndex(i, desc); - removeSortIndicators(); - currentSort.index = i; - currentSort.desc = desc; - addSortIndicators(); - }; - }; - for (i = 0; i < cols.length; i += 1) { - if (cols[i].sortable) { - // add the click event handler on the th so users - // dont have to click on those tiny arrows - el = getNthColumn(i).querySelector('.sorter').parentElement; - if (el.addEventListener) { - el.addEventListener('click', ithSorter(i)); - } else { - el.attachEvent('onclick', ithSorter(i)); - } - } - } - } - // adds sorting functionality to the UI - return function() { - if (!getTable()) { - return; - } - cols = loadColumns(); - loadData(); - addSearchBox(); - addSortIndicators(); - enableUI(); - }; -})(); - -window.addEventListener('load', addSorting); From 154fc4f4b94723c1da0813f6e2f2eaa3c1f88b77 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 12:54:23 +0000 Subject: [PATCH 21/31] Make changes based on code review and calculate cost based on haversine distance --- server/.nyc_output/processinfo/index.json | 2 +- server/business/bill.business.js | 6 +- server/coverage/lcov.info | 82 ++++++++++++------- server/database/index.js | 6 +- server/database/seed.js | 26 +++--- server/models/{bill.js => bill.model.js} | 9 +- .../models/{journey.js => journey.model.js} | 0 .../models/{location.js => location.model.js} | 0 server/package-lock.json | 18 ++-- server/package.json | 4 +- .../test/integration/bill.controller.test.js | 40 ++++----- server/utilities.js | 9 ++ 12 files changed, 124 insertions(+), 78 deletions(-) rename server/models/{bill.js => bill.model.js} (62%) rename server/models/{journey.js => journey.model.js} (100%) rename server/models/{location.js => location.model.js} (100%) create mode 100644 server/utilities.js diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index 0c53470..0f3266a 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"7b3978e8-85aa-46d2-9a25-1b740367f6cb":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["7b3978e8-85aa-46d2-9a25-1b740367f6cb"]},"externalIds":{}} \ No newline at end of file +{"processes":{"af3517a2-0c52-452e-b2ec-5fe8a90c051a":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"]},"externalIds":{}} \ No newline at end of file diff --git a/server/business/bill.business.js b/server/business/bill.business.js index 4625cec..7662f70 100644 --- a/server/business/bill.business.js +++ b/server/business/bill.business.js @@ -1,8 +1,9 @@ const DataLayer = require("../datalayer/mongo"); +const Utilities = require("../utilities") const model = require("../database").getModel("bill"); const httpError = require("http-errors"); -module.exports = class billBusiness { +module.exports = class BillBusiness { constructor() { // Create an instance of the data layer. this.dataLayer = new DataLayer(model); @@ -19,7 +20,8 @@ module.exports = class billBusiness { offset: queryString.offset ?? 0 } return this.dataLayer - .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }}) + .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }}) + .catch((error) => { throw httpError(500, error.message)}) } /** diff --git a/server/coverage/lcov.info b/server/coverage/lcov.info index 5e328df..0b5acf5 100644 --- a/server/coverage/lcov.info +++ b/server/coverage/lcov.info @@ -32,33 +32,52 @@ BRF:0 BRH:0 end_of_record TN: +SF:utilities.js +FN:4,(anonymous_0) +FNF:1 +FNH:0 +FNDA:0,(anonymous_0) +DA:1,1 +DA:3,1 +DA:5,0 +DA:8,1 +LF:4 +LH:3 +BRF:0 +BRH:0 +end_of_record +TN: SF:business\bill.business.js -FN:6,(anonymous_0) -FN:14,(anonymous_1) -FN:28,(anonymous_2) -FN:33,(anonymous_3) -FNF:4 +FN:7,(anonymous_0) +FN:15,(anonymous_1) +FN:24,(anonymous_2) +FN:30,(anonymous_3) +FN:35,(anonymous_4) +FNF:5 FNH:4 FNDA:1,(anonymous_0) FNDA:5,(anonymous_1) -FNDA:2,(anonymous_2) -FNDA:1,(anonymous_3) +FNDA:0,(anonymous_2) +FNDA:2,(anonymous_3) +FNDA:1,(anonymous_4) DA:1,1 DA:2,1 DA:3,1 -DA:5,1 -DA:8,1 -DA:15,5 -DA:21,5 -DA:29,2 -DA:32,2 -DA:33,1 -LF:10 -LH:10 -BRDA:18,0,0,5 -BRDA:18,0,1,4 -BRDA:19,1,0,5 -BRDA:19,1,1,4 +DA:4,1 +DA:6,1 +DA:9,1 +DA:16,5 +DA:22,5 +DA:24,0 +DA:31,2 +DA:34,2 +DA:35,1 +LF:12 +LH:11 +BRDA:19,0,0,5 +BRDA:19,0,1,4 +BRDA:20,1,0,5 +BRDA:20,1,1,4 BRF:4 BRH:4 end_of_record @@ -291,21 +310,28 @@ BRF:0 BRH:0 end_of_record TN: -SF:models\bill.js -FN:1,(anonymous_0) -FNF:1 +SF:models\bill.model.js +FN:2,(anonymous_0) +FN:26,(anonymous_1) +FNF:2 FNH:1 FNDA:1,(anonymous_0) +FNDA:0,(anonymous_1) DA:1,1 DA:2,1 -DA:25,1 -LF:3 -LH:3 +DA:3,1 +DA:26,1 +DA:27,0 +DA:28,0 +DA:29,0 +DA:32,1 +LF:8 +LH:5 BRF:0 BRH:0 end_of_record TN: -SF:models\journey.js +SF:models\journey.model.js FN:1,(anonymous_0) FNF:1 FNH:1 @@ -319,7 +345,7 @@ BRF:0 BRH:0 end_of_record TN: -SF:models\location.js +SF:models\location.model.js FN:1,(anonymous_0) FNF:1 FNH:1 diff --git a/server/database/index.js b/server/database/index.js index f3cff22..eaea80b 100644 --- a/server/database/index.js +++ b/server/database/index.js @@ -4,9 +4,9 @@ mongoose.Promise = global.Promise; const environment = process.env.NODE_ENV; let dbConfig = require("../config/db.config.js")[environment]; -const journey = require("../models/journey")(mongoose); -const bill = require("../models/bill")(mongoose); -const location = require("../models/location")(mongoose); +const journey = require("../models/journey.model.js")(mongoose); +const bill = require("../models/bill.model.js")(mongoose); +const location = require("../models/location.model.js")(mongoose); const user = require("../models/user.model.js")(mongoose); // Create mongoose and read in config diff --git a/server/database/seed.js b/server/database/seed.js index 4db1451..d058bf6 100644 --- a/server/database/seed.js +++ b/server/database/seed.js @@ -1,12 +1,14 @@ const mongoose = require("mongoose"); mongoose.users = require("../models/user.model")(mongoose); -mongoose.locations = require("../models/location")(mongoose); -mongoose.journeys = require("../models/journey")(mongoose); -mongoose.bills = require("../models/bill")(mongoose); +mongoose.locations = require("../models/location.model")(mongoose); +mongoose.journeys = require("../models/journey.model")(mongoose); +mongoose.bills = require("../models/bill.model")(mongoose); const bcrypt = require("bcryptjs"); +const environment = process.env.NODE_ENV; +let dbConfig = require("../config/db.config.js")[environment]; mongoose - .connect("mongodb://localhost:27017/highwaytrackerdb_testing", { + .connect(dbConfig.url, { useNewUrlParser: true, useUnifiedTopology: true, }) @@ -31,16 +33,16 @@ const locations = [ _id: "123456789101", name: "test_location_1", coordinates: { - longitude: 10, - latitude: 10 + longitude: 50, + latitude: 50 } }, { _id: "123456789102", name: "test_location_2", coordinates: { - longitude: 10, - latitude: 10 + longitude: 0, + latitude: 0 } } ] @@ -84,10 +86,10 @@ const seedDB = async () => { await mongoose.connection.collections[collection].deleteMany() } - await mongoose.users.insertMany(users); - await mongoose.locations.insertMany(locations); - await mongoose.journeys.insertMany(journeys); - await mongoose.bills.insertMany(bills) + await mongoose.users.create(users); + await mongoose.locations.create(locations); + await mongoose.journeys.create(journeys); + await mongoose.bills.create(bills) }; seedDB() diff --git a/server/models/bill.js b/server/models/bill.model.js similarity index 62% rename from server/models/bill.js rename to server/models/bill.model.js index b0e9bb2..758f965 100644 --- a/server/models/bill.js +++ b/server/models/bill.model.js @@ -1,4 +1,5 @@ -module.exports = mongoose => { +const Utilities = require("../utilities") +module.exports = mongoose => { const billSchema = mongoose.Schema( { journey: { @@ -22,5 +23,11 @@ } ) + billSchema.pre('save', async function (next) { + const journey = await mongoose.model('journey').findById(this.journey).populate({ path: 'entryLocation exitLocation' }) + this.cost = Utilities.calculateCost(journey) + next() + }) + return mongoose.model("bill", billSchema) } \ No newline at end of file diff --git a/server/models/journey.js b/server/models/journey.model.js similarity index 100% rename from server/models/journey.js rename to server/models/journey.model.js diff --git a/server/models/location.js b/server/models/location.model.js similarity index 100% rename from server/models/location.js rename to server/models/location.model.js diff --git a/server/package-lock.json b/server/package-lock.json index f0524c0..470d780 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -15,7 +15,7 @@ "dotenv": "^15.0.0", "eslint": "^8.8.0", "express": "^4.17.2", - "haversine-distance": "^1.2.1", + "haversine": "^1.1.1", "http-errors": "^2.0.0", "jshint": "^2.13.4", "jsonwebtoken": "^8.5.1", @@ -2361,10 +2361,10 @@ "node": ">=8" } }, - "node_modules/haversine-distance": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/haversine-distance/-/haversine-distance-1.2.1.tgz", - "integrity": "sha512-rQpG89d6NlAis0eqOSFXDqNU/GZcMPlHNVMqTSzD16niD9s1fDK8T6kwrK0WJ7OMU+iRNy3cgGYnNQihMqmaHg==" + "node_modules/haversine": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/haversine/-/haversine-1.1.1.tgz", + "integrity": "sha512-KW4MS8+krLIeiw8bF5z532CptG0ZyGGFj0UbKMxx25lKnnJ1hMUbuzQl+PXQjNiDLnl1bOyz23U6hSK10r4guw==" }, "node_modules/he": { "version": "1.2.0", @@ -6793,10 +6793,10 @@ } } }, - "haversine-distance": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/haversine-distance/-/haversine-distance-1.2.1.tgz", - "integrity": "sha512-rQpG89d6NlAis0eqOSFXDqNU/GZcMPlHNVMqTSzD16niD9s1fDK8T6kwrK0WJ7OMU+iRNy3cgGYnNQihMqmaHg==" + "haversine": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/haversine/-/haversine-1.1.1.tgz", + "integrity": "sha512-KW4MS8+krLIeiw8bF5z532CptG0ZyGGFj0UbKMxx25lKnnJ1hMUbuzQl+PXQjNiDLnl1bOyz23U6hSK10r4guw==" }, "he": { "version": "1.2.0", diff --git a/server/package.json b/server/package.json index d249be5..4dab44b 100644 --- a/server/package.json +++ b/server/package.json @@ -1,6 +1,6 @@ { "scripts": { - "start": "set NODE_ENV=dev&& node ./bin/www", + "start": "set NODE_ENV=dev&& node ./database/seed.js && node ./bin/www", "test": "set NODE_ENV=test&& node ./database/seed.js && nyc --reporter lcov mocha --recursive --timeout 5000 --exit" }, "dependencies": { @@ -14,8 +14,8 @@ "dotenv": "^15.0.0", "eslint": "^8.8.0", "express": "^4.17.2", + "haversine": "^1.1.1", "http-errors": "^2.0.0", - "haversine-distance": "^1.2.1", "jshint": "^2.13.4", "jsonwebtoken": "^8.5.1", "mocha": "^9.2.0", diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js index eec3c14..1331cf0 100644 --- a/server/test/integration/bill.controller.test.js +++ b/server/test/integration/bill.controller.test.js @@ -18,17 +18,17 @@ describe("Testing /bill paths", () => { res.should.have.status(200); res.should.be.a("object"); res.body.should.have.lengthOf(2); - res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('cost', 72.93887106726764) res.body[0].should.haveOwnProperty('driver', 'test_driver') res.body[0].should.haveOwnProperty('paid', false) res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 50) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 50) res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 0) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 0) done(); }) @@ -48,17 +48,17 @@ describe("Testing /bill paths", () => { res.should.have.status(200); res.should.be.a("object"); res.body.should.have.lengthOf(1); - res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('cost', 72.93887106726764) res.body[0].should.haveOwnProperty('driver', 'test_driver') res.body[0].should.haveOwnProperty('paid', false) res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 50) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 50) res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 0) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 0) done(); }) @@ -78,17 +78,17 @@ describe("Testing /bill paths", () => { res.should.have.status(200); res.should.be.a("object"); res.body.should.have.lengthOf(1); - res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('cost', 72.93887106726764) res.body[0].should.haveOwnProperty('driver', 'test_driver2') res.body[0].should.haveOwnProperty('paid', true) res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number2') res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.038Z') res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 50) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 50) res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 0) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 0) done(); }) @@ -108,17 +108,17 @@ describe("Testing /bill paths", () => { res.should.have.status(200); res.should.be.a("object"); res.body.should.have.lengthOf(1); - res.body[0].should.haveOwnProperty('cost', 5) + res.body[0].should.haveOwnProperty('cost', 72.93887106726764) res.body[0].should.haveOwnProperty('driver', 'test_driver') res.body[0].should.haveOwnProperty('paid', false) res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('longitude', 50) + res.body[0].journey.entryLocation.coordinates.should.haveOwnProperty('latitude', 50) res.body[0].journey.exitLocation.should.haveOwnProperty('name', 'test_location_2') - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 10) - res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 10) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('longitude', 0) + res.body[0].journey.exitLocation.coordinates.should.haveOwnProperty('latitude', 0) done(); }) diff --git a/server/utilities.js b/server/utilities.js new file mode 100644 index 0000000..2f1a78f --- /dev/null +++ b/server/utilities.js @@ -0,0 +1,9 @@ +const haversine = require("haversine") + +module.exports = class Utilities { + static calculateCost(journey) { + return (haversine(journey.entryLocation.coordinates, journey.exitLocation.coordinates) * this.costPerMile) + } + + static costPerMile = 0.01 +} \ No newline at end of file From 55c2a7e30714c03295c3d551f8ffbfbcde049eee Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 12:56:51 +0000 Subject: [PATCH 22/31] remove unneeded package.json --- package-lock.json | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 13e7197..0000000 --- a/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "CSSD-Assignment", - "lockfileVersion": 2, - "requires": true, - "packages": {} -} From a69488af56c2fc5567833bb22c956b7d39c8b2e2 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 13:00:33 +0000 Subject: [PATCH 23/31] Debug pipeline --- server/database/seed.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/database/seed.js b/server/database/seed.js index d058bf6..a17cb10 100644 --- a/server/database/seed.js +++ b/server/database/seed.js @@ -7,6 +7,7 @@ const bcrypt = require("bcryptjs"); const environment = process.env.NODE_ENV; let dbConfig = require("../config/db.config.js")[environment]; +console.log(dbConfig) mongoose .connect(dbConfig.url, { useNewUrlParser: true, From defca38f830bb4cd2f971beb6bb3a27d840352e1 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 13:08:10 +0000 Subject: [PATCH 24/31] HT-14 Set default object for dbConfig --- server/database/seed.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/database/seed.js b/server/database/seed.js index a17cb10..4dcbe75 100644 --- a/server/database/seed.js +++ b/server/database/seed.js @@ -5,9 +5,8 @@ mongoose.journeys = require("../models/journey.model")(mongoose); mongoose.bills = require("../models/bill.model")(mongoose); const bcrypt = require("bcryptjs"); const environment = process.env.NODE_ENV; -let dbConfig = require("../config/db.config.js")[environment]; +let dbConfig = require("../config/db.config.js")[environment] ?? { url: "mongodb://localhost:27017/highwaytrackerdb_testing" }; -console.log(dbConfig) mongoose .connect(dbConfig.url, { useNewUrlParser: true, From d1fc89ec6d91d51f66dbab03a9bd445d93f61f85 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 13:32:40 +0000 Subject: [PATCH 25/31] HT-14 Add driver id to bill and update tests --- server/.nyc_output/processinfo/index.json | 2 +- server/business/bill.business.js | 6 +++-- server/coverage/lcov.info | 23 ++++++++++--------- server/database/seed.js | 14 +++++++++-- server/models/bill.model.js | 5 ++-- .../test/integration/bill.controller.test.js | 18 +++++++++++---- 6 files changed, 45 insertions(+), 23 deletions(-) diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index 0f3266a..e6ee2c3 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"af3517a2-0c52-452e-b2ec-5fe8a90c051a":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["af3517a2-0c52-452e-b2ec-5fe8a90c051a"]},"externalIds":{}} \ No newline at end of file +{"processes":{"79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"]},"externalIds":{}} \ No newline at end of file diff --git a/server/business/bill.business.js b/server/business/bill.business.js index 7662f70..41ad743 100644 --- a/server/business/bill.business.js +++ b/server/business/bill.business.js @@ -20,8 +20,10 @@ module.exports = class BillBusiness { offset: queryString.offset ?? 0 } return this.dataLayer - .findAllAndPopulate(filter, { path: 'journey', populate: { path: 'entryLocation exitLocation' }}) - .catch((error) => { throw httpError(500, error.message)}) + .findAllAndPopulate(filter, [{ path: 'journey', populate: { path: 'entryLocation exitLocation' }}, {path: 'driver', select: 'username type email'}]) + .catch((error) => { + console.log(error) + throw httpError(500, error.message)}) } /** diff --git a/server/coverage/lcov.info b/server/coverage/lcov.info index 0b5acf5..9c3f1c6 100644 --- a/server/coverage/lcov.info +++ b/server/coverage/lcov.info @@ -51,8 +51,8 @@ SF:business\bill.business.js FN:7,(anonymous_0) FN:15,(anonymous_1) FN:24,(anonymous_2) -FN:30,(anonymous_3) -FN:35,(anonymous_4) +FN:32,(anonymous_3) +FN:37,(anonymous_4) FNF:5 FNH:4 FNDA:1,(anonymous_0) @@ -68,11 +68,12 @@ DA:6,1 DA:9,1 DA:16,5 DA:22,5 -DA:24,0 -DA:31,2 -DA:34,2 -DA:35,1 -LF:12 +DA:25,0 +DA:26,0 +DA:33,2 +DA:36,2 +DA:37,1 +LF:13 LH:11 BRDA:19,0,0,5 BRDA:19,0,1,4 @@ -312,7 +313,7 @@ end_of_record TN: SF:models\bill.model.js FN:2,(anonymous_0) -FN:26,(anonymous_1) +FN:27,(anonymous_1) FNF:2 FNH:1 FNDA:1,(anonymous_0) @@ -320,11 +321,11 @@ FNDA:0,(anonymous_1) DA:1,1 DA:2,1 DA:3,1 -DA:26,1 -DA:27,0 +DA:27,1 DA:28,0 DA:29,0 -DA:32,1 +DA:30,0 +DA:33,1 LF:8 LH:5 BRF:0 diff --git a/server/database/seed.js b/server/database/seed.js index 4dcbe75..c35987d 100644 --- a/server/database/seed.js +++ b/server/database/seed.js @@ -21,11 +21,19 @@ mongoose const users = [ { + _id: "123456789107", username: "test_username", email: "test@email.com", password: bcrypt.hashSync("test1", 8), type: "Driver", }, + { + _id: "123456789108", + username: "test_username2", + email: "test2@email.com", + password: bcrypt.hashSync("test1", 8), + type: "Driver", + }, ]; const locations = [ @@ -68,14 +76,16 @@ const bills = [ { _id: "123456789105", journey: "123456789103", - driver: "test_driver", + driver: "123456789107", + username: "test_username", cost: 5, paid: false }, { _id: "123456789106", journey: "123456789104", - driver: "test_driver2", + driver: "123456789108", + username: "test_username", cost: 5, paid: true } diff --git a/server/models/bill.model.js b/server/models/bill.model.js index 758f965..88cd7df 100644 --- a/server/models/bill.model.js +++ b/server/models/bill.model.js @@ -8,8 +8,9 @@ module.exports = mongoose => { required: [true, "A journey must be attached to a bill."], unique: true }, - driver: { - type: String, + driver: { + type: mongoose.Schema.Types.ObjectId, + ref: "user", required: [true, "A driver must be assigned to a bill."] }, cost: { diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js index 1331cf0..c2d974f 100644 --- a/server/test/integration/bill.controller.test.js +++ b/server/test/integration/bill.controller.test.js @@ -19,8 +19,10 @@ describe("Testing /bill paths", () => { res.should.be.a("object"); res.body.should.have.lengthOf(2); res.body[0].should.haveOwnProperty('cost', 72.93887106726764) - res.body[0].should.haveOwnProperty('driver', 'test_driver') res.body[0].should.haveOwnProperty('paid', false) + res.body[0].driver.should.haveOwnProperty('username', 'test_username') + res.body[0].driver.should.haveOwnProperty('email', 'test@email.com') + res.body[0].driver.should.haveOwnProperty('type', 'Driver') res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') @@ -36,7 +38,7 @@ describe("Testing /bill paths", () => { it("Should get all bills which match the driver ID", (done) => { // Arrange - const driverId = "test_driver" + const driverId = "123456789107" const url = `/bill?driver=${driverId}` // Act @@ -49,8 +51,10 @@ describe("Testing /bill paths", () => { res.should.be.a("object"); res.body.should.have.lengthOf(1); res.body[0].should.haveOwnProperty('cost', 72.93887106726764) - res.body[0].should.haveOwnProperty('driver', 'test_driver') res.body[0].should.haveOwnProperty('paid', false) + res.body[0].driver.should.haveOwnProperty('username', 'test_username') + res.body[0].driver.should.haveOwnProperty('email', 'test@email.com') + res.body[0].driver.should.haveOwnProperty('type', 'Driver') res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') res.body[0].journey.entryLocation.should.haveOwnProperty('name', 'test_location_1') @@ -79,7 +83,9 @@ describe("Testing /bill paths", () => { res.should.be.a("object"); res.body.should.have.lengthOf(1); res.body[0].should.haveOwnProperty('cost', 72.93887106726764) - res.body[0].should.haveOwnProperty('driver', 'test_driver2') + res.body[0].driver.should.haveOwnProperty('username', 'test_username2') + res.body[0].driver.should.haveOwnProperty('email', 'test2@email.com') + res.body[0].driver.should.haveOwnProperty('type', 'Driver') res.body[0].should.haveOwnProperty('paid', true) res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number2') res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.038Z') @@ -109,7 +115,9 @@ describe("Testing /bill paths", () => { res.should.be.a("object"); res.body.should.have.lengthOf(1); res.body[0].should.haveOwnProperty('cost', 72.93887106726764) - res.body[0].should.haveOwnProperty('driver', 'test_driver') + res.body[0].driver.should.haveOwnProperty('username', 'test_username') + res.body[0].driver.should.haveOwnProperty('email', 'test@email.com') + res.body[0].driver.should.haveOwnProperty('type', 'Driver') res.body[0].should.haveOwnProperty('paid', false) res.body[0].journey.should.haveOwnProperty('regNumber', 'test_reg_number') res.body[0].journey.should.haveOwnProperty('journeyDateTime', '2022-02-01T15:50:51.039Z') From 02512361d097ba90d91edb6d1c0e5ed9ff400efb Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 13:53:19 +0000 Subject: [PATCH 26/31] HT-14 Fix pipeline tests --- server/.nyc_output/processinfo/index.json | 2 +- server/database/seed.js | 2 -- server/test/integration/bill.controller.test.js | 1 + 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index e6ee2c3..5c4f95e 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["79f18387-1e6b-42e2-9aa1-4f3d5dd2f4f2"]},"externalIds":{}} \ No newline at end of file +{"processes":{"16423c71-9f0e-482c-94dc-b8d93aa45211":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"]},"externalIds":{}} \ No newline at end of file diff --git a/server/database/seed.js b/server/database/seed.js index c35987d..2c8313f 100644 --- a/server/database/seed.js +++ b/server/database/seed.js @@ -77,7 +77,6 @@ const bills = [ _id: "123456789105", journey: "123456789103", driver: "123456789107", - username: "test_username", cost: 5, paid: false }, @@ -85,7 +84,6 @@ const bills = [ _id: "123456789106", journey: "123456789104", driver: "123456789108", - username: "test_username", cost: 5, paid: true } diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js index c2d974f..7a2d0f0 100644 --- a/server/test/integration/bill.controller.test.js +++ b/server/test/integration/bill.controller.test.js @@ -47,6 +47,7 @@ describe("Testing /bill paths", () => { .send() .end((err, res) => { // Assert + res.should.have.status(200); res.should.be.a("object"); res.body.should.have.lengthOf(1); From 9c864734752a656957a2bb1142efa5a5bc642446 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 14:28:44 +0000 Subject: [PATCH 27/31] HT-14 Update price on insert many hook --- server/.nyc_output/processinfo/index.json | 2 +- server/coverage/lcov.info | 5 +++-- server/database/seed.js | 8 ++++---- server/models/bill.model.js | 8 +++++--- server/test/integration/bill.controller.test.js | 1 + 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index 5c4f95e..20d22ee 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"16423c71-9f0e-482c-94dc-b8d93aa45211":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["16423c71-9f0e-482c-94dc-b8d93aa45211"]},"externalIds":{}} \ No newline at end of file +{"processes":{"5ef259dd-faf0-4325-be8d-80d8ed87b972":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"]},"externalIds":{}} \ No newline at end of file diff --git a/server/coverage/lcov.info b/server/coverage/lcov.info index 9c3f1c6..70c4109 100644 --- a/server/coverage/lcov.info +++ b/server/coverage/lcov.info @@ -325,8 +325,9 @@ DA:27,1 DA:28,0 DA:29,0 DA:30,0 -DA:33,1 -LF:8 +DA:32,0 +DA:35,1 +LF:9 LH:5 BRF:0 BRH:0 diff --git a/server/database/seed.js b/server/database/seed.js index 2c8313f..3e1d0a3 100644 --- a/server/database/seed.js +++ b/server/database/seed.js @@ -94,10 +94,10 @@ const seedDB = async () => { await mongoose.connection.collections[collection].deleteMany() } - await mongoose.users.create(users); - await mongoose.locations.create(locations); - await mongoose.journeys.create(journeys); - await mongoose.bills.create(bills) + await mongoose.users.insertMany(users) + await mongoose.locations.insertMany(locations) + await mongoose.journeys.insertMany(journeys) + await mongoose.bills.insertMany(bills) }; seedDB() diff --git a/server/models/bill.model.js b/server/models/bill.model.js index 88cd7df..5f4d6c8 100644 --- a/server/models/bill.model.js +++ b/server/models/bill.model.js @@ -24,9 +24,11 @@ module.exports = mongoose => { } ) - billSchema.pre('save', async function (next) { - const journey = await mongoose.model('journey').findById(this.journey).populate({ path: 'entryLocation exitLocation' }) - this.cost = Utilities.calculateCost(journey) + billSchema.pre('insertMany', async function (next, docs) { + for(const index in docs){ + const journey = await mongoose.model('journey').findById(docs[index].journey).populate({path: 'entryLocation exitLocation'}) + await mongoose.model('bill').findByIdAndUpdate(docs[index]._id, docs[index].cost = Utilities.calculateCost(journey)) + } next() }) diff --git a/server/test/integration/bill.controller.test.js b/server/test/integration/bill.controller.test.js index 7a2d0f0..10e1765 100644 --- a/server/test/integration/bill.controller.test.js +++ b/server/test/integration/bill.controller.test.js @@ -80,6 +80,7 @@ describe("Testing /bill paths", () => { .send() .end((err, res) => { // Assert + res.should.have.status(200); res.should.be.a("object"); res.body.should.have.lengthOf(1); From 648124955e48319fda06ebe188cd927117a2439f Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 14:35:25 +0000 Subject: [PATCH 28/31] HT-14 remove unneeded console.log and fix code smells --- server/.nyc_output/processinfo/index.json | 2 +- server/business/bill.business.js | 1 - server/coverage/lcov.info | 20 ++++++++++---------- server/models/bill.model.js | 5 +++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index 20d22ee..7354e51 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"5ef259dd-faf0-4325-be8d-80d8ed87b972":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["5ef259dd-faf0-4325-be8d-80d8ed87b972"]},"externalIds":{}} \ No newline at end of file +{"processes":{"fc00a8a7-b024-4415-b88b-a578103cff2f":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"]},"externalIds":{}} \ No newline at end of file diff --git a/server/business/bill.business.js b/server/business/bill.business.js index 41ad743..e284c5c 100644 --- a/server/business/bill.business.js +++ b/server/business/bill.business.js @@ -22,7 +22,6 @@ module.exports = class BillBusiness { return this.dataLayer .findAllAndPopulate(filter, [{ path: 'journey', populate: { path: 'entryLocation exitLocation' }}, {path: 'driver', select: 'username type email'}]) .catch((error) => { - console.log(error) throw httpError(500, error.message)}) } diff --git a/server/coverage/lcov.info b/server/coverage/lcov.info index 70c4109..67fabb4 100644 --- a/server/coverage/lcov.info +++ b/server/coverage/lcov.info @@ -51,8 +51,8 @@ SF:business\bill.business.js FN:7,(anonymous_0) FN:15,(anonymous_1) FN:24,(anonymous_2) -FN:32,(anonymous_3) -FN:37,(anonymous_4) +FN:31,(anonymous_3) +FN:36,(anonymous_4) FNF:5 FNH:4 FNDA:1,(anonymous_0) @@ -69,11 +69,10 @@ DA:9,1 DA:16,5 DA:22,5 DA:25,0 -DA:26,0 -DA:33,2 -DA:36,2 -DA:37,1 -LF:13 +DA:32,2 +DA:35,2 +DA:36,1 +LF:12 LH:11 BRDA:19,0,0,5 BRDA:19,0,1,4 @@ -325,9 +324,10 @@ DA:27,1 DA:28,0 DA:29,0 DA:30,0 -DA:32,0 -DA:35,1 -LF:9 +DA:31,0 +DA:33,0 +DA:36,1 +LF:10 LH:5 BRF:0 BRH:0 diff --git a/server/models/bill.model.js b/server/models/bill.model.js index 5f4d6c8..4ba9bd9 100644 --- a/server/models/bill.model.js +++ b/server/models/bill.model.js @@ -26,8 +26,9 @@ module.exports = mongoose => { billSchema.pre('insertMany', async function (next, docs) { for(const index in docs){ - const journey = await mongoose.model('journey').findById(docs[index].journey).populate({path: 'entryLocation exitLocation'}) - await mongoose.model('bill').findByIdAndUpdate(docs[index]._id, docs[index].cost = Utilities.calculateCost(journey)) + const bill = docs[index] + const journey = await mongoose.model('journey').findById(bill.journey).populate({path: 'entryLocation exitLocation'}) + await mongoose.model('bill').findByIdAndUpdate(bill._id, bill.cost = Utilities.calculateCost(journey)) } next() }) From 3f211e020d6b12f5d57b112fd7b01f1e81378538 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 14:38:25 +0000 Subject: [PATCH 29/31] HT-14 Fix code smell --- server/.nyc_output/processinfo/index.json | 2 +- server/coverage/lcov.info | 7 ++++--- server/models/bill.model.js | 3 ++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index 7354e51..817faca 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"fc00a8a7-b024-4415-b88b-a578103cff2f":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["fc00a8a7-b024-4415-b88b-a578103cff2f"]},"externalIds":{}} \ No newline at end of file +{"processes":{"f2f06607-7674-438e-a2d8-01440853485b":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["f2f06607-7674-438e-a2d8-01440853485b"]},"externalIds":{}} \ No newline at end of file diff --git a/server/coverage/lcov.info b/server/coverage/lcov.info index 67fabb4..eb402f4 100644 --- a/server/coverage/lcov.info +++ b/server/coverage/lcov.info @@ -325,9 +325,10 @@ DA:28,0 DA:29,0 DA:30,0 DA:31,0 -DA:33,0 -DA:36,1 -LF:10 +DA:32,0 +DA:34,0 +DA:37,1 +LF:11 LH:5 BRF:0 BRH:0 diff --git a/server/models/bill.model.js b/server/models/bill.model.js index 4ba9bd9..c9e851c 100644 --- a/server/models/bill.model.js +++ b/server/models/bill.model.js @@ -28,7 +28,8 @@ module.exports = mongoose => { for(const index in docs){ const bill = docs[index] const journey = await mongoose.model('journey').findById(bill.journey).populate({path: 'entryLocation exitLocation'}) - await mongoose.model('bill').findByIdAndUpdate(bill._id, bill.cost = Utilities.calculateCost(journey)) + const cost = Utilities.calculateCost(journey) + await mongoose.model('bill').findByIdAndUpdate(bill._id, bill.cost = cost) } next() }) From 120bb76899a1983c735648bcbe9fa4a6c35d8110 Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 14:40:30 +0000 Subject: [PATCH 30/31] HT-14 Fix code smell --- server/.nyc_output/processinfo/index.json | 2 +- server/models/bill.model.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index 817faca..d207ad0 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"f2f06607-7674-438e-a2d8-01440853485b":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["f2f06607-7674-438e-a2d8-01440853485b"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["f2f06607-7674-438e-a2d8-01440853485b"]},"externalIds":{}} \ No newline at end of file +{"processes":{"8889d08b-7017-4db4-b719-dcb609e1cca7":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"]},"externalIds":{}} \ No newline at end of file diff --git a/server/models/bill.model.js b/server/models/bill.model.js index c9e851c..1413b84 100644 --- a/server/models/bill.model.js +++ b/server/models/bill.model.js @@ -28,8 +28,8 @@ module.exports = mongoose => { for(const index in docs){ const bill = docs[index] const journey = await mongoose.model('journey').findById(bill.journey).populate({path: 'entryLocation exitLocation'}) - const cost = Utilities.calculateCost(journey) - await mongoose.model('bill').findByIdAndUpdate(bill._id, bill.cost = cost) + bill.cost = Utilities.calculateCost(journey) + await mongoose.model('bill').findByIdAndUpdate(bill._id, bill) } next() }) From 0ddd85102bd4a0e933c63749bb48cd0e6afcf4cc Mon Sep 17 00:00:00 2001 From: Jake Date: Wed, 2 Feb 2022 15:19:27 +0000 Subject: [PATCH 31/31] HT-14 Add unit tests for utilities function --- server/.nyc_output/processinfo/index.json | 2 +- server/coverage/lcov.info | 8 +++--- server/test/unit/utilities.test.js | 34 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 server/test/unit/utilities.test.js diff --git a/server/.nyc_output/processinfo/index.json b/server/.nyc_output/processinfo/index.json index d207ad0..e2f59c3 100644 --- a/server/.nyc_output/processinfo/index.json +++ b/server/.nyc_output/processinfo/index.json @@ -1 +1 @@ -{"processes":{"8889d08b-7017-4db4-b719-dcb609e1cca7":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["8889d08b-7017-4db4-b719-dcb609e1cca7"]},"externalIds":{}} \ No newline at end of file +{"processes":{"4d150775-f277-4c3e-a138-a2031d24611b":{"parent":null,"children":[]}},"files":{"C:\\Projects\\CSSD-Assignment\\server\\app.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\database\\index.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\config\\db.config.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\journey.model.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\bill.model.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\utilities.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\location.model.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\models\\user.model.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\auth.routes.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\auth.controller.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\business\\user.business.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\datalayer\\mongo.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\routes\\bill.routes.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\controllers\\bill.controller.js":["4d150775-f277-4c3e-a138-a2031d24611b"],"C:\\Projects\\CSSD-Assignment\\server\\business\\bill.business.js":["4d150775-f277-4c3e-a138-a2031d24611b"]},"externalIds":{}} \ No newline at end of file diff --git a/server/coverage/lcov.info b/server/coverage/lcov.info index eb402f4..d615551 100644 --- a/server/coverage/lcov.info +++ b/server/coverage/lcov.info @@ -35,14 +35,14 @@ TN: SF:utilities.js FN:4,(anonymous_0) FNF:1 -FNH:0 -FNDA:0,(anonymous_0) +FNH:1 +FNDA:1,(anonymous_0) DA:1,1 DA:3,1 -DA:5,0 +DA:5,1 DA:8,1 LF:4 -LH:3 +LH:4 BRF:0 BRH:0 end_of_record diff --git a/server/test/unit/utilities.test.js b/server/test/unit/utilities.test.js new file mode 100644 index 0000000..d994c08 --- /dev/null +++ b/server/test/unit/utilities.test.js @@ -0,0 +1,34 @@ +let chai = require("chai"); +let should = chai.should(); +const Utilities = require("../../utilities") + +describe("Testing utilities functions", () => { + it("Calculate cost based on distance travelled", (done) => { + // Arrange + const location1 = { + name: "test_location1", + coordinates: { + longitude: 0, + latitude: 0 + } + } + const location2 = { + name: "test_location2", + coordinates: { + longitude: 50, + latitude: 50 + } + } + const journey = { + entryLocation: location1, + exitLocation: location2 + } + + // Act + const cost = Utilities.calculateCost(journey) + + // Assert + cost.should.equal(72.93887106726764) + done(); + }) +}) \ No newline at end of file