From fc48710b4df721824c903c7affbac08b084abf37 Mon Sep 17 00:00:00 2001 From: cindyliang01 Date: Tue, 5 Dec 2023 14:11:06 -0500 Subject: [PATCH 1/2] Updated tests --- back-end/test/loginRoute.test.js | 24 ++++++++++++++++++++---- back-end/test/signupRoute.test.js | 26 ++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/back-end/test/loginRoute.test.js b/back-end/test/loginRoute.test.js index 976d5f8..cdb2ba5 100644 --- a/back-end/test/loginRoute.test.js +++ b/back-end/test/loginRoute.test.js @@ -3,19 +3,35 @@ const chaiHttp = require("chai-http"); const app = require("../app"); const expect = chai.expect; +const should = chai.should(); // the same assertion library in the style using the word 'should' + chai.use(chaiHttp); describe("POST for Login", () => { - describe("POST /", () => { - it("should return a success response", (done) => { + describe("POST / with correct login credentials", () => { + it("should return a 200 success response", (done) => { chai .request(app) .post("/") - .send({ username: "testuser", password: "testpassword" }) + .send({ username: "cindy", password: "hi" }) .end((err, res) => { expect(res).to.have.status(200); expect(res.body).to.be.a("object"); - expect(res.body).to.have.property("status", "Success"); + expect(res.body).to.have.property("message"); + done(); + }); + }); + }); + + describe("POST / with incorrect login credentials", () => { + it("should return a 401 unauthorized response", (done) => { + chai + .request(app) + .post("/") + .send({ username: "incorrect", password: "incorrect" }) + .end((err, res) => { + expect(res).to.have.status(401); + expect(res.body).to.be.a("object"); expect(res.body).to.have.property("message"); done(); }); diff --git a/back-end/test/signupRoute.test.js b/back-end/test/signupRoute.test.js index 2e07f4f..59d1feb 100644 --- a/back-end/test/signupRoute.test.js +++ b/back-end/test/signupRoute.test.js @@ -12,14 +12,32 @@ describe("POST for Signup", () => { .request(app) .post("/signup") .send({ - email: "testemail", - username: "testuser", - password: "testpassword", + email: "wrongnewtest01@gmail9.com", + username: "wrongnewtestuser019", + password: "wrongnewtestpassword", }) .end((err, res) => { expect(res).to.have.status(200); expect(res.body).to.be.a("object"); - expect(res.body).to.have.property("status", "Success"); + expect(res.body).to.have.property("message"); + done(); + }); + }); + }); + + describe("POST /signup", () => { + it("should return a unsuccess response", (done) => { + chai + .request(app) + .post("/signup") + .send({ + email: "cindyliang01@gmail.com", + username: "cindy", + password: "hi", + }) + .end((err, res) => { + expect(res).to.have.status(409); + expect(res.body).to.be.a("object"); expect(res.body).to.have.property("message"); done(); }); From d13f59e1e0259d7acc11ea6c66970e719ecbd7ec Mon Sep 17 00:00:00 2001 From: cindyliang01 Date: Tue, 5 Dec 2023 14:29:13 -0500 Subject: [PATCH 2/2] Updated tests --- back-end/test/forgotPasswordRoute.test.js | 28 +++++++++++++++++++++-- back-end/test/loginRoute.test.js | 2 ++ back-end/test/logoutRoute.test.js | 1 + back-end/test/signupRoute.test.js | 8 ++++--- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/back-end/test/forgotPasswordRoute.test.js b/back-end/test/forgotPasswordRoute.test.js index c337ab6..5205928 100644 --- a/back-end/test/forgotPasswordRoute.test.js +++ b/back-end/test/forgotPasswordRoute.test.js @@ -11,11 +11,35 @@ describe("POST for Forgot Password", () => { chai .request(app) .post("/forgot-password") - .send({ username: "testuser", password: "testnewpassword" }) + .send({ + email: "candy@gmail.com", + username: "candy", + newPassword: "candy01", + }) .end((err, res) => { expect(res).to.have.status(200); expect(res.body).to.be.a("object"); - expect(res.body).to.have.property("status", "Success"); + expect(res.body).to.have.property("success", true); + expect(res.body).to.have.property("message"); + done(); + }); + }); + }); + + describe("POST /forgot-password", () => { + it("should return an unsuccessful response", (done) => { + chai + .request(app) + .post("/forgot-password") + .send({ + email: "candy01@gmail.com", + username: "candy", + newPassword: "candy01", + }) + .end((err, res) => { + expect(res).to.have.status(404); + expect(res.body).to.be.a("object"); + expect(res.body).to.have.property("success", false); expect(res.body).to.have.property("message"); done(); }); diff --git a/back-end/test/loginRoute.test.js b/back-end/test/loginRoute.test.js index cdb2ba5..adee07a 100644 --- a/back-end/test/loginRoute.test.js +++ b/back-end/test/loginRoute.test.js @@ -17,6 +17,7 @@ describe("POST for Login", () => { .end((err, res) => { expect(res).to.have.status(200); expect(res.body).to.be.a("object"); + expect(res.body).to.have.property("success", true); expect(res.body).to.have.property("message"); done(); }); @@ -32,6 +33,7 @@ describe("POST for Login", () => { .end((err, res) => { expect(res).to.have.status(401); expect(res.body).to.be.a("object"); + expect(res.body).to.have.property("success", false); expect(res.body).to.have.property("message"); done(); }); diff --git a/back-end/test/logoutRoute.test.js b/back-end/test/logoutRoute.test.js index f9e5d7e..3477de4 100644 --- a/back-end/test/logoutRoute.test.js +++ b/back-end/test/logoutRoute.test.js @@ -14,6 +14,7 @@ describe(" GET Endpoint for logout", () => { .end((err, res) => { expect(res).to.have.status(200); expect(res.body).to.be.a("object"); + expect(res.body).to.have.property("success", true); done(); }); }); diff --git a/back-end/test/signupRoute.test.js b/back-end/test/signupRoute.test.js index 59d1feb..4f27608 100644 --- a/back-end/test/signupRoute.test.js +++ b/back-end/test/signupRoute.test.js @@ -12,13 +12,14 @@ describe("POST for Signup", () => { .request(app) .post("/signup") .send({ - email: "wrongnewtest01@gmail9.com", - username: "wrongnewtestuser019", + email: "wrongnewtest01@gmail129.com", + username: "wrongnewtestuser01129", password: "wrongnewtestpassword", }) .end((err, res) => { expect(res).to.have.status(200); expect(res.body).to.be.a("object"); + expect(res.body).to.have.property("success", true); expect(res.body).to.have.property("message"); done(); }); @@ -26,7 +27,7 @@ describe("POST for Signup", () => { }); describe("POST /signup", () => { - it("should return a unsuccess response", (done) => { + it("should return a unsuccessful response", (done) => { chai .request(app) .post("/signup") @@ -38,6 +39,7 @@ describe("POST for Signup", () => { .end((err, res) => { expect(res).to.have.status(409); expect(res.body).to.be.a("object"); + expect(res.body).to.have.property("success", false); expect(res.body).to.have.property("message"); done(); });