generated from nyu-software-engineering/generic-mern-stack-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from agiledev-students-spring2024/unit-tests
Added tests for friends
- Loading branch information
Showing
2 changed files
with
111 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
const chai = require('chai'); | ||
const chaiHttp = require('chai-http'); | ||
const app = require('../app.js'); | ||
const chai = require("chai"); | ||
const chaiHttp = require("chai-http"); | ||
const app = require("../app.js"); | ||
const expect = chai.expect; | ||
|
||
chai.use(chaiHttp); | ||
|
@@ -21,76 +21,113 @@ describe('Name', () => { | |
}) | ||
*/ | ||
|
||
describe('Login & Signup', () => { | ||
// successful login - TODO : failing | ||
describe('Successful login of an existing user', () => { | ||
it('should log in existing user', (done) => { | ||
chai.request(app) | ||
.post('/users/login') | ||
.send({'email' : '[email protected]', 'password' : '123'}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
expect(res.body).to.be.an('object'); | ||
expect(res.body).to.have.property('id'); | ||
expect(res.body).to.have.property('fullname', 'John Doe'); | ||
expect(res.body).to.have.property('username', 'John'); | ||
done(); | ||
}) | ||
}) | ||
}) | ||
|
||
// failed login due to incorrect email address | ||
describe('Failed login, email not found', (done) => { | ||
it('should return 401', (done) => { | ||
chai.request(app) | ||
.post('/users/login') | ||
.send({'email' : '[email protected]', 'password': '123'}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(401) | ||
expect(res.body).to.be.an('object') | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
|
||
// failed login due to incorrect password | ||
describe('Failed login, incorrect password', (done) => { | ||
it('should return 401', (done) => { | ||
chai.request(app) | ||
.post('/users/login') | ||
.send({'email' : '[email protected]', 'password': 'incorrectPassword'}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(401) | ||
expect(res.body).to.be.an('object') | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
// successful signup | ||
describe('Successful signup of new user', () => { | ||
it ('should register new user', (done) => { | ||
chai.request(app) | ||
.post('/users/register') | ||
.send({'fullname' : 'Tester', 'username' : 'testing', 'email' : '[email protected]', 'password' : '123'}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(201) | ||
expect(res.body).to.be.an('object') | ||
done() | ||
}) | ||
describe("Login & Signup", () => { | ||
// successful login - TODO : failing | ||
describe("Successful login of an existing user", () => { | ||
it("should log in existing user", (done) => { | ||
chai | ||
.request(app) | ||
.post("/users/login") | ||
.send({ email: "[email protected]", password: "123" }) | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
expect(res.body).to.be.an("object"); | ||
expect(res.body).to.have.property("id"); | ||
expect(res.body).to.have.property("fullname", "John Doe"); | ||
expect(res.body).to.have.property("username", "John"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
// failed login due to incorrect email address | ||
describe("Failed login, email not found", (done) => { | ||
it("should return 401", (done) => { | ||
chai | ||
.request(app) | ||
.post("/users/login") | ||
.send({ email: "[email protected]", password: "123" }) | ||
.end((err, res) => { | ||
expect(res).to.have.status(401); | ||
expect(res.body).to.be.an("object"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
// failed login due to incorrect password | ||
describe("Failed login, incorrect password", (done) => { | ||
it("should return 401", (done) => { | ||
chai | ||
.request(app) | ||
.post("/users/login") | ||
.send({ email: "[email protected]", password: "incorrectPassword" }) | ||
.end((err, res) => { | ||
expect(res).to.have.status(401); | ||
expect(res.body).to.be.an("object"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
// successful signup | ||
describe("Successful signup of new user", () => { | ||
it("should register new user", (done) => { | ||
chai | ||
.request(app) | ||
.post("/users/register") | ||
.send({ | ||
fullname: "Tester", | ||
username: "testing", | ||
email: "[email protected]", | ||
password: "123", | ||
}) | ||
}) | ||
}) | ||
.end((err, res) => { | ||
expect(res).to.have.status(201); | ||
expect(res.body).to.be.an("object"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Book Routes", () => { | ||
it("should get all books", (done) => { | ||
chai | ||
.request(app) | ||
.get("/books") | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
expect(res.body).to.be.an("array"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("Friends", () => { | ||
describe("Friend Shelf Route", () => { | ||
it("should display friends", (done) => { | ||
chai | ||
.request(app) | ||
.get("/friendShelf") | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
expect(res.body).to.be.an("object"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Book Routes', () => { | ||
it('should get all books', (done) => { | ||
chai.request(app) | ||
.get('/books') | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
expect(res.body).to.be.an('array'); | ||
done(); | ||
}); | ||
describe("Friends Route", () => { | ||
it("Friends Page Route", (done) => { | ||
chai | ||
.request(app) | ||
.get("/Friends") | ||
.end((err, res) => { | ||
expect(res).to.have.status(200); | ||
expect(res.body).to.be.an("object"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters