Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongoose2 #500

Open
wants to merge 64 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6a83034
Adding test docs folder and docs
Swright88 Jun 12, 2023
695b1a7
Reversed posts
Swright88 Jun 13, 2023
3cb3a40
Install dotenv
cutetofuu Jun 13, 2023
cdc17ed
Set up production environment
cutetofuu Jun 13, 2023
57982b6
Add first and last names
cutetofuu Jun 13, 2023
bb69b3d
Merge branch 'main' into mongodb-setup
cutetofuu Jun 13, 2023
322ac35
Merge pull request #1 from MMal87/mongodb-setup
cutetofuu Jun 13, 2023
cbc2ab1
changes
Chrishall17 Jun 13, 2023
05da992
working on posts and comments
MMal87 Jun 13, 2023
f609f27
working on comments
MMal87 Jun 14, 2023
be596ed
changes
Chrishall17 Jun 14, 2023
783fd87
add seed data to development, create profile page/routes
AlexBuz-web Jun 14, 2023
376c233
Add login and signup links
cutetofuu Jun 14, 2023
54aec43
Install bcrypt
cutetofuu Jun 14, 2023
a991cef
Add password hashing feature
cutetofuu Jun 14, 2023
eba3db6
comments working
MMal87 Jun 14, 2023
f17c9fa
draft posts tests
Swright88 Jun 14, 2023
87d82d0
implement list of friends and non-friends on profile page first draft
AlexBuz-web Jun 14, 2023
ed399e3
ability to add and remove friends from database and show on html page
AlexBuz-web Jun 14, 2023
9a21f63
Update seed data
cutetofuu Jun 14, 2023
2614eab
like button work
MMal87 Jun 14, 2023
9c6eee2
"css and password validation"
Chrishall17 Jun 14, 2023
983e89d
Merge branch 'tester-ch' into main
Chrishall17 Jun 15, 2023
2bd6624
Merge pull request #2 from MMal87/main
Chrishall17 Jun 15, 2023
23a92b1
ready to merge
Chrishall17 Jun 15, 2023
1274bb9
Merge pull request #3 from MMal87/tester-ch
Chrishall17 Jun 15, 2023
8eaafd9
Created a couple of tests, added input on show.hbs
PHagan23 Jun 15, 2023
11cd474
"changes"
Chrishall17 Jun 15, 2023
da65184
when user submits add friend it goes into friend requests section for…
AlexBuz-web Jun 15, 2023
7e92548
changes to likes
MMal87 Jun 15, 2023
b8e3bc9
likes
MMal87 Jun 15, 2023
916111c
"changes"
Chrishall17 Jun 15, 2023
f7eea29
Merge pull request #4 from MMal87/tester-ch
Chrishall17 Jun 15, 2023
70ffa0d
added tests
PHagan23 Jun 15, 2023
d91efa1
changes
Chrishall17 Jun 15, 2023
8b24f6b
Add login and signup error messages
cutetofuu Jun 15, 2023
4e85664
Merge pull request #5 from MMal87/tester-ch
Chrishall17 Jun 15, 2023
665f935
Merge branch 'main' into signup-validation
cutetofuu Jun 15, 2023
0b82e3e
likes and comments
MMal87 Jun 15, 2023
a4c7568
likes
MMal87 Jun 15, 2023
9d8f035
edited likebutton name
MMal87 Jun 15, 2023
5c05679
likebutton
MMal87 Jun 15, 2023
e6ef101
fix bug and page now updates after accepting friend request to reflec…
AlexBuz-web Jun 15, 2023
9e68988
Update stylesheet links
cutetofuu Jun 15, 2023
0b61a7b
Update error message
cutetofuu Jun 15, 2023
61fa331
likes on index page
MMal87 Jun 15, 2023
fa1ede2
Merge branch 'main' into tuesday
ClaudiaGC1339 Jun 15, 2023
9704f5c
Merge pull request #7 from MMal87/tuesday
ClaudiaGC1339 Jun 15, 2023
65e0f4a
Add form validation with regex
cutetofuu Jun 15, 2023
07a1111
Merge branch 'main' to signup-validation
cutetofuu Jun 15, 2023
22d62f9
fixed some styling issues
AlexBuz-web Jun 15, 2023
9ba2005
Merge branch 'main' into mongoose
AlexBuzea Jun 15, 2023
74f0516
Merge pull request #8 from MMal87/mongoose
AlexBuzea Jun 15, 2023
2b25996
Update routes
cutetofuu Jun 15, 2023
dc750fe
Merge branch 'main' into signup-validation
cutetofuu Jun 15, 2023
78803e8
Merge pull request #6 from MMal87/signup-validation
cutetofuu Jun 15, 2023
7ed740e
Update seed data with hashed passwords
cutetofuu Jun 16, 2023
e24fa8b
Merge pull request #9 from MMal87/update-seed-data
cutetofuu Jun 16, 2023
ebb2155
Add user to seed data
cutetofuu Jun 16, 2023
892919c
Merge branch 'main' of https://github.com/MMal87/acebook-neutral into…
cutetofuu Jun 16, 2023
037b447
Merge pull request #10 from MMal87/update-seed-data
cutetofuu Jun 16, 2023
d75a31f
fix remove friend
AlexBuz-web Jun 16, 2023
8c968a1
fix bug where use
AlexBuz-web Jun 16, 2023
e142210
add sentFriendRequests field to user model in order to evaluate wheth…
AlexBuz-web Jun 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It uses:

