Skip to content

Commit

Permalink
Merge pull request #198 from agiledev-students-fall2023/update-tests
Browse files Browse the repository at this point in the history
Updated tests for login, signup, forgot password, and logout
  • Loading branch information
cindyliang01 authored Dec 5, 2023
2 parents 02a371e + d13f59e commit 107af8e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 10 deletions.
28 changes: 26 additions & 2 deletions back-end/test/forgotPasswordRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,35 @@ describe("POST for Forgot Password", () => {
chai
.request(app)
.post("/forgot-password")
.send({ username: "testuser", password: "testnewpassword" })
.send({
email: "[email protected]",
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: "[email protected]",
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();
});
Expand Down
26 changes: 22 additions & 4 deletions back-end/test/loginRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,37 @@ 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("success", true);
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("success", false);
expect(res.body).to.have.property("message");
done();
});
Expand Down
1 change: 1 addition & 0 deletions back-end/test/logoutRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
28 changes: 24 additions & 4 deletions back-end/test/signupRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,34 @@ describe("POST for Signup", () => {
.request(app)
.post("/signup")
.send({
email: "testemail",
username: "testuser",
password: "testpassword",
email: "[email protected]",
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("status", "Success");
expect(res.body).to.have.property("success", true);
expect(res.body).to.have.property("message");
done();
});
});
});

describe("POST /signup", () => {
it("should return a unsuccessful response", (done) => {
chai
.request(app)
.post("/signup")
.send({
email: "[email protected]",
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("success", false);
expect(res.body).to.have.property("message");
done();
});
Expand Down

0 comments on commit 107af8e

Please sign in to comment.