Skip to content

Commit

Permalink
Merge pull request #101 from agiledev-students-spring2024/unit-tests
Browse files Browse the repository at this point in the history
Added tests for friends
  • Loading branch information
hah8236 authored Apr 2, 2024
2 parents d68e21a + aa68567 commit e0a72fb
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 73 deletions.
183 changes: 110 additions & 73 deletions back-end/tests/test.js
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);
Expand All @@ -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();
});
});
});
});
});
1 change: 1 addition & 0 deletions front-end/src/components/FriendShelf.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const FriendShelf = ({ friendsList = friendsReading }) => {
<div className="absolute m-0 top-0 left-0 right-0 h-full flex justify-center items-center backdrop-blur-sm">
<div className="flex flex-col justify-center items-center rounded-lg friendPreview z-10 top-14 left-1/6 flex w-4/6 h-4/5 bg-white fixed">
<h1 className="font-semibold text-3xl text-gray-900">{`${popupFriendName.friendName} is reading...`}</h1>
{/* include links to the friend's profile as well as to the book's page */}
<img
className="m-10"
src={`http://localhost:3001/books/${popupFriendName.bookTitle}`}
Expand Down

0 comments on commit e0a72fb

Please sign in to comment.