Skip to content

Commit

Permalink
Wrote tests for home and login page
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyliang01 committed Nov 14, 2023
1 parent 3352748 commit 01dbc9f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
6 changes: 5 additions & 1 deletion back-end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
23 changes: 23 additions & 0 deletions back-end/tests/homeRoute.test.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
});
27 changes: 1 addition & 26 deletions back-end/tests/loginTest.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
Expand Down

0 comments on commit 01dbc9f

Please sign in to comment.