## Card wall

REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
https://trello.com/invite/b/Fv5Elopq/ATTI7a7e4a5260b33e9bf40ad2a5da74932bF6FF7822/acebook-team-neutral

## Quickstart

Expand Down
83 changes: 83 additions & 0 deletions Test Documents/Acebook-Test-Plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Acebook Test Plan

## Objective

This test plan intends to outline the testing that will be performed on the Acebook code that is being developed by our team.
It will aim to highlight potential bugs in the software and provide information on their severity and priority prior to deployment.

The Acebook website is a piece of software that aims to allow a user to:
- Sign up
- Log in
- Edit and update their profile
- Create and publish a post
- View a list of users that they can send a friend request to
- Approve and deny friend requests
- View a list of their friends
- View feed
- Comment and like posts from other users
- Log out


## Scope of testing

We are going to test all of the main pieces of functionality from a users perspective. We will also include some validation checking for areas such as email addresses and user passwords. In addition we will be testing the database functionaility for items such as unique user ID's and the integration between each database.

## Test environment

These test sessions will be conducted in VSCode as well as multiple modern browsers starting with Chrome and moving to Firefox.

## Test Team

The test team consists of 4 testers.

- Sean Wright
- James Turnbull
- Chris Hall
- Patrick Hagan

## Features to be tested

- User sign up and field validity checks
- Login
- Log out
- Page navigation (once logged in)
- Duplicate user accounts (blocked)
- Users can create a post (can consist of text and/or pictures)
- Editing profile
- Check that a user can add a profile picture
- Check name and picture appears beside their own posts
- Sending friend requests
- Approving/denying a friend request
- View list of friends
- View list of users they may know
- Be able to comment on a post in their feed
- Be able to like a post in their feed and view the number of likes for that post

## Assumptions

During these tests certain assumptions will be made to make testing more effective and efficient. These assumptions are as follows:

- Only users logged in will be able to make a post
- The language will be English
-

## Defect management

When a defect is found it will be noted and a bug report will be created containing the details of the issue as well as the steps to reproduce. These will then be placed onto the teams Trello board in the 'Reviewed - Needs action' list. From here it will be picked up by the development team and then resubmitted for review by the test team. Once the tests have been conducted and the team is happy the task will be placed into the 'Done' list.

## Risks

| Risk | Mitigation |
| ---- | ---------- |
| Friction within the team. | Talk through issues/use coaches where needed. |
| Recent intermittent internet access in testers home. | Use of hot spot if necessary. |
| Time limit not allowing for all features to be tested. | Limit straying or chasing rabit holes. |
| Lack of knowledge of language and codebase for testers. | Use coaches/devs and the internet to upskill |

## Exit criteria

The project will be deemed completed once all of the tasks on the Trello board are placed into done or when the time limit has been reached (02/06/2023).




70 changes: 43 additions & 27 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const homeRouter = require("./routes/home");
const postsRouter = require("./routes/posts");
const sessionsRouter = require("./routes/sessions");
const usersRouter = require("./routes/users");
const profileRouter = require("./routes/profile");
const commentsRouter = require("./routes/posts");
const { AsyncLocalStorage } = require("async_hooks");


const app = express();

Expand All @@ -25,54 +29,66 @@ app.use(express.static(path.join(__dirname, "public")));
app.use(methodOverride("_method"));

app.use(
session({
key: "user_sid",
secret: "super_secret",
resave: false,
saveUninitialized: false,
cookie: {
expires: 600000,
},
})
session({
key: "user_sid",
secret: "super_secret",
resave: false,
saveUninitialized: false,
cookie: {
expires: 600000,
},
})
);

// clear the cookies after user logs out
// clear the cookies and session after user logs out
app.use((req, res, next) => {
if (req.cookies.user_sid && !req.session.user) {
res.clearCookie("user_sid");
}
next();
});
if (req.cookies.user_sid && !req.session.user) {
res.clearCookie("user_sid");
req.session.friendRequestSent = null; // Clear the friendRequestSent value
}
next();
});

