Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyliang01 committed Dec 5, 2023
1 parent 703e5ac commit fc48710
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
24 changes: 20 additions & 4 deletions back-end/test/loginRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
26 changes: 22 additions & 4 deletions back-end/test/signupRoute.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,32 @@ describe("POST for Signup", () => {
.request(app)
.post("/signup")
.send({
email: "testemail",
username: "testuser",
password: "testpassword",
email: "[email protected]",
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: "[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("message");
done();
});
Expand Down

0 comments on commit fc48710

Please sign in to comment.