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

Updated like button #473

Open
wants to merge 108 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
7e621a7
Test_time
TheMany172 Feb 6, 2023
49f1d2e
add the like button and increment
C-M-Silva Feb 7, 2023
b5748a0
sessions like nearly
PDyson1400 Feb 7, 2023
86ce444
initial commit, added file as template in .github folder
TheMany172 Feb 7, 2023
98b3f44
like button functionality
PDyson1400 Feb 7, 2023
674f07c
Merge pull request #1 from PDyson1400/like_button
MarkRobins81 Feb 7, 2023
bb4c281
test the first part
TheMany172 Feb 7, 2023
c34bc01
edited the cicd files
TheMany172 Feb 7, 2023
d444e4a
amended the start in the yml file
TheMany172 Feb 7, 2023
0abf236
validation
Feb 7, 2023
a51921f
Merge pull request #2 from PDyson1400/validation
H-Azza-17 Feb 7, 2023
bc7f2e9
newest post first
PDyson1400 Feb 7, 2023
8a53fc8
Merge pull request #3 from PDyson1400/newest_post
H-Azza-17 Feb 7, 2023
0f8322d
Merge pull request #4 from PDyson1400/CICD
PDyson1400 Feb 7, 2023
cec44d4
amended gitignore to also ignore .idea folder
TheMany172 Feb 7, 2023
76eff83
Delete .idea directory
TheMany172 Feb 7, 2023
18b4533
Merge pull request #5 from PDyson1400/CICD
joaomdf Feb 7, 2023
bf58171
Delete .DS_Store
joaomdf Feb 8, 2023
3d40ff3
Update .gitignore
joaomdf Feb 8, 2023
f9e318e
Update posts.js
joaomdf Feb 8, 2023
2b6a8cb
Merge pull request #6 from PDyson1400/post-fix
H-Azza-17 Feb 8, 2023
a66b5a8
Merge pull request #7 from PDyson1400/joaomdf-patch-1
H-Azza-17 Feb 8, 2023
d874145
comment functionality
PDyson1400 Feb 8, 2023
f753a32
Merge pull request #8 from PDyson1400/comments
C-M-Silva Feb 8, 2023
5c87ab6
inital commit to check it has not broken
TheMany172 Feb 8, 2023
64d7c73
INCOMPLETE friends
PDyson1400 Feb 8, 2023
501e2dc
Visible user requests
PDyson1400 Feb 8, 2023
2305923
trim function working
PDyson1400 Feb 8, 2023
7795b10
jest testing added
PDyson1400 Feb 9, 2023
4124ad8
confirmation nearly working
PDyson1400 Feb 9, 2023
d329747
should drop databases after first test 'home screen'
TheMany172 Feb 9, 2023
743c30c
commented code push
PDyson1400 Feb 9, 2023
a06e98b
can confirm and deny friends
PDyson1400 Feb 9, 2023
54f2afa
Merge pull request #9 from PDyson1400/friends
C-M-Silva Feb 9, 2023
d9a22a0
adds max character count: 250
Feb 9, 2023
940630e
Merge pull request #10 from PDyson1400/friends
PDyson1400 Feb 9, 2023
71f3394
added post user links
PDyson1400 Feb 9, 2023
3f02d24
Merge pull request #11 from PDyson1400/photo_upload
H-Azza-17 Feb 9, 2023
a560823
updated e2e testing suite
joaomdf Feb 9, 2023
00feb0d
other users can't access your friend request
PDyson1400 Feb 9, 2023
9fc0d2c
Merge pull request #12 from PDyson1400/photo_upload
H-Azza-17 Feb 9, 2023
5395d71
added user links to comments
PDyson1400 Feb 9, 2023
4c59287
added poster links to comments page
PDyson1400 Feb 9, 2023
33710d4
Merge pull request #14 from PDyson1400/photo_upload
H-Azza-17 Feb 9, 2023
3cd5bcd
first e2e tests for posts comments
joaomdf Feb 9, 2023
694f199
updated sign up spec and submit post spec
TheMany172 Feb 10, 2023
7f8e86a
amended some tests to have 'submit' command to test the back end as well
TheMany172 Feb 10, 2023
7e20285
new test added
joaomdf Feb 10, 2023
9aff1a3
Merge pull request #15 from PDyson1400/e2e-adam
joaomdf Feb 10, 2023
2b71342
backend checks for html
PDyson1400 Feb 10, 2023
7edc9b6
removed redundant code
PDyson1400 Feb 10, 2023
7620757
removed more redundant code
PDyson1400 Feb 10, 2023
d7a957e
added log in link to sign up page
PDyson1400 Feb 10, 2023
01c617e
more tests
joaomdf Feb 10, 2023
03a30e1
Merge branch 'development-branch' into e2e
joaomdf Feb 10, 2023
b44fe88
Merge pull request #17 from PDyson1400/e2e
joaomdf Feb 10, 2023
1cdf5e7
Merge pull request #16 from PDyson1400/backend_checks
C-M-Silva Feb 10, 2023
d3c7d6d
Updated README
TheMany172 Feb 10, 2023
cc47279
Update README.md
TheMany172 Feb 10, 2023
a5ddd62
Merge pull request #18 from PDyson1400/backend_checks
TheMany172 Feb 10, 2023
cddab7e
pending filter
PDyson1400 Feb 10, 2023
4ad6c51
modified posts controller to just redirect to the same page rather th…
TheMany172 Feb 10, 2023
895a809
split test for blank post and post with just spaces into two, and ame…
TheMany172 Feb 10, 2023
f54ed1d
modified controllers to fix the issue of posts with spaces
TheMany172 Feb 10, 2023
2dc3a4c
Merge pull request #19 from PDyson1400/development-branch-test
TheMany172 Feb 10, 2023
044b4c7
Merge pull request #20 from PDyson1400/development-branch
PDyson1400 Feb 10, 2023
9188013
views changes
PDyson1400 Feb 10, 2023
6b90b91
Merge pull request #21 from PDyson1400/views_changes
PDyson1400 Feb 10, 2023
23830b7
working picture links
PDyson1400 Feb 13, 2023
422a211
Merge pull request #22 from PDyson1400/photo_upload
PDyson1400 Feb 13, 2023
0d08a1c
only user can update their own picture
PDyson1400 Feb 13, 2023
9ec141d
max picture size
PDyson1400 Feb 13, 2023
74c0667
fixed test after views change
joaomdf Feb 13, 2023
7412172
fixed tests
joaomdf Feb 13, 2023
71b0b29
Update user_can_submit_posts_spec.js
TheMany172 Feb 13, 2023
08b7055
Merge pull request #24 from PDyson1400/second_week_tests
TheMany172 Feb 13, 2023
2bc160b
working username and profile pic
PDyson1400 Feb 13, 2023
c3e6154
working order profile pic and username
PDyson1400 Feb 13, 2023
f857371
Merge pull request #25 from PDyson1400/test_branch
PDyson1400 Feb 13, 2023
590c353
Merge pull request #26 from PDyson1400/software_branch
H-Azza-17 Feb 13, 2023
4c4dbf5
navbar
PDyson1400 Feb 13, 2023
be84f97
Merge pull request #27 from PDyson1400/test_branch
PDyson1400 Feb 13, 2023
70dd0b3
console log gone
Feb 13, 2023
8c56dfc
rejigged img src
PDyson1400 Feb 13, 2023
7cce836
fixed issue
PDyson1400 Feb 13, 2023
416659c
Merge pull request #29 from PDyson1400/test_branch
PDyson1400 Feb 13, 2023
4b5b5e5
pics all in order
PDyson1400 Feb 13, 2023
d6d6110
Merge pull request #30 from PDyson1400/software_branch
joaomdf Feb 13, 2023
fb52e90
removed redundant code
PDyson1400 Feb 13, 2023
8c9cba4
Merge pull request #31 from PDyson1400/test_branch
PDyson1400 Feb 13, 2023
b37f7d6
Merge pull request #32 from PDyson1400/software_branch
PDyson1400 Feb 13, 2023
3bcc918
cant add self as friend, button remains
PDyson1400 Feb 13, 2023
5d0182b
Merge pull request #33 from PDyson1400/test_branch
PDyson1400 Feb 13, 2023
42edca4
adding pictures to posts
PDyson1400 Feb 13, 2023
20f8305
your -> incoming friends requests
PDyson1400 Feb 13, 2023
bab8d93
test
C-M-Silva Feb 14, 2023
c1ab0cd
update
C-M-Silva Feb 14, 2023
fa9c7a8
final update
C-M-Silva Feb 14, 2023
442c0a1
Merge pull request #34 from PDyson1400/testing_friend_requests
C-M-Silva Feb 14, 2023
78a2c97
Merge pull request #35 from PDyson1400/software_branch
H-Azza-17 Feb 14, 2023
d43ea95
updates
Feb 14, 2023
0abc0d9
no pic on no pic posts
PDyson1400 Feb 14, 2023
6d6f7a7
updates
Feb 14, 2023
b0fde6e
Merge pull request #36 from PDyson1400/software_branch
C-M-Silva Feb 14, 2023
3d5586e
no pic posts have no img
PDyson1400 Feb 14, 2023
51990ec
Merge pull request #37 from PDyson1400/test_branch
PDyson1400 Feb 14, 2023
7f5243e
Merge pull request #38 from PDyson1400/software_branch
joaomdf Feb 14, 2023
6a44a02
user can like and unlike
C-M-Silva Feb 14, 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 .github/.DS_Store
Binary file not shown.
28 changes: 28 additions & 0 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Cypress Tests
on: [push]
jobs:
cypress-run:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
build: npm run build