// middleware function to check for logged-in users
const sessionChecker = (req, res, next) => {
if (!req.session.user && !req.cookies.user_sid) {
res.redirect("/sessions/new");
} else {
next();
}
if (!req.session.user && !req.cookies.user_sid) {
res.redirect("/sessions/new");
} else {
next();
}
};

// route setup
app.use("/", homeRouter);
app.use("/posts", sessionChecker, postsRouter);
app.use("/sessions", sessionsRouter);
app.use("/users", usersRouter);
app.use("/profile", profileRouter);
app.use("/:postId", sessionChecker, postsRouter);
app.use("/:postId/comments", sessionChecker, commentsRouter);
app.use("/:postId/like", sessionChecker, postsRouter);

// catch 404 and forward to error handler
app.use((req, res, next) => {
next(createError(404));
console.log("Hellooooooo");
next(createError(404));
});

app.use((req, res, next) => {
console.log("Hellooooooo");
next(createError(400));
});

// error handler
app.use((err, req, res) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get("env") === "development" ? err : {};

// render the error page
res.status(err.status || 500);
res.render("error");
// render the error page
res.status(err.status || 500);
res.render("error");
});

module.exports = app;
module.exports.sessionChecker = sessionChecker;
94 changes: 50 additions & 44 deletions bin/www
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
#!/usr/bin/env node
// #!/usr/bin/env node


/**
* Module dependencies.
*/

var app = require("../app");
var debug = require("debug")("acebook:server");
var http = require("http");
var mongoose = require("mongoose");
let app = require("../app");
let debug = require("debug")("acebook:server");
let http = require("http");
let mongoose = require("mongoose");

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || "3000");
let port = normalizePort(process.env.PORT || "3000");
app.set("port", port);

/**
* Connect to MongoDB
**/

var mongoDbUrl = process.env.MONGODB_URL || "mongodb://0.0.0.0/acebook";
require("dotenv").config();

let mongoDbUrl = process.env.MONGODB_URL || "mongodb://0.0.0.0/acebook";
mongoose.connect(mongoDbUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
useNewUrlParser: true,
useUnifiedTopology: true,
});

var db = mongoose.connection;
let db = mongoose.connection;
db.on("error", console.error.bind(console, "MongoDB connection error:"));

/**
* Create HTTP server.
*/

var server = http.createServer(app);
let server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
Expand All @@ -48,54 +51,57 @@ server.on("listening", onListening);
*/

function normalizePort(val) {
var port = parseInt(val, 10);
let port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}
if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}
if (port >= 0) {
// port number
return port;
}

return false;
return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== "listen") {
throw error;
}

var bind = typeof port === "string" ? "Pipe " + port : "Port " + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case "EACCES":
console.error(bind + " requires elevated privileges");
process.exit(1);
break;
case "EADDRINUSE":
console.error(bind + " is already in use");
process.exit(1);
break;
default:
throw error;
}
if (error.syscall !== "listen") {
throw error;
}

let bind = typeof port === "string" ? "Pipe " + port : "Port " + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case "EACCES":
console.error(bind + " requires elevated privileges");
// eslint-disable-next-line no-process-exit
process.exit(1);
break;
case "EADDRINUSE":
console.error(bind + " is already in use");
// eslint-disable-next-line no-process-exit
process.exit(1);
break;
default:
throw error;
}

}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
console.log("Now listening on " + bind);
debug("Listening on " + bind);
let addr = server.address();
let bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
console.log("Now listening on " + bind);
debug("Listening on " + bind);
}
41 changes: 41 additions & 0 deletions controllers/comments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//const Comment = require("../models/comments");
const Post = require("../models/post");

const CommentsController = {
CreateComment: (req, res) => {
const { message } = req.body; // Extract the comment data from the request body

Post.findById(req.params.postId)
.then((post) => {
post.comments = post.comments || [];
// Create a new comment object
const newComment = { message };

// Add the new comment to the comments array of the post
post.comments.unshift(newComment);

return post.save(); // Save the updated post with the new comment
})
.then(() => res.redirect(`/posts/${req.params.postId}`))
.catch((err) => {
console.log(err);
});
}

};


module.exports = CommentsController;


// const comment = new Comment(req.body);
// comment.save()
// .then(() => Post.findById(req.params.postId))
// .then((post) => {
// post.comments.unshift(comment);
// return post.save();
// })
// .then(() => res.redirect(`/posts/${req.params.postId}`))
// .catch((err) => {
// console.log(err);
// });
Loading