From 01dbc9f6f1c918c6bcee9d5e5601cb9a16de8f02 Mon Sep 17 00:00:00 2001 From: cindyliang01 Date: Mon, 13 Nov 2023 22:35:44 -0500 Subject: [PATCH] Wrote tests for home and login page --- back-end/package.json | 6 +++++- back-end/tests/homeRoute.test.js | 23 +++++++++++++++++++++++ back-end/tests/loginTest.js | 27 +-------------------------- 3 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 back-end/tests/homeRoute.test.js diff --git a/back-end/package.json b/back-end/package.json index 28a7c5d..7cd8c24 100644 --- a/back-end/package.json +++ b/back-end/package.json @@ -4,7 +4,8 @@ "description": "The back-end of your project will live in this directory.", "main": "server.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "mocha", + "coverage": "c8 mocha" }, "author": "", "license": "ISC", @@ -14,6 +15,9 @@ "express": "^4.18.2" }, "devDependencies": { + "chai": "^4.3.10", + "chai-http": "^4.4.0", + "mocha": "^10.2.0", "nodemon": "^3.0.1" } } diff --git a/back-end/tests/homeRoute.test.js b/back-end/tests/homeRoute.test.js new file mode 100644 index 0000000..3441b45 --- /dev/null +++ b/back-end/tests/homeRoute.test.js @@ -0,0 +1,23 @@ +const chai = require("chai"); +const chaiHttp = require("chai-http"); +const server = require("../app"); +const expect = chai.expect; + +chai.use(chaiHttp); + +describe(" GET Endpoint for Home", () => { + describe("/GET /home", () => { + it("it should return a 200 status code", (done) => { + chai + .request(server) + .get("/home") + .end((err, res) => { + expect(res).to.have.status(200); + expect(res.body).to.be.a("object"); + expect(res.body).to.have.property("id"); + expect(res.body).to.have.property("name"); + done(); + }); + }); + }); +}); diff --git a/back-end/tests/loginTest.js b/back-end/tests/loginTest.js index 7a61517..1e25492 100644 --- a/back-end/tests/loginTest.js +++ b/back-end/tests/loginTest.js @@ -1,44 +1,19 @@ -// const chai = require("chai"); -// const request = require("supertest"); -// const app = require("../app"); -// const expect = chai.expect; - -// describe("Login Endpoint", function () { -// it("should return a 200 status code and a success message", function (done) { -// request(app) -// .post("/") -// .send({ username: "testuser", password: "testpassword" }) -// .expect(200) -// .expect("Content-Type", /json/) -// .end(function (err, res) { -// if (err) return done(err); -// const response = res.body; -// expect(response) -// .to.have.property("message") -// .equal("We recieved your data!"); -// done(); -// }); -// }); - const chai = require("chai"); const chaiHttp = require("chai-http"); const server = require("../app"); const expect = chai.expect; chai.use(chaiHttp); -chai.should(); describe(" GET Endpoint for Login", () => { describe("/GET /", () => { - it("it should return a 200 status code and a success message", (done) => { + it("it should return a 200 status code", (done) => { chai .request(server) .get("/") .end((err, res) => { - // res.should.have.status(200); expect(res).to.have.status(200); - // res.body.should.be.a("array"); done(); }); });