# Install NPM dependencies, cache them correctly
# and run all Cypress tests
- name: Create mongoDB Docker container
run: sudo docker run -d -p 27017:27017 mongo:latest
- name: start server
uses: cypress-io/[email protected] # use the explicit version number
with:
wait-on: "http://localhost:3030"
config-file: cypress.config.cjs
# build: npm run build
start: npm run start:test
env:
MONGODB_URI: "mongodb://0.0.0.0:27017/"
MONGODB_DATABASE: "acebook_test"
- name: run cypress component test
run: npm run test:unit
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ typings/
# cypress.io
cypress/screenshots
cypress/videos

# Webstorm config folder
.idea

# DS_STORE FILE
.DS_Store
60 changes: 59 additions & 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
Link to Trello: https://trello.com/b/TpjSuBYO/jam-a-pc

## Quickstart

Expand All @@ -31,6 +31,17 @@ REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL
nvm install 18
```

_Note: you if you get an error when running `nvm install 18`, completeing the following commands might help:_

`curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash`

`source ~/.zshrc`

`nvm install node`

`nvm use node`


### Set up your project

1. Fork this repository
Expand Down Expand Up @@ -74,6 +85,9 @@ so that integration tests do not interact with the development server.

### Test

_Note: if at any point you get a 'this is your first time running cypress' message telling you that you need to verify it, enter the following command to verify:_
`npx cypress verify`

- Run all tests
```
npm test
Expand All @@ -93,3 +107,47 @@ Some people occasionally experience MongoDB connection errors when running the t
- Check that it's running using `brew services list`

If you have issues that are not resolved by these tips, please reach out to a coach and, once the issue is resolved, we can add a new tip!

# General Rules:

To be used as a guide, will fluctuate day to day as work needs

1. **0930** - Previous cohort/team standup
1. shared learning
2. ideas sharing
3. shared unblocking


2. **1000** - JAMA PC standup
1. completed items
2. plans for the day
3. new items to add
4. items to remove
5. any issues?


3. **1230-1400** LUNCH


5. **1400** - Afternoon catchup


7. **1700** - daily roundup
1. completed items
2. plans for the day
3. new items to add
4. items to remove
5. any issues?


## Quality - for the group is:
- understandable code
- fully functional to the MVP - or above if time
- looks nice as well

Maybe we need to consider:
- Usability
- Accessibility
- Security
- Testability
- Longevity
138 changes: 130 additions & 8 deletions controllers/posts.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,150 @@
const Post = require("../models/post");
const Comment = require("../models/comment");
const User = require("../models/user");

const PostsController = {
Index: (req, res) => {
Post.find((err, posts) => {
Post.find((err) => {
if (err) {
throw err;
}

res.render("posts/index", { posts: posts });
});
}).sort({date:-1}).then((post) => {
let collection = [];
async function post_set(post, i) {
await User.findById(post[i].user_id, (err, user) => {
if (err) {
throw err;
}
let regex = /^\w*[^@]/g;
let username = user.email.match(regex);
let isPicture = post[i].picture !== "";
collection.push({post: post[i], picture: user.picture, username: username, isPicture: isPicture});
})
}
async function increment(post) {
for(let i = 0; i < post.length; i++) {
await post_set(post, i);
}
res.render("posts/index", { collection: collection , session_user: req.session.user});
}
increment(post);
})
},
New: (req, res) => {
res.render("posts/new", {});
res.render("posts/new", {session_user: req.session.user});
},
Create: (req, res) => {
const post = new Post(req.body);
post.save((err) => {
post.date = Date.now();
post.user_id = req.session.user._id;
if (post.message === "" || post.message.length > 250) {
res.status(201).redirect("/posts/new");
} else if (post.message[0] === " ") {
const trimmed_post = post.message.trim();
if (trimmed_post.length != 0) {
post.message = trimmed_post;
post.save((err) => {
if (err) {
throw err;
}

res.status(201).redirect(`/posts/`);
});
} else {
res.status(201).redirect(`/posts/new`);
}
} else {
post.save((err) => {
if (err) {
throw err;
}

res.status(201).redirect("/posts");
});
}
},

Like: (req, res) => {
const postId = req.params.id;
const userId = req.session.user._id

Post.findById(postId, (err, post) => {
if (err) {
throw err;
}

res.status(201).redirect("/posts");

const alreadyLiked = post.liked_by.includes(userId);

if (!alreadyLiked) {
post.likes = post.likes + 1;
post.liked_by.push(userId);
} else {
post.likes = post.likes - 1;
post.liked_by = post.liked_by.filter(id => id !== userId);
}

post.save((err) => {
if (err) {
throw err;
}

res.redirect("/posts");
});
});
},

Details: (req, res) => {
const postId = req.params.id;
Post.findById(postId, (err, post) => {
if (err) {
throw err;
}

return post;
}).then((post) => (
Comment.find((err, comments) => {
if (err) {
throw err;
}
res.render("posts/details", {comments: comments, post: post, session_user: req.session.user});
}).where({post_id: postId})
));
},

CreateComment: (req, res) => {
const postId = req.params.id;
const userId = req.session.user._id

const comment = new Comment(req.body);
comment.post_id = postId;
comment.user_id = userId;

if (comment.message === "" || comment.message.length > 250) {
res.status(201).redirect(`/posts/${postId}`);
} else if (comment.message[0] === " ") {
const trimmed = comment.message.trim();
if (trimmed.length != 0) {
comment.message = trimmed;
comment.save((err) => {
if (err) {
throw err;
}

res.status(201).redirect(`/posts/${postId}`);
});
} else {
res.status(201).redirect(`/posts/${postId}`);
}
} else {
comment.save((err) => {
if (err) {
throw err;
}

res.status(201).redirect(`/posts/${postId}`);
});
}
}
};

module.exports = PostsController;
7 changes: 3 additions & 4 deletions controllers/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const User = require("../models/user");

const SessionsController = {
New: (req, res) => {
res.render("sessions/new", {});
res.render("sessions/new", {error: req.session.error});
},

Create: (req, res) => {
Expand All @@ -11,9 +11,8 @@ const SessionsController = {
const password = req.body.password;

User.findOne({ email: email }).then((user) => {
if (!user) {
res.redirect("/sessions/new");
} else if (user.password != password) {
if (!user || user.password != password) {
req.session.error = "INVALID USERNAME OR PASSWORD";
res.redirect("/sessions/new");
} else {
req.session.user = user;
Expand Down
Loading