From 7e621a7970dc7a1723e9aec9bea2b2e896a20678 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Mon, 6 Feb 2023 10:43:43 +0000 Subject: [PATCH 01/71] Test_time --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index eee74593d..d3c16f78d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ It uses: REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL +HAS THIS CHANGED GONE THROUGH? + ## Quickstart ### Install Node.js From 49f1d2e0631958f56616824c344a9b06c7e0cf84 Mon Sep 17 00:00:00 2001 From: Cristiano Silva Date: Tue, 7 Feb 2023 10:04:54 +0000 Subject: [PATCH 02/71] add the like button and increment --- controllers/posts.js | 10 ++++++++++ models/post.js | 1 + models/user.js | 2 +- routes/posts.js | 1 + views/posts/index.hbs | 5 ++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index 4b521304d..2938defa9 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -23,6 +23,16 @@ const PostsController = { res.status(201).redirect("/posts"); }); }, + Like: (req, res) => { + const postId = req.params.id; + Post.findByIdAndUpdate(postId, { $inc: { likes: 1 } }, (err, post) => { + if (err) { + throw err; + } + + res.redirect("/posts"); + }); + }, }; module.exports = PostsController; diff --git a/models/post.js b/models/post.js index 3ef06ae2d..0bc8a3523 100644 --- a/models/post.js +++ b/models/post.js @@ -8,3 +8,4 @@ const PostSchema = new mongoose.Schema({ const Post = mongoose.model("Post", PostSchema); module.exports = Post; + diff --git a/models/user.js b/models/user.js index 27406b498..29ad72b68 100644 --- a/models/user.js +++ b/models/user.js @@ -7,4 +7,4 @@ const UserSchema = new mongoose.Schema({ const User = mongoose.model("User", UserSchema); -module.exports = User; +module.exports = User; \ No newline at end of file diff --git a/routes/posts.js b/routes/posts.js index d4ec2d937..c4f13622c 100644 --- a/routes/posts.js +++ b/routes/posts.js @@ -6,5 +6,6 @@ const PostsController = require("../controllers/posts"); router.get("/", PostsController.Index); router.post("/", PostsController.Create); router.get("/new", PostsController.New); +router.post("/:id/like", PostsController.Like); module.exports = router; diff --git a/views/posts/index.hbs b/views/posts/index.hbs index 4a4bca1d8..bbabf3f2f 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -3,7 +3,10 @@ {{#each posts}}
  • {{this.message}}
  • {{this.likes}} likes
  • +
    + +
    {{/each}} -New post +New post \ No newline at end of file From b5748a0b7e07987373d0e5971d98d6056787c81e Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Tue, 7 Feb 2023 12:03:32 +0000 Subject: [PATCH 03/71] sessions like nearly --- controllers/posts.js | 11 +++++++++-- models/post.js | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index 2938defa9..2d6d5799b 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -25,12 +25,19 @@ const PostsController = { }, Like: (req, res) => { const postId = req.params.id; - Post.findByIdAndUpdate(postId, { $inc: { likes: 1 } }, (err, post) => { + const userId = req.session.user._id + Post.findById(postId, (err, post) => { if (err) { throw err; } + if (!post.liked_by.includes(userId)) { + post.likes = post.likes + 1; + post.liked_by.push(userId) - res.redirect("/posts"); + Post.findByIdAndUpdate(postId, {likes: post.likes}, {liked_by: post.liked_by}); + + res.redirect("/posts"); + } }); }, }; diff --git a/models/post.js b/models/post.js index 0bc8a3523..e2d5db7ce 100644 --- a/models/post.js +++ b/models/post.js @@ -2,7 +2,8 @@ const mongoose = require("mongoose"); const PostSchema = new mongoose.Schema({ message: String, - likes: { type: Number, default: 0 } + likes: { type: Number, default: 0 }, + liked_by: [], }); const Post = mongoose.model("Post", PostSchema); From 86ce4449c49ece42c0d02515468d1cb1e3550ec7 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Tue, 7 Feb 2023 14:01:56 +0000 Subject: [PATCH 04/71] initial commit, added file as template in .github folder --- .DS_Store | Bin 0 -> 8196 bytes .github/.DS_Store | Bin 0 -> 6148 bytes .github/workflows/cypress-tests.yml | 26 +++++++++++++++++++ .idea/.gitignore | 5 ++++ .idea/acebook-node-template.iml | 12 +++++++++ .idea/inspectionProfiles/Project_Default.xml | 6 +++++ .idea/jsLibraryMappings.xml | 6 +++++ .idea/modules.xml | 8 ++++++ .idea/vcs.xml | 6 +++++ package.json | 13 +++++++++- 10 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 .github/.DS_Store create mode 100644 .github/workflows/cypress-tests.yml create mode 100644 .idea/.gitignore create mode 100644 .idea/acebook-node-template.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ed6ec0296c11701f0309279f64187d94a00cf9ad GIT binary patch literal 8196 zcmeI1Pfrs;7{=d$(rzu1nqb6($tGU0QX^vGr4%@js0V8Fpr-D&rK~JFO}nKr1npfv zgI~e3U&Qa?NuPISA+uAs8k5eDop=8{&+NRvnQc1@5sBuwTPIp0A`ctKY6aC5g|G8A zQx>u_cMt{qL=h#F(vUh-n^C(Hj({WJ2si?cfFtlf5Wsgf7w?+yeSOu{j({UDmjw9p z!NZ1ddS^^*za9S1YV;!J8eij>9oa(5oXj88qL}nG)5<_S^uKO%UY-Dk& zqqdXKb`sg0MYci_>hAFQN=~AoqpKYOM_`r!uiaO$TJO<_;@tZEBhE-l_G8%zV;Mrn zkJdJ}+8(($Mn4Bzt6D=FjfVm}C9N4-hAy1FBiG>DSkP#L0b50ZCp zqNFP)O*u}wBjs)B3trhPx2t#0&Ysqvtox5QADyrJXZ4LO9BgjY&(F)=?fVa(9kh?* zlSF=1I7nolPjpisU)JBSXQg%88YZz!`nbZb8<&V8AWZ;&NIeVGJ?KpQOYlV0#qb4| zlKW#SixkiRe>K9uTH4>1c9BA!3VGE6_tR{#g4aBlAnJvW#N>(5i=o}NnlRsUL))QG z=m&Dc1haZVJZ((%GVWohb?;}VrC=_mZv|O$`zai{mxsuxe`WSe%Ji1#IqlO9?a@nW z(O#Z{U{Wi_g-ZD+2rqGnUTLnc-XX1BmAKpw}a`*1&iOR8fv znzKBZW3Gi|tA%TP%rWOH!iUEd_lu}wkpQ=xwoC_LwoSYA0~h)yMson2)eD|q;*;@jzu@xcZ&`KOF^@`d=1#;lxy7bU%joL$7g}4r2#duMi;6oJ2=k|yC zCHxM&+1*s2gd{FJX`OUM7H0I!{o71K1KG2L4~{WHmRf>Hi7-oxMA8bh>}kyPcCWBf_3@~oV8 zyEm%QY;C>R_O`vY_ana0RXiO|XJs^;eB-MVt@C6V50fw1s2X%$e$d5qm=&XmA!O+Y zDc`?lMXIYv&x*7(+}I9yzUL1*yYu| z@ct0M8AFG)MYDCFF(m-7g>GYr`G=7?fy2;YZ4o0dWvM_*Rj$NPmX7|w<%JGwiDnWy9afk`J7T9j545CtA8z_lN&!{`6U$LoKSB#kH_3Or8*RO>iCj__{o zY+ZRvK5GN`DV&Y-YKwm<2+UE8Tt13-;l|J(Z~zP)))vtNlOF*igEXSRKULrk@yA + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..03d9549ea --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 000000000..d23208fbb --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..094fe603c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..35eb1ddfb --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index b0b63690e..bf221f63e 100644 --- a/package.json +++ b/package.json @@ -38,5 +38,16 @@ }, "nodemonConfig": { "ext": "js,hbs" - } + }, + "main": "app.js", + "repository": { + "type": "git", + "url": "git+https://github.com/PDyson1400/acebook-node-template.git" + }, + "keywords": [], + "author": "", + "bugs": { + "url": "https://github.com/PDyson1400/acebook-node-template/issues" + }, + "homepage": "https://github.com/PDyson1400/acebook-node-template#readme" } From 98b3f4401590996bf92b9c7c948d3d679a09ce97 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Tue, 7 Feb 2023 14:07:44 +0000 Subject: [PATCH 05/71] like button functionality --- controllers/posts.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index 2d6d5799b..28fdbf3b7 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -23,9 +23,11 @@ const PostsController = { 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; @@ -34,10 +36,13 @@ const PostsController = { post.likes = post.likes + 1; post.liked_by.push(userId) - Post.findByIdAndUpdate(postId, {likes: post.likes}, {liked_by: post.liked_by}); - - res.redirect("/posts"); + post.save((err) => { + if (err) { + throw err; + } + }); } + res.redirect("/posts"); }); }, }; From bb4c2818eeb684f36a0155a9cf0d5f2e9c258d84 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Tue, 7 Feb 2023 14:14:57 +0000 Subject: [PATCH 06/71] test the first part --- .github/workflows/cypress-tests.yml | 34 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/workflows/cypress-tests.yml b/.github/workflows/cypress-tests.yml index ef332e63f..ea77c5b1c 100644 --- a/.github/workflows/cypress-tests.yml +++ b/.github/workflows/cypress-tests.yml @@ -8,19 +8,21 @@ jobs: 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/github-action@v4.1.0 # use the explicit version number - with: - wait-on: "http://localhost:8888" - config-file: cypress.config.cjs - # build: npm run build - start: netlify dev - env: - MONGODB_URI: "mongodb://0.0.0.0:27017/" - MONGODB_DATABASE: "gladiators" - - name: run cypress component test - run: npx cypress run --component \ No newline at end of file + + +# # 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/github-action@v4.1.0 # use the explicit version number +# with: +# wait-on: "http://localhost:8888" +# config-file: cypress.config.cjs +# # build: npm run build +# start: netlify dev +# env: +# MONGODB_URI: "mongodb://0.0.0.0:27017/" +# MONGODB_DATABASE: "gladiators" +# - name: run cypress component test +# run: npx cypress run --component \ No newline at end of file From c34bc01130f1e42f3de90dba99ed6551aab975bf Mon Sep 17 00:00:00 2001 From: Adam Little Date: Tue, 7 Feb 2023 14:48:49 +0000 Subject: [PATCH 07/71] edited the cicd files --- .github/workflows/cypress-tests.yml | 32 ++++++++++++++--------------- cypress.config.cjs | 10 +++++++++ 2 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 cypress.config.cjs diff --git a/.github/workflows/cypress-tests.yml b/.github/workflows/cypress-tests.yml index ea77c5b1c..edd4a0b21 100644 --- a/.github/workflows/cypress-tests.yml +++ b/.github/workflows/cypress-tests.yml @@ -10,19 +10,19 @@ jobs: 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/github-action@v4.1.0 # use the explicit version number -# with: -# wait-on: "http://localhost:8888" -# config-file: cypress.config.cjs -# # build: npm run build -# start: netlify dev -# env: -# MONGODB_URI: "mongodb://0.0.0.0:27017/" -# MONGODB_DATABASE: "gladiators" -# - name: run cypress component test -# run: npx cypress run --component \ No newline at end of file + # 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/github-action@v4.1.0 # use the explicit version number + with: + wait-on: "http://localhost:3030" + config-file: cypress.config.cjs + # build: npm run build + start: netlify dev + env: + MONGODB_URI: "mongodb://0.0.0.0:27017/" + MONGODB_DATABASE: "acebook_test" + - name: run cypress component test + run: npm run test:unit \ No newline at end of file diff --git a/cypress.config.cjs b/cypress.config.cjs new file mode 100644 index 000000000..7bf7bbdbb --- /dev/null +++ b/cypress.config.cjs @@ -0,0 +1,10 @@ +const { defineConfig } = require("cypress"); + +module.exports = defineConfig({ + component: { + devServer: { + framework: "node" + }, + }, + e2e: { + baseUrl: "http://localhost:3030"}}) \ No newline at end of file From d444e4a09686ed91bf6bbaaef2a5460c80ace062 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Tue, 7 Feb 2023 14:50:20 +0000 Subject: [PATCH 08/71] amended the start in the yml file --- .github/workflows/cypress-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cypress-tests.yml b/.github/workflows/cypress-tests.yml index edd4a0b21..2fe9626b5 100644 --- a/.github/workflows/cypress-tests.yml +++ b/.github/workflows/cypress-tests.yml @@ -20,7 +20,7 @@ jobs: wait-on: "http://localhost:3030" config-file: cypress.config.cjs # build: npm run build - start: netlify dev + start: npm run start:test env: MONGODB_URI: "mongodb://0.0.0.0:27017/" MONGODB_DATABASE: "acebook_test" From 0abf23645edad46986a32b5b49c75855f2e6ccdc Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 7 Feb 2023 14:58:38 +0000 Subject: [PATCH 09/71] validation --- views/posts/new.hbs | 2 +- views/sessions/new.hbs | 4 ++-- views/users/new.hbs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/views/posts/new.hbs b/views/posts/new.hbs index a80541cdf..99e10342e 100644 --- a/views/posts/new.hbs +++ b/views/posts/new.hbs @@ -1,5 +1,5 @@
    - +
    diff --git a/views/sessions/new.hbs b/views/sessions/new.hbs index 86de20b62..1fef78625 100644 --- a/views/sessions/new.hbs +++ b/views/sessions/new.hbs @@ -1,7 +1,7 @@
    - + - +
    diff --git a/views/users/new.hbs b/views/users/new.hbs index 13e3b4fc1..e9033dc00 100644 --- a/views/users/new.hbs +++ b/views/users/new.hbs @@ -1,7 +1,7 @@
    - + - +
    From bc7f2e932de6de61b2553fd1c9b6c14603de0c42 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Tue, 7 Feb 2023 15:37:00 +0000 Subject: [PATCH 10/71] newest post first --- controllers/posts.js | 3 ++- models/post.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/controllers/posts.js b/controllers/posts.js index 28fdbf3b7..2859253bc 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -8,13 +8,14 @@ const PostsController = { } res.render("posts/index", { posts: posts }); - }); + }).sort({date:1}); }, New: (req, res) => { res.render("posts/new", {}); }, Create: (req, res) => { const post = new Post(req.body); + post.date = Date.now(); post.save((err) => { if (err) { throw err; diff --git a/models/post.js b/models/post.js index e2d5db7ce..e0391a552 100644 --- a/models/post.js +++ b/models/post.js @@ -4,6 +4,7 @@ const PostSchema = new mongoose.Schema({ message: String, likes: { type: Number, default: 0 }, liked_by: [], + date: Date, }); const Post = mongoose.model("Post", PostSchema); From cec44d41221e323534cb2daea194b87123dd6b04 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Tue, 7 Feb 2023 16:28:16 +0000 Subject: [PATCH 11/71] amended gitignore to also ignore .idea folder --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3dc633e98..1499eceed 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,6 @@ typings/ # cypress.io cypress/screenshots cypress/videos + +# Webstorm config folder +.idea \ No newline at end of file From 76eff830c3aa9e370247fea47cb9de0d630598b1 Mon Sep 17 00:00:00 2001 From: Adam <110791742+TheMany172@users.noreply.github.com> Date: Tue, 7 Feb 2023 16:29:48 +0000 Subject: [PATCH 12/71] Delete .idea directory --- .idea/.gitignore | 5 ----- .idea/acebook-node-template.iml | 12 ------------ .idea/inspectionProfiles/Project_Default.xml | 6 ------ .idea/jsLibraryMappings.xml | 6 ------ .idea/modules.xml | 8 -------- .idea/vcs.xml | 6 ------ 6 files changed, 43 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/acebook-node-template.iml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/jsLibraryMappings.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index b58b603fe..000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/acebook-node-template.iml b/.idea/acebook-node-template.iml deleted file mode 100644 index 0c8867d7e..000000000 --- a/.idea/acebook-node-template.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 03d9549ea..000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml deleted file mode 100644 index d23208fbb..000000000 --- a/.idea/jsLibraryMappings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 094fe603c..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1ddfb..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From bf581715ea7a0e3dc7f333304f94490e5cf8af48 Mon Sep 17 00:00:00 2001 From: Joao Fernandes <115627873+joaomdf@users.noreply.github.com> Date: Wed, 8 Feb 2023 10:20:09 +0000 Subject: [PATCH 13/71] Delete .DS_Store --- .DS_Store | Bin 8196 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index ed6ec0296c11701f0309279f64187d94a00cf9ad..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeI1Pfrs;7{=d$(rzu1nqb6($tGU0QX^vGr4%@js0V8Fpr-D&rK~JFO}nKr1npfv zgI~e3U&Qa?NuPISA+uAs8k5eDop=8{&+NRvnQc1@5sBuwTPIp0A`ctKY6aC5g|G8A zQx>u_cMt{qL=h#F(vUh-n^C(Hj({WJ2si?cfFtlf5Wsgf7w?+yeSOu{j({UDmjw9p z!NZ1ddS^^*za9S1YV;!J8eij>9oa(5oXj88qL}nG)5<_S^uKO%UY-Dk& zqqdXKb`sg0MYci_>hAFQN=~AoqpKYOM_`r!uiaO$TJO<_;@tZEBhE-l_G8%zV;Mrn zkJdJ}+8(($Mn4Bzt6D=FjfVm}C9N4-hAy1FBiG>DSkP#L0b50ZCp zqNFP)O*u}wBjs)B3trhPx2t#0&Ysqvtox5QADyrJXZ4LO9BgjY&(F)=?fVa(9kh?* zlSF=1I7nolPjpisU)JBSXQg%88YZz!`nbZb8<&V8AWZ;&NIeVGJ?KpQOYlV0#qb4| zlKW#SixkiRe>K9uTH4>1c9BA!3VGE6_tR{#g4aBlAnJvW#N>(5i=o}NnlRsUL))QG z=m&Dc1haZVJZ((%GVWohb?;}VrC=_mZv|O$`zai{mxsuxe`WSe%Ji1#IqlO9?a@nW z(O#Z{U{Wi_g-ZD+2rqGnUTLnc-XX1BmAKpw}a`*1&iOR8fv znzKBZW3Gi|tA%TP%rWOH!iUEd_lu}wkpQ=xwoC_LwoSYA0~h)yMson2)eD|q;*;@ Date: Wed, 8 Feb 2023 10:21:06 +0000 Subject: [PATCH 14/71] Update .gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1499eceed..eba69689a 100644 --- a/.gitignore +++ b/.gitignore @@ -65,4 +65,7 @@ cypress/screenshots cypress/videos # Webstorm config folder -.idea \ No newline at end of file +.idea + +# DS_STORE FILE +.DS_Store From f9e318e7cc157af54aec1833903b780992576c7d Mon Sep 17 00:00:00 2001 From: Joao Fernandes <115627873+joaomdf@users.noreply.github.com> Date: Wed, 8 Feb 2023 10:22:50 +0000 Subject: [PATCH 15/71] Update posts.js --- controllers/posts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/posts.js b/controllers/posts.js index 2859253bc..ee9ce056d 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -8,7 +8,7 @@ const PostsController = { } res.render("posts/index", { posts: posts }); - }).sort({date:1}); + }).sort({date:-1}); }, New: (req, res) => { res.render("posts/new", {}); From d87414540ef773555c31ff18e675b79b9afc60e3 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Wed, 8 Feb 2023 11:58:30 +0000 Subject: [PATCH 16/71] comment functionality --- app.js | 2 +- controllers/posts.js | 54 ++++++++++++++++++++++++++++++++++++++++- models/comment.js | 13 ++++++++++ routes/posts.js | 2 ++ views/posts/details.hbs | 16 ++++++++++++ views/posts/index.hbs | 2 ++ 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 models/comment.js create mode 100644 views/posts/details.hbs diff --git a/app.js b/app.js index bb2057955..a97fdad64 100644 --- a/app.js +++ b/app.js @@ -31,7 +31,7 @@ app.use( resave: false, saveUninitialized: false, cookie: { - expires: 600000, + expires: 60000000, }, }) ); diff --git a/controllers/posts.js b/controllers/posts.js index 2859253bc..f1a4bf6a4 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -1,4 +1,5 @@ const Post = require("../models/post"); +const Comment = require("../models/comment"); const PostsController = { Index: (req, res) => { @@ -8,7 +9,7 @@ const PostsController = { } res.render("posts/index", { posts: posts }); - }).sort({date:1}); + }).sort({date:-1}); }, New: (req, res) => { res.render("posts/new", {}); @@ -46,6 +47,57 @@ const PostsController = { 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}); + }).where({post_id: postId}) + )); + }, + + CreateComment: (req, res) => { + const postId = req.params.id; + + console.log(postId); + + const comment = new Comment(req.body); + comment.post_id = postId; + + if (comment.message[0] === " ") { + const trimmed = comment.message.trim(); + if (trimmed.length != 0) { + 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; diff --git a/models/comment.js b/models/comment.js new file mode 100644 index 000000000..a14f9d2c9 --- /dev/null +++ b/models/comment.js @@ -0,0 +1,13 @@ +const mongoose = require("mongoose"); + +const CommentSchema = new mongoose.Schema({ + post_id: String, + user_id: String, + message: String, + date: Date, +}); + +const Comment = mongoose.model("Comment", CommentSchema); + +module.exports = Comment; + diff --git a/routes/posts.js b/routes/posts.js index c4f13622c..f358a13bb 100644 --- a/routes/posts.js +++ b/routes/posts.js @@ -6,6 +6,8 @@ const PostsController = require("../controllers/posts"); router.get("/", PostsController.Index); router.post("/", PostsController.Create); router.get("/new", PostsController.New); +router.get("/:id", PostsController.Details); +router.post("/:id/create", PostsController.CreateComment); router.post("/:id/like", PostsController.Like); module.exports = router; diff --git a/views/posts/details.hbs b/views/posts/details.hbs new file mode 100644 index 000000000..9f148ee11 --- /dev/null +++ b/views/posts/details.hbs @@ -0,0 +1,16 @@ +

    Post

    + +{{post.message}} + +
    + + +
    + +
      + {{#each comments}} +
    • {{this.message}}
    • + {{/each}} +
    + +Posts \ No newline at end of file diff --git a/views/posts/index.hbs b/views/posts/index.hbs index bbabf3f2f..caeea6f5c 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -6,6 +6,8 @@
    + More details +

    =====================

    {{/each}} From 5c87ab650655b51547ad9047bc749ddac30b1b56 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Wed, 8 Feb 2023 14:41:36 +0000 Subject: [PATCH 17/71] inital commit to check it has not broken --- cypress/fixtures/example.json | 5 +++++ cypress/integration/adam_check.js | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 cypress/fixtures/example.json create mode 100644 cypress/integration/adam_check.js diff --git a/cypress/fixtures/example.json b/cypress/fixtures/example.json new file mode 100644 index 000000000..02e425437 --- /dev/null +++ b/cypress/fixtures/example.json @@ -0,0 +1,5 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io", + "body": "Fixtures are a great way to mock data for responses to routes" +} diff --git a/cypress/integration/adam_check.js b/cypress/integration/adam_check.js new file mode 100644 index 000000000..c9954c40e --- /dev/null +++ b/cypress/integration/adam_check.js @@ -0,0 +1,6 @@ +describe("Home page", () => { + it("has a title", () => { + cy.visit("/"); + cy.get(".title").should("contain", "Acebook"); + }); +}); From 64d7c73f15e4cbd87fa84dfded964b71c9bcecde Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Wed, 8 Feb 2023 16:39:42 +0000 Subject: [PATCH 18/71] INCOMPLETE friends --- controllers/sessions.js | 7 +++--- controllers/users.js | 54 ++++++++++++++++++++++++++++++++++++++--- models/user.js | 1 + routes/users.js | 2 ++ views/sessions/new.hbs | 5 +++- views/users/details.hbs | 3 +++ views/users/new.hbs | 3 ++- 7 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 views/users/details.hbs diff --git a/controllers/sessions.js b/controllers/sessions.js index 917e2e14c..d7049c8f9 100644 --- a/controllers/sessions.js +++ b/controllers/sessions.js @@ -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) => { @@ -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; diff --git a/controllers/users.js b/controllers/users.js index bdc2ea8f3..e9765ec50 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -2,16 +2,64 @@ const User = require("../models/user"); const UsersController = { New: (req, res) => { - res.render("users/new", {}); + res.render("users/new", {error: req.session.error}); }, Create: (req, res) => { const user = new User(req.body); - user.save((err) => { + + User.findOne({email : user.email}, (err, founduser) => { + if (err) { + throw err; + } + + if (founduser === null) { + user.save((err) => { + if (err) { + throw err; + } + res.status(201).redirect("/sessions/new"); + }); + } else { + req.session.error = "INVALID USERNAME OR PASSWORD"; + res.redirect("/users/new"); + } + }) + }, + + Details: (req, res) => { + const userId = req.params.id; + + User.findById(userId, (err, user) => { + if (err) { + throw err; + } + + res.render("users/details", {user: user}); + }); + }, + + Request: (req, res) => { + const currentId = req.session.user._id; + const targetId = req.params.id; + + console.log(currentId); + console.log(targetId); + + User.findById(targetId, (err, user) => { if (err) { throw err; } - res.status(201).redirect("/posts"); + if (user.friends.filter(object => object.user_id === currentId).length === 0) { + user.friends.push({user_id: `${currentId}`, status: "pending"}) + + user.save((err) => { + if (err) { + throw err; + } + }); + } + res.status(201).redirect(`/users/${targetId}`); }); }, }; diff --git a/models/user.js b/models/user.js index 29ad72b68..a753603f4 100644 --- a/models/user.js +++ b/models/user.js @@ -3,6 +3,7 @@ const mongoose = require("mongoose"); const UserSchema = new mongoose.Schema({ email: String, password: String, + friends: Array, }); const User = mongoose.model("User", UserSchema); diff --git a/routes/users.js b/routes/users.js index 1203f91bf..35b56ec65 100644 --- a/routes/users.js +++ b/routes/users.js @@ -5,5 +5,7 @@ const UsersController = require("../controllers/users"); router.get("/new", UsersController.New); router.post("/", UsersController.Create); +router.get("/:id", UsersController.Details); +router.post("/:id/request", UsersController.Request); module.exports = router; diff --git a/views/sessions/new.hbs b/views/sessions/new.hbs index 1fef78625..05fd2130f 100644 --- a/views/sessions/new.hbs +++ b/views/sessions/new.hbs @@ -3,5 +3,8 @@ - + + +

    {{this.error}}

    +Sign up diff --git a/views/users/details.hbs b/views/users/details.hbs new file mode 100644 index 000000000..07cead7cd --- /dev/null +++ b/views/users/details.hbs @@ -0,0 +1,3 @@ +
    + +
    \ No newline at end of file diff --git a/views/users/new.hbs b/views/users/new.hbs index e9033dc00..ceb2b1267 100644 --- a/views/users/new.hbs +++ b/views/users/new.hbs @@ -3,5 +3,6 @@ - + +

    {{this.error}}

    \ No newline at end of file From 501e2dc5a01ea8c04bb4bb3ba90412acdb3f628b Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Wed, 8 Feb 2023 17:16:18 +0000 Subject: [PATCH 19/71] Visible user requests --- controllers/users.js | 7 ++----- views/users/details.hbs | 10 +++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index e9765ec50..55e61e0ec 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -26,7 +26,7 @@ const UsersController = { } }) }, - + Details: (req, res) => { const userId = req.params.id; @@ -34,7 +34,7 @@ const UsersController = { if (err) { throw err; } - + res.render("users/details", {user: user}); }); }, @@ -43,9 +43,6 @@ const UsersController = { const currentId = req.session.user._id; const targetId = req.params.id; - console.log(currentId); - console.log(targetId); - User.findById(targetId, (err, user) => { if (err) { throw err; diff --git a/views/users/details.hbs b/views/users/details.hbs index 07cead7cd..c145bae21 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -1,3 +1,11 @@
    -
    \ No newline at end of file + + +

    Your friend requests

    +
      + {{#each user.friends}} +
    • {{this.user_id}}
    • +
    • {{this.status}}
    • + {{/each}} +
    \ No newline at end of file From 2305923abade8f40a01aaebcea62f7d39c958b72 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Wed, 8 Feb 2023 17:21:55 +0000 Subject: [PATCH 20/71] trim function working --- controllers/posts.js | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/posts.js b/controllers/posts.js index f1a4bf6a4..2b13e8d6e 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -78,6 +78,7 @@ const PostsController = { if (comment.message[0] === " ") { const trimmed = comment.message.trim(); if (trimmed.length != 0) { + comment.message = trimmed; comment.save((err) => { if (err) { throw err; From 7795b10acd40e41c6ae0d2149926d5002b779557 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Thu, 9 Feb 2023 11:49:03 +0000 Subject: [PATCH 21/71] jest testing added --- spec/models/comment.spec.js | 60 +++++++++++++++++++++++++++++++++++++ spec/models/post.spec.js | 6 ++++ spec/models/user.spec.js | 9 ++++++ 3 files changed, 75 insertions(+) create mode 100644 spec/models/comment.spec.js diff --git a/spec/models/comment.spec.js b/spec/models/comment.spec.js new file mode 100644 index 000000000..4d47bd6bc --- /dev/null +++ b/spec/models/comment.spec.js @@ -0,0 +1,60 @@ +const mongoose = require("mongoose"); + +require("../mongodb_helper"); +const Comment = require("../../models/comment"); + +describe("User model", () => { + beforeEach((done) => { + mongoose.connection.collections.comments.drop(() => { + done(); + }); + }); + + it("has a post_id", () => { + const comment = new Comment({ + post_id: "63e38f8d190e0f6cef23cc0f", + user_id: "63e4dada71de08c481ac30dd", + message: "Message", + }); + expect(comment.post_id).toEqual("63e38f8d190e0f6cef23cc0f"); + }); + + it("has a user_id", () => { + const comment = new Comment({ + post_id: "63e38f8d190e0f6cef23cc0f", + user_id: "63e4dada71de08c481ac30dd", + message: "Message", + }); + expect(comment.user_id).toEqual("63e4dada71de08c481ac30dd"); + }); + + it("has a message", () => { + const comment = new Comment({ + post_id: "63e38f8d190e0f6cef23cc0f", + user_id: "63e4dada71de08c481ac30dd", + message: "Message", + }); + expect(comment.message).toEqual("Message"); + }); + + it("can save a comment", (done) => { + const comment = new Comment({ + post_id: "63e38f8d190e0f6cef23cc0f", + user_id: "63e4dada71de08c481ac30dd", + message: "Message", + }); + + comment.save((err) => { + expect(err).toBeNull(); + + Comment.find((err, posts) => { + expect(err).toBeNull(); + + expect(posts[0]).toMatchObject({ post_id: "63e38f8d190e0f6cef23cc0f", + user_id: "63e4dada71de08c481ac30dd", + message: "Message", }); + done(); + }); + }); + }); +}); \ No newline at end of file diff --git a/spec/models/post.spec.js b/spec/models/post.spec.js index 3acfd48ce..4016f08a5 100644 --- a/spec/models/post.spec.js +++ b/spec/models/post.spec.js @@ -15,6 +15,12 @@ describe("Post model", () => { expect(post.message).toEqual("some message"); }); + it("has a liked_by list", () => { + var post = new Post({ message: "some message", liked_by: ["63e3dac27cf776b5b35d5b80"]}); + expect(post.message).toEqual("some message"); + expect(post.liked_by[0]).toEqual("63e3dac27cf776b5b35d5b80"); + }); + it("can list all posts", (done) => { Post.find((err, posts) => { expect(err).toBeNull(); diff --git a/spec/models/user.spec.js b/spec/models/user.spec.js index ed1c93ef5..3c6741fa4 100644 --- a/spec/models/user.spec.js +++ b/spec/models/user.spec.js @@ -26,6 +26,15 @@ describe("User model", () => { expect(user.password).toEqual("password"); }); + it("has friends", () => { + const user = new User({ + email: "someone@example.com", + password: "password", + friends: [{"status":"pending","user_id":"63e4dada71de08c481ac30dd"}] + }); + expect(user.friends[0]).toEqual({"status":"pending","user_id":"63e4dada71de08c481ac30dd"}); + }); + it("can list all users", (done) => { User.find((err, users) => { expect(err).toBeNull(); From 4124ad8a1177f4f32aa0409b934a1bcaa1f77ad5 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Thu, 9 Feb 2023 12:31:13 +0000 Subject: [PATCH 22/71] confirmation nearly working --- controllers/users.js | 49 ++++++++++++++++++++++++++++++++++++++++- routes/users.js | 2 ++ views/users/details.hbs | 6 +++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/controllers/users.js b/controllers/users.js index 55e61e0ec..4e41b5984 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -34,7 +34,6 @@ const UsersController = { if (err) { throw err; } - res.render("users/details", {user: user}); }); }, @@ -59,6 +58,54 @@ const UsersController = { res.status(201).redirect(`/users/${targetId}`); }); }, + + Confirm: (req, res) => { + const theirId = req.params.id; + const hostId = req.session.user._id; + + User.findById(hostId, (err, user) => { + if (err) { + throw err; + } + for(let i = 0; i < user.friends.length; i++) { + console.log(user.friends[i]); + if(user.friends[i]["user_id"] === theirId) { + console.log("confirmation") + user.friends[i]["status"] = "confirmed"; + console.log(user.friends[i]); + } + } + user.save((err) => { + if (err) { + throw err; + } + res.status(201).redirect(`/users/${theirId}`); + }); + }); + }, + + Deny: (req, res) => { + const otherId = req.params.id; + const hostId = req.session.user._id; + + User.findById(hostId, (err, user) => { + if (err) { + throw err; + } + for(let i = 0; i < user.friends.length; i++) { + if(user.friends[i]["user_id"] === otherId) { + user.friends[i]["status"] = "denied"; + user.save((err) => { + if (err) { + throw err; + } + }); + console.log(user); + } + } + res.status(201).redirect(`/users/${otherId}`); + }); + }, }; module.exports = UsersController; diff --git a/routes/users.js b/routes/users.js index 35b56ec65..6ead24d30 100644 --- a/routes/users.js +++ b/routes/users.js @@ -7,5 +7,7 @@ router.get("/new", UsersController.New); router.post("/", UsersController.Create); router.get("/:id", UsersController.Details); router.post("/:id/request", UsersController.Request); +router.post("/:id/confirm", UsersController.Confirm); +router.post("/:id/deny", UsersController.Deny); module.exports = router; diff --git a/views/users/details.hbs b/views/users/details.hbs index c145bae21..936e4dc75 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -7,5 +7,11 @@ {{#each user.friends}}
  • {{this.user_id}}
  • {{this.status}}
  • +
    + +
    +
    + +
    {{/each}} \ No newline at end of file From d329747682bda81cfd370fe265e8aab6591f0fc9 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Thu, 9 Feb 2023 12:44:18 +0000 Subject: [PATCH 23/71] should drop databases after first test 'home screen' --- cypress/integration/adam_check.js | 6 --- cypress/integration/home_page_spec.js | 2 + .../integration/user_can_like_posts_spec.js | 43 +++++++++++++++++++ cypress/plugins/index.js | 32 ++++++++++++-- 4 files changed, 74 insertions(+), 9 deletions(-) delete mode 100644 cypress/integration/adam_check.js create mode 100644 cypress/integration/user_can_like_posts_spec.js diff --git a/cypress/integration/adam_check.js b/cypress/integration/adam_check.js deleted file mode 100644 index c9954c40e..000000000 --- a/cypress/integration/adam_check.js +++ /dev/null @@ -1,6 +0,0 @@ -describe("Home page", () => { - it("has a title", () => { - cy.visit("/"); - cy.get(".title").should("contain", "Acebook"); - }); -}); diff --git a/cypress/integration/home_page_spec.js b/cypress/integration/home_page_spec.js index e5fc9fdb9..161598e86 100644 --- a/cypress/integration/home_page_spec.js +++ b/cypress/integration/home_page_spec.js @@ -1,5 +1,7 @@ describe("Home page", () => { + it("has a title", () => { + cy.task("wipe_database"); cy.visit("/"); cy.get(".title").should("contain", "Acebook"); }); diff --git a/cypress/integration/user_can_like_posts_spec.js b/cypress/integration/user_can_like_posts_spec.js new file mode 100644 index 000000000..f33bb25fb --- /dev/null +++ b/cypress/integration/user_can_like_posts_spec.js @@ -0,0 +1,43 @@ +// var mongoose = require("mongoose"); +// +// require("../mongodb_helper2"); +// var Post = require("../../models/post"); +// describe("Timeline", () => { +// beforeEach((done) => { +// // mongoose.connection.collections.users.drop(() => { +// // done(); +// // }); +// mongoose.connection.collections.posts.drop(() => { +// done(); +// }); +// }); +// +// it("can see likes count on a new post", () => { +// // sign up +// cy.visit("/users/new"); +// cy.get("#email").type("tester@email.com"); +// cy.get("#password").type("password123"); +// cy.get("#submit").click(); +// +// // sign in +// cy.visit("/sessions/new"); +// cy.get("#email").type("tester@email.com"); +// cy.get("#password").type("password123"); +// cy.get("#submit").click(); +// +// // submit a post +// cy.visit("/posts"); +// cy.contains("New post").click(); +// +// cy.get("#new-post-form").find('[type="text"]').type("Testing time 1234"); +// cy.get("#new-post-form").submit(); +// +// cy.get(".posts").should("contain", "Testing time 1234"); +// +// // Assert that we can see the likes count +// cy.get(".posts").should("contain", "1 likes"); +// +// +// +// }); +// }); diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index f6b2b82ce..e45e1596c 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -11,7 +11,33 @@ // This function is called when a project is opened or re-opened (e.g. due to // the project's config changing) -module.exports = function() { - // `on` is used to hook into various events Cypress emits - // `config` is the resolved Cypress config +// module.exports = function() { +// // `on` is used to hook into various events Cypress emits +// // `config` is the resolved Cypress config +// } + +// var mongoose = require("mongoose"); +// require("../../spec/mongodb_helper"); +// + +const User = require("../../models/user") +const Comment = require("../../models/comment") +const Post = require("../../models/post") + +const mongoose = require("mongoose"); + +module.exports = (on) => { + on('task', { + 'wipe_database': async () => { + console.log("hello world"); + mongoose.connect("mongodb://0.0.0.0/acebook_test", { + useNewUrlParser: true, + useUnifiedTopology: true, + }); + await Post.deleteMany({}); + await User.deleteMany({}); + await Comment.deleteMany({}); + return null + }, + }) } From 743c30ceeb9dfcd9b3dbbaae516d0fd53f1d71d1 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Thu, 9 Feb 2023 14:42:35 +0000 Subject: [PATCH 24/71] commented code push --- controllers/users.js | 45 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index 4e41b5984..8fa5b3b32 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -60,28 +60,43 @@ const UsersController = { }, Confirm: (req, res) => { + console.log("confirmed") const theirId = req.params.id; const hostId = req.session.user._id; - User.findById(hostId, (err, user) => { + // User.findOneAndUpdate({_id: hostId}, {friends: [{user_id: theirId, status: "confirmed"}]}); + + // User.findOneAndUpdate({ "_id": hostId }, {"$set": {"status": "confirmed"}}) + + // res.status(201).redirect(`/users/${theirId}`); + User.findOneAndUpdate({"_id": hostId, "friends.user_id": theirId}, {"$set": {"friends.$.status": "confirmed"}}, (err, user) => { if (err) { throw err; } - for(let i = 0; i < user.friends.length; i++) { - console.log(user.friends[i]); - if(user.friends[i]["user_id"] === theirId) { - console.log("confirmation") - user.friends[i]["status"] = "confirmed"; - console.log(user.friends[i]); - } - } - user.save((err) => { - if (err) { - throw err; - } - res.status(201).redirect(`/users/${theirId}`); - }); + console.log(user); + res.status(201).redirect(`/users/${hostId}`); }); + + // User.findById(hostId, (err, user) => { + // if (err) { + // throw err; + // } + // // for(let i = 0; i < user.friends.length; i++) { + // // if(user.friends[i]["user_id"] === theirId) { + // // user.friends[i]["status"] = "confirmed"; + // // } + // // } + // // user.save((err) => { + // // if (err) { + // // throw err; + // // } + // // let stat = user.$isNew; + // // console.log(stat); + // // res.status(201).redirect(`/users/${theirId}`); + // // }); + // // User.updateOne({_id: hostId}, {friends: [{user_id: theirId, status: "confirmed"}]}) + // // res.status(201).redirect(`/users/${theirId}`); + // }); }, Deny: (req, res) => { From a06e98b55c65b9b293ea83029aa9f18f72ad8c8c Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Thu, 9 Feb 2023 14:44:28 +0000 Subject: [PATCH 25/71] can confirm and deny friends --- controllers/users.js | 45 ++++---------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index 8fa5b3b32..c97961961 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -60,15 +60,9 @@ const UsersController = { }, Confirm: (req, res) => { - console.log("confirmed") const theirId = req.params.id; const hostId = req.session.user._id; - // User.findOneAndUpdate({_id: hostId}, {friends: [{user_id: theirId, status: "confirmed"}]}); - - // User.findOneAndUpdate({ "_id": hostId }, {"$set": {"status": "confirmed"}}) - - // res.status(201).redirect(`/users/${theirId}`); User.findOneAndUpdate({"_id": hostId, "friends.user_id": theirId}, {"$set": {"friends.$.status": "confirmed"}}, (err, user) => { if (err) { throw err; @@ -76,49 +70,18 @@ const UsersController = { console.log(user); res.status(201).redirect(`/users/${hostId}`); }); - - // User.findById(hostId, (err, user) => { - // if (err) { - // throw err; - // } - // // for(let i = 0; i < user.friends.length; i++) { - // // if(user.friends[i]["user_id"] === theirId) { - // // user.friends[i]["status"] = "confirmed"; - // // } - // // } - // // user.save((err) => { - // // if (err) { - // // throw err; - // // } - // // let stat = user.$isNew; - // // console.log(stat); - // // res.status(201).redirect(`/users/${theirId}`); - // // }); - // // User.updateOne({_id: hostId}, {friends: [{user_id: theirId, status: "confirmed"}]}) - // // res.status(201).redirect(`/users/${theirId}`); - // }); }, Deny: (req, res) => { - const otherId = req.params.id; + const theirId = req.params.id; const hostId = req.session.user._id; - User.findById(hostId, (err, user) => { + User.findOneAndUpdate({"_id": hostId, "friends.user_id": theirId}, {"$set": {"friends.$.status": "denied"}}, (err, user) => { if (err) { throw err; } - for(let i = 0; i < user.friends.length; i++) { - if(user.friends[i]["user_id"] === otherId) { - user.friends[i]["status"] = "denied"; - user.save((err) => { - if (err) { - throw err; - } - }); - console.log(user); - } - } - res.status(201).redirect(`/users/${otherId}`); + console.log(user); + res.status(201).redirect(`/users/${hostId}`); }); }, }; From d9a22a041d41666392b957e2b059fb3c0dd1ed5b Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 9 Feb 2023 14:53:39 +0000 Subject: [PATCH 26/71] adds max character count: 250 --- views/posts/details.hbs | 2 +- views/posts/new.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/views/posts/details.hbs b/views/posts/details.hbs index 9f148ee11..a6c840d1c 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -3,7 +3,7 @@ {{post.message}}
    - +
    diff --git a/views/posts/new.hbs b/views/posts/new.hbs index 99e10342e..a71bc74bd 100644 --- a/views/posts/new.hbs +++ b/views/posts/new.hbs @@ -1,5 +1,5 @@
    - +
    From 71f33942db5f6756513f94e8eb12e515057e3998 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Thu, 9 Feb 2023 15:19:08 +0000 Subject: [PATCH 27/71] added post user links --- controllers/posts.js | 1 + models/post.js | 1 + views/posts/index.hbs | 1 + 3 files changed, 3 insertions(+) diff --git a/controllers/posts.js b/controllers/posts.js index 2b13e8d6e..b7e000a5c 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -17,6 +17,7 @@ const PostsController = { Create: (req, res) => { const post = new Post(req.body); post.date = Date.now(); + post.user_id = req.session.user._id; post.save((err) => { if (err) { throw err; diff --git a/models/post.js b/models/post.js index e0391a552..5cf0b1aff 100644 --- a/models/post.js +++ b/models/post.js @@ -5,6 +5,7 @@ const PostSchema = new mongoose.Schema({ likes: { type: Number, default: 0 }, liked_by: [], date: Date, + user_id: String, }); const Post = mongoose.model("Post", PostSchema); diff --git a/views/posts/index.hbs b/views/posts/index.hbs index caeea6f5c..2880c74dd 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -1,6 +1,7 @@

    Timeline

      {{#each posts}} + User Profile
    • {{this.message}}
    • {{this.likes}} likes
    • From a560823fb4197d27170b004c38d8402e36cc0f92 Mon Sep 17 00:00:00 2001 From: Joao Date: Thu, 9 Feb 2023 15:31:22 +0000 Subject: [PATCH 28/71] updated e2e testing suite --- cypress/integration/home_page_spec.js | 1 - .../integration/user_can_like_posts_spec.js | 121 +++++++++++------- .../user_can_see_posts_count_on_post.js | 1 + cypress/integration/user_can_sign_in_spec.js | 1 + cypress/integration/user_can_sign_up_spec.js | 43 +++++++ .../integration/user_can_submit_posts_spec.js | 1 + views/posts/index.hbs | 20 +-- 7 files changed, 135 insertions(+), 53 deletions(-) diff --git a/cypress/integration/home_page_spec.js b/cypress/integration/home_page_spec.js index 161598e86..62897d55b 100644 --- a/cypress/integration/home_page_spec.js +++ b/cypress/integration/home_page_spec.js @@ -1,5 +1,4 @@ describe("Home page", () => { - it("has a title", () => { cy.task("wipe_database"); cy.visit("/"); diff --git a/cypress/integration/user_can_like_posts_spec.js b/cypress/integration/user_can_like_posts_spec.js index f33bb25fb..53a74159a 100644 --- a/cypress/integration/user_can_like_posts_spec.js +++ b/cypress/integration/user_can_like_posts_spec.js @@ -1,43 +1,78 @@ -// var mongoose = require("mongoose"); -// -// require("../mongodb_helper2"); -// var Post = require("../../models/post"); -// describe("Timeline", () => { -// beforeEach((done) => { -// // mongoose.connection.collections.users.drop(() => { -// // done(); -// // }); -// mongoose.connection.collections.posts.drop(() => { -// done(); -// }); -// }); -// -// it("can see likes count on a new post", () => { -// // sign up -// cy.visit("/users/new"); -// cy.get("#email").type("tester@email.com"); -// cy.get("#password").type("password123"); -// cy.get("#submit").click(); -// -// // sign in -// cy.visit("/sessions/new"); -// cy.get("#email").type("tester@email.com"); -// cy.get("#password").type("password123"); -// cy.get("#submit").click(); -// -// // submit a post -// cy.visit("/posts"); -// cy.contains("New post").click(); -// -// cy.get("#new-post-form").find('[type="text"]').type("Testing time 1234"); -// cy.get("#new-post-form").submit(); -// -// cy.get(".posts").should("contain", "Testing time 1234"); -// -// // Assert that we can see the likes count -// cy.get(".posts").should("contain", "1 likes"); -// -// -// -// }); -// }); +describe("Timeline", () => { + it("can see likes count on a new post", () => { + // sign up + cy.task("wipe_database"); + cy.visit("/users/new"); + cy.get("#email").type("tester@email.com"); + cy.get("#password").type("password123"); + cy.get("#submit").click(); + + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("tester@email.com"); + cy.get("#password").type("password123"); + cy.get("#submit").click(); + + // submit a post + cy.visit("/posts"); + cy.contains("New post").click(); + + cy.get("#new-post-form").find('[type="text"]').type("Testing time 1234"); + cy.get("#new-post-form").submit(); + + cy.get(".posts").should("contain", "Testing time 1234"); + + // Assert that we can see the likes count + cy.get(".posts").should("contain", "0 likes"); + cy.get("button:first").click(); + + // Assert that we can see the updated likes count + cy.get(".posts").should("contain", "1 like"); + }); + it("can see likes count on a new post with two existing posts", () => { + // sign up + cy.task("wipe_database"); + cy.visit("/users/new"); + cy.get("#email").type("tester@email.com"); + cy.get("#password").type("password123"); + cy.get("#submit").click(); + + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("tester@email.com"); + cy.get("#password").type("password123"); + cy.get("#submit").click(); + + + cy.visit("/posts"); + + // submit first post + cy.contains("New post").click(); + cy.get("#new-post-form").find('[type="text"]').type("Testing time 1"); + cy.get("#new-post-form").submit(); + + cy.get(".posts").should("contain", "Testing time 1"); + + // submit second post + cy.contains("New post").click(); + cy.get("#new-post-form").find('[type="text"]').type("Testing time 2"); + cy.get("#new-post-form").submit(); + + cy.get(".posts").should("contain", "Testing time 2"); + cy.get("button:first").click(); + + + // must be fixed, this is garbage + // cy.get(".posts").eq(0).should("contain", "1 like"); + // cy.get(".posts").eq(1).should("contain", "0 likes"); + + + + // Assert that we can see the likes count + cy.get(".posts").should("contain", "0 likes"); + // cy.get("button:first").click(); + + // Assert that we can see the updated likes count + cy.get(".posts").should("contain", "1 like"); + }); +}); diff --git a/cypress/integration/user_can_see_posts_count_on_post.js b/cypress/integration/user_can_see_posts_count_on_post.js index 203897aca..b7aa655e3 100644 --- a/cypress/integration/user_can_see_posts_count_on_post.js +++ b/cypress/integration/user_can_see_posts_count_on_post.js @@ -1,6 +1,7 @@ describe("Timeline", () => { it("can see likes count on a new post", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#email").type("someone@example.com"); cy.get("#password").type("password"); diff --git a/cypress/integration/user_can_sign_in_spec.js b/cypress/integration/user_can_sign_in_spec.js index 2c2ae6d9a..6d31a3596 100644 --- a/cypress/integration/user_can_sign_in_spec.js +++ b/cypress/integration/user_can_sign_in_spec.js @@ -1,6 +1,7 @@ describe("Authentication", () => { it("A user signs in and is redirected to /posts", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#email").type("someone@example.com"); cy.get("#password").type("password"); diff --git a/cypress/integration/user_can_sign_up_spec.js b/cypress/integration/user_can_sign_up_spec.js index 7863a66e5..bb31e2052 100644 --- a/cypress/integration/user_can_sign_up_spec.js +++ b/cypress/integration/user_can_sign_up_spec.js @@ -1,6 +1,7 @@ describe("Registration", () => { it("A user signs up and is redirected to sign in", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#email").type("someone@example.com"); cy.get("#password").type("password"); @@ -8,4 +9,46 @@ describe("Registration", () => { cy.url().should("include", "/sessions/new"); }); + + it("A user cannot sign up with blank credentials", () => { + // sign up + cy.visit("/users/new"); + cy.get("#submit").click(); + cy.url().should("include", "/users/new"); + }); + + it("A user cannot sign up with valid email and blank password", () => { + // sign up + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#submit").click(); + cy.url().should("include", "/users/new"); + }); + + it("A user cannot sign up with a valid password and blank email", () => { + // sign up + cy.visit("/users/new"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + cy.url().should("include", "/users/new"); + }); + + it("A user cannot sign up with a password and an incomplete/invalid email", () => { + // sign up + cy.visit("/users/new"); + cy.get("#email").type("someone"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + cy.url().should("include", "/users/new"); + }); + + // + // it("A user cannot sign up with a valid email and an invalid password", () => { + // // sign up + // cy.visit("/users/new"); + // cy.get("#email").type("someone@example.com"); + // cy.get("#password").type("pass"); + // cy.get("#submit").click(); + // cy.url().should("include", "/users/new"); + // }); }); diff --git a/cypress/integration/user_can_submit_posts_spec.js b/cypress/integration/user_can_submit_posts_spec.js index 019075937..5cd13cee9 100644 --- a/cypress/integration/user_can_submit_posts_spec.js +++ b/cypress/integration/user_can_submit_posts_spec.js @@ -1,6 +1,7 @@ describe("Timeline", () => { it("can submit posts, when signed in, and view them", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#email").type("someone@example.com"); cy.get("#password").type("password"); diff --git a/views/posts/index.hbs b/views/posts/index.hbs index caeea6f5c..e8a2e7c35 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -1,14 +1,16 @@

      Timeline

        - {{#each posts}} -
      • {{this.message}}
      • -
      • {{this.likes}} likes
      • - - - - More details -

        =====================

        - {{/each}} +
      • + {{#each posts}} +

        {{this.message}}

        +

        {{this.likes}} likes

        +
        + +
        + More details +

        =====================

        + {{/each}} +
      New post \ No newline at end of file From 00feb0d39286f04d137ab20738328d3b32ab6b03 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Thu, 9 Feb 2023 15:35:09 +0000 Subject: [PATCH 29/71] other users can't access your friend request --- controllers/users.js | 6 ++++++ views/users/details.hbs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/controllers/users.js b/controllers/users.js index c97961961..e351a27ee 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -29,11 +29,17 @@ const UsersController = { Details: (req, res) => { const userId = req.params.id; + const sessionId = req.session.user._id; User.findById(userId, (err, user) => { if (err) { throw err; } + + if(userId != sessionId) { + user.friends = []; + } + res.render("users/details", {user: user}); }); }, diff --git a/views/users/details.hbs b/views/users/details.hbs index 936e4dc75..bbe34afc0 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -2,6 +2,12 @@ + +
      + + +
      +

      Your friend requests

        {{#each user.friends}} From 5395d714a96f2c04f0bd5e8df324a2eab15e1c3a Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Thu, 9 Feb 2023 15:45:30 +0000 Subject: [PATCH 30/71] added user links to comments --- controllers/posts.js | 5 +++-- views/posts/details.hbs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index b7e000a5c..df26c73c0 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -62,7 +62,6 @@ const PostsController = { if (err) { throw err; } - res.render("posts/details", {comments: comments, post: post}); }).where({post_id: postId}) )); @@ -70,12 +69,14 @@ const PostsController = { CreateComment: (req, res) => { const postId = req.params.id; + const userId = req.session.user._id console.log(postId); const comment = new Comment(req.body); comment.post_id = postId; - + comment.user_id = userId; + if (comment.message[0] === " ") { const trimmed = comment.message.trim(); if (trimmed.length != 0) { diff --git a/views/posts/details.hbs b/views/posts/details.hbs index 9f148ee11..d7b055cfa 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -9,6 +9,7 @@
          {{#each comments}} + User Profile
        • {{this.message}}
        • {{/each}}
        From 4c592878313bef44df1462c6024e092865f32f0e Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Thu, 9 Feb 2023 15:49:02 +0000 Subject: [PATCH 31/71] added poster links to comments page --- views/posts/details.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/views/posts/details.hbs b/views/posts/details.hbs index d7b055cfa..f8af25d3b 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -1,5 +1,6 @@

        Post

        +User {{post.message}}
        From 3cd5bcd3faf831f0979c00ae5ff7fce5409c1a85 Mon Sep 17 00:00:00 2001 From: Joao Date: Thu, 9 Feb 2023 17:12:28 +0000 Subject: [PATCH 32/71] first e2e tests for posts comments --- .../user_can_submit_comments_spec.js | 112 ++++++++++++++++++ views/posts/details.hbs | 4 +- 2 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 cypress/integration/user_can_submit_comments_spec.js diff --git a/cypress/integration/user_can_submit_comments_spec.js b/cypress/integration/user_can_submit_comments_spec.js new file mode 100644 index 000000000..ac5de000a --- /dev/null +++ b/cypress/integration/user_can_submit_comments_spec.js @@ -0,0 +1,112 @@ +describe("Comments", () => { + it("user can create post and add comment to it", () => { + // sign up + cy.task("wipe_database"); + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // submit a post + cy.visit("/posts"); + cy.contains("New post").click(); + cy.get("#new-post-form").find('[type="text"]').type("Hello, world!"); + cy.get("#new-post-form").submit(); + + // add a comment + cy.contains("More details").click(); + cy.get(".title").should("contain", "Hello,"); + cy.get("#message").type("Comment 1"); + cy.contains("Create").click(); + cy.get(".comments li").should("contain", "Comment 1"); + }); + + it("user can't add empty comment to post", () => { + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // attempt to add a comment + cy.contains("More details").click(); + cy.get("#message").invoke('val', '') + cy.contains("Create").click(); + cy.get(".comments li").should("contain", "Comment 1"); + cy.get(".comments li").should("have.length", 1); + }); + + it("user can't add comment with just spaces to post", () => { + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // attempt to add a comment + cy.contains("More details").click(); + cy.get("#message").type(" "); + cy.contains("Create").click(); + cy.get(".comments li").should("contain", "Comment 1"); + cy.get(".comments li").should("have.length", 1); + }); + + it("user can comment on other user post", () => { + // sign up + cy.visit("/users/new"); + cy.get("#email").type("tester@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("tester@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // attempt to add a comment + cy.contains("More details").click(); + cy.get("#message").type("Comment 2"); + cy.contains("Create").click(); + cy.get(".comments li").should("contain", "Comment 2"); + cy.get(".comments li").should("have.length", 2); + }); + + it("user can navigate back to posts after visiting comments page", () => { + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("tester@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // go to comments page and add comment + cy.contains("More details").click(); + cy.get("#message").type("Comment 3"); + cy.contains("Create").click(); + + // travel back to posts + cy.contains("Posts").click(); + cy.url().should("include", "/posts"); + }); + + // it("user comment is added without extra spaces", () => { + // // sign in + // cy.visit("/sessions/new"); + // cy.get("#email").type("someone@example.com"); + // cy.get("#password").type("password"); + // cy.get("#submit").click(); + // + // // attempt to add a comment + // cy.contains("More details").click(); + // cy.get("#message").type(" Comment 4 "); + // cy.contains("Create").click(); + // cy.get(".comments li").eq(3).should("have.text", "Comment 4"); + // cy.get(".comments li").should("have.length", 4); + // }); +}); \ No newline at end of file diff --git a/views/posts/details.hbs b/views/posts/details.hbs index 9f148ee11..39ff8cf06 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -1,6 +1,4 @@ -

        Post

        - -{{post.message}} +

        {{post.message}}

        From 694f199563fda70abf27dd311efec6f2cf25b4f1 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Fri, 10 Feb 2023 10:25:31 +0000 Subject: [PATCH 33/71] updated sign up spec and submit post spec --- cypress/integration/user_can_sign_up_spec.js | 36 +++++++++++++----- .../integration/user_can_submit_posts_spec.js | 38 +++++++++++++++++++ 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/cypress/integration/user_can_sign_up_spec.js b/cypress/integration/user_can_sign_up_spec.js index bb31e2052..36baf430d 100644 --- a/cypress/integration/user_can_sign_up_spec.js +++ b/cypress/integration/user_can_sign_up_spec.js @@ -42,13 +42,31 @@ describe("Registration", () => { cy.url().should("include", "/users/new"); }); - // - // it("A user cannot sign up with a valid email and an invalid password", () => { - // // sign up - // cy.visit("/users/new"); - // cy.get("#email").type("someone@example.com"); - // cy.get("#password").type("pass"); - // cy.get("#submit").click(); - // cy.url().should("include", "/users/new"); - // }); + it("A user cannot sign up with a duplicate account", () => { + // sign up + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + cy.url().should("include", "/sessions/new"); + + // sign up 2 + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + cy.url().should("include", "/users/new"); + }); + + + it("A user cannot sign up with a valid email and an invalid password", () => { + // sign up + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("pass"); + + cy.get("#password").type('{enter}'); + cy.url().should("include", "/users/new"); + }); }); diff --git a/cypress/integration/user_can_submit_posts_spec.js b/cypress/integration/user_can_submit_posts_spec.js index 5cd13cee9..0a78c597f 100644 --- a/cypress/integration/user_can_submit_posts_spec.js +++ b/cypress/integration/user_can_submit_posts_spec.js @@ -22,4 +22,42 @@ describe("Timeline", () => { cy.get(".posts").should("contain", "Hello, world!"); }); + + it("cannot submit a blank post", () => { + // sign up + cy.task("wipe_database"); + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // DON'T submit a post, but press submit anyway + cy.visit("/posts"); + cy.contains("New post").click(); + cy.get("#message").type('{enter}') + cy.url().should("include", "/posts/new"); + + // Submit a post with just spaces - this should not post + cy.visit("/posts"); + cy.contains("New post").click(); + + cy.get("#new-post-form").find('[type="text"]').type(" "); + cy.get('#new-post-form > [type="submit"]').click() + cy.url().should("include", "/posts/new"); + + //Removed as it appears the HTML is fixing this itself + // // submit a flawed post, spaces at front, spaces in middle, spaces at end + // cy.get("#new-post-form").find('[type="text"]').type(" Hello, world! "); + // cy.get('#new-post-form > [type="submit"]').click() + // + // // assert that the message exists, but with the spaces stripped + // // eslint-disable-next-line no-invalid-regexp + // cy.get('li > :nth-child(1)').should('have.text',"Hello, world! "); + }); }); From 7f8e86aae16c448e2bc44b51b68ff5387e5c1120 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Fri, 10 Feb 2023 11:32:15 +0000 Subject: [PATCH 34/71] amended some tests to have 'submit' command to test the back end as well --- cypress/integration/user_can_submit_posts_spec.js | 13 ++++++++----- views/users/new.hbs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cypress/integration/user_can_submit_posts_spec.js b/cypress/integration/user_can_submit_posts_spec.js index 0a78c597f..4a91656e2 100644 --- a/cypress/integration/user_can_submit_posts_spec.js +++ b/cypress/integration/user_can_submit_posts_spec.js @@ -40,7 +40,7 @@ describe("Timeline", () => { // DON'T submit a post, but press submit anyway cy.visit("/posts"); cy.contains("New post").click(); - cy.get("#message").type('{enter}') + cy.get("#new-post-form").submit(); cy.url().should("include", "/posts/new"); // Submit a post with just spaces - this should not post @@ -51,13 +51,16 @@ describe("Timeline", () => { cy.get('#new-post-form > [type="submit"]').click() cy.url().should("include", "/posts/new"); - //Removed as it appears the HTML is fixing this itself - // // submit a flawed post, spaces at front, spaces in middle, spaces at end - // cy.get("#new-post-form").find('[type="text"]').type(" Hello, world! "); + + + // CAN INSERT BACK IN FOR FORMATTING _ CURRENTLY RELYING ON HTML + + // submit a flawed post, spaces at front, spaces in middle, spaces at end + // cy.get("#new-post-form").find('[type="text"]').type(" Hello, world! "); // cy.get('#new-post-form > [type="submit"]').click() // // // assert that the message exists, but with the spaces stripped // // eslint-disable-next-line no-invalid-regexp - // cy.get('li > :nth-child(1)').should('have.text',"Hello, world! "); + // cy.get('li > :nth-child(1)').should('have.text',"Hello, world!"); }); }); diff --git a/views/users/new.hbs b/views/users/new.hbs index e9033dc00..f9e528e0a 100644 --- a/views/users/new.hbs +++ b/views/users/new.hbs @@ -2,6 +2,6 @@ - + From 7e202850bccb7495b01edf82ed0ce21fbde9e452 Mon Sep 17 00:00:00 2001 From: Joao Date: Fri, 10 Feb 2023 11:35:59 +0000 Subject: [PATCH 35/71] new test added --- .../user_can_submit_comments_spec.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cypress/integration/user_can_submit_comments_spec.js b/cypress/integration/user_can_submit_comments_spec.js index ac5de000a..a94e43b7f 100644 --- a/cypress/integration/user_can_submit_comments_spec.js +++ b/cypress/integration/user_can_submit_comments_spec.js @@ -95,18 +95,18 @@ describe("Comments", () => { cy.url().should("include", "/posts"); }); - // it("user comment is added without extra spaces", () => { - // // sign in - // cy.visit("/sessions/new"); - // cy.get("#email").type("someone@example.com"); - // cy.get("#password").type("password"); - // cy.get("#submit").click(); - // - // // attempt to add a comment - // cy.contains("More details").click(); - // cy.get("#message").type(" Comment 4 "); - // cy.contains("Create").click(); - // cy.get(".comments li").eq(3).should("have.text", "Comment 4"); - // cy.get(".comments li").should("have.length", 4); - // }); + it("user comment is added without extra spaces", () => { + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // attempt to add a comment + cy.contains("More details").click(); + cy.get("#message").type(" Comment 4 "); + cy.contains("Create").click(); + cy.get(".comments li").eq(3).should("have.text", "Comment 4"); + cy.get(".comments li").should("have.length", 4); + }); }); \ No newline at end of file From 2b71342da4669be0555fec216896ded6fbe34e40 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Fri, 10 Feb 2023 11:45:26 +0000 Subject: [PATCH 36/71] backend checks for html --- controllers/posts.js | 27 +++++++++++++++++---------- controllers/users.js | 8 ++++---- views/posts/details.hbs | 2 +- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index df26c73c0..e5914e83f 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -18,13 +18,17 @@ const PostsController = { const post = new Post(req.body); post.date = Date.now(); post.user_id = req.session.user._id; - post.save((err) => { - if (err) { - throw err; - } - + if (post.message === "" || post.message.length > 250) { res.status(201).redirect("/posts"); - }); + } else { + post.save((err) => { + if (err) { + throw err; + } + + res.status(201).redirect("/posts"); + }); + } }, Like: (req, res) => { @@ -71,13 +75,16 @@ const PostsController = { const postId = req.params.id; const userId = req.session.user._id - console.log(postId); - const comment = new Comment(req.body); comment.post_id = postId; comment.user_id = userId; - - if (comment.message[0] === " ") { + + console.log(comment.message) + + if (comment.message === "" || comment.message.length > 250) { + console.log("oops") + res.status(201).redirect(`/posts/${postId}`); + } else if (comment.message[0] === " ") { const trimmed = comment.message.trim(); if (trimmed.length != 0) { comment.message = trimmed; diff --git a/controllers/users.js b/controllers/users.js index e351a27ee..b89a83fbe 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -13,16 +13,16 @@ const UsersController = { throw err; } - if (founduser === null) { + if (user.email === "" || user.password < 8 || founduser != null) { + req.session.error = "INVALID USERNAME OR PASSWORD"; + res.redirect("/users/new"); + } else if (founduser === null) { user.save((err) => { if (err) { throw err; } res.status(201).redirect("/sessions/new"); }); - } else { - req.session.error = "INVALID USERNAME OR PASSWORD"; - res.redirect("/users/new"); } }) }, diff --git a/views/posts/details.hbs b/views/posts/details.hbs index c6cae4c1d..c218b9c67 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -3,7 +3,7 @@ User {{post.message}} -
        +
        From 7edc9b6398bdc5d9a75737ced2aecbbd79adc553 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Fri, 10 Feb 2023 11:46:42 +0000 Subject: [PATCH 37/71] removed redundant code --- controllers/posts.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index e5914e83f..9e2b3ad21 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -79,8 +79,6 @@ const PostsController = { comment.post_id = postId; comment.user_id = userId; - console.log(comment.message) - if (comment.message === "" || comment.message.length > 250) { console.log("oops") res.status(201).redirect(`/posts/${postId}`); From 7620757d4aa3deb7ac5a5c739a99c9f7bb0c0c2d Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Fri, 10 Feb 2023 11:48:07 +0000 Subject: [PATCH 38/71] removed more redundant code --- controllers/posts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/posts.js b/controllers/posts.js index 9e2b3ad21..7ac5a040d 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -80,7 +80,6 @@ const PostsController = { comment.user_id = userId; if (comment.message === "" || comment.message.length > 250) { - console.log("oops") res.status(201).redirect(`/posts/${postId}`); } else if (comment.message[0] === " ") { const trimmed = comment.message.trim(); From d7a957e50a10d4c9d4601eefe7800043a9338bea Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Fri, 10 Feb 2023 11:56:24 +0000 Subject: [PATCH 39/71] added log in link to sign up page --- views/users/new.hbs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/views/users/new.hbs b/views/users/new.hbs index ceb2b1267..01ed72a99 100644 --- a/views/users/new.hbs +++ b/views/users/new.hbs @@ -5,4 +5,6 @@ -

        {{this.error}}

        \ No newline at end of file +

        {{this.error}}

        + +Log in \ No newline at end of file From 01c617e0707bb47decae205f9984fa420c315ffc Mon Sep 17 00:00:00 2001 From: Joao Date: Fri, 10 Feb 2023 12:23:21 +0000 Subject: [PATCH 40/71] more tests --- .../integration/user_can_like_posts_spec.js | 17 ++++------- .../user_can_see_posts_count_on_post.js | 29 ------------------- cypress/integration/user_can_sign_up_spec.js | 8 ++++- .../user_can_submit_comments_spec.js | 1 - .../integration/user_can_submit_posts_spec.js | 2 +- cypress/plugins/index.js | 1 - 6 files changed, 13 insertions(+), 45 deletions(-) delete mode 100644 cypress/integration/user_can_see_posts_count_on_post.js diff --git a/cypress/integration/user_can_like_posts_spec.js b/cypress/integration/user_can_like_posts_spec.js index 53a74159a..2a24401a5 100644 --- a/cypress/integration/user_can_like_posts_spec.js +++ b/cypress/integration/user_can_like_posts_spec.js @@ -1,4 +1,4 @@ -describe("Timeline", () => { +describe("Timeline Likes", () => { it("can see likes count on a new post", () => { // sign up cy.task("wipe_database"); @@ -24,11 +24,12 @@ describe("Timeline", () => { // Assert that we can see the likes count cy.get(".posts").should("contain", "0 likes"); - cy.get("button:first").click(); - + cy.get("button").click(); + cy.wait(1000); // Assert that we can see the updated likes count - cy.get(".posts").should("contain", "1 like"); + cy.get(".posts").should("contain", "1 likes"); }); + it("can see likes count on a new post with two existing posts", () => { // sign up cy.task("wipe_database"); @@ -61,16 +62,8 @@ describe("Timeline", () => { cy.get(".posts").should("contain", "Testing time 2"); cy.get("button:first").click(); - - // must be fixed, this is garbage - // cy.get(".posts").eq(0).should("contain", "1 like"); - // cy.get(".posts").eq(1).should("contain", "0 likes"); - - - // Assert that we can see the likes count cy.get(".posts").should("contain", "0 likes"); - // cy.get("button:first").click(); // Assert that we can see the updated likes count cy.get(".posts").should("contain", "1 like"); diff --git a/cypress/integration/user_can_see_posts_count_on_post.js b/cypress/integration/user_can_see_posts_count_on_post.js deleted file mode 100644 index b7aa655e3..000000000 --- a/cypress/integration/user_can_see_posts_count_on_post.js +++ /dev/null @@ -1,29 +0,0 @@ -describe("Timeline", () => { - it("can see likes count on a new post", () => { - // sign up - cy.task("wipe_database"); - cy.visit("/users/new"); - cy.get("#email").type("someone@example.com"); - cy.get("#password").type("password"); - cy.get("#submit").click(); - - // sign in - cy.visit("/sessions/new"); - cy.get("#email").type("someone@example.com"); - cy.get("#password").type("password"); - cy.get("#submit").click(); - - // submit a post - cy.visit("/posts"); - cy.contains("New post").click(); - - cy.get("#new-post-form").find('[type="text"]').type("Hello, world!"); - cy.get("#new-post-form").submit(); - - cy.get(".posts").should("contain", "Hello, world!"); - - // Assert that we can see the likes count - cy.get(".posts").should("contain", "0 likes"); - }); - }); - \ No newline at end of file diff --git a/cypress/integration/user_can_sign_up_spec.js b/cypress/integration/user_can_sign_up_spec.js index 36baf430d..152751887 100644 --- a/cypress/integration/user_can_sign_up_spec.js +++ b/cypress/integration/user_can_sign_up_spec.js @@ -12,6 +12,7 @@ describe("Registration", () => { it("A user cannot sign up with blank credentials", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#submit").click(); cy.url().should("include", "/users/new"); @@ -19,6 +20,7 @@ describe("Registration", () => { it("A user cannot sign up with valid email and blank password", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#email").type("someone@example.com"); cy.get("#submit").click(); @@ -27,6 +29,7 @@ describe("Registration", () => { it("A user cannot sign up with a valid password and blank email", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#password").type("password"); cy.get("#submit").click(); @@ -35,6 +38,7 @@ describe("Registration", () => { it("A user cannot sign up with a password and an incomplete/invalid email", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#email").type("someone"); cy.get("#password").type("password"); @@ -44,6 +48,7 @@ describe("Registration", () => { it("A user cannot sign up with a duplicate account", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#email").type("someone@example.com"); cy.get("#password").type("password"); @@ -56,16 +61,17 @@ describe("Registration", () => { cy.get("#email").type("someone@example.com"); cy.get("#password").type("password"); cy.get("#submit").click(); + // this may fail if a redirect is implemented cy.url().should("include", "/users/new"); }); it("A user cannot sign up with a valid email and an invalid password", () => { // sign up + cy.task("wipe_database"); cy.visit("/users/new"); cy.get("#email").type("someone@example.com"); cy.get("#password").type("pass"); - cy.get("#password").type('{enter}'); cy.url().should("include", "/users/new"); }); diff --git a/cypress/integration/user_can_submit_comments_spec.js b/cypress/integration/user_can_submit_comments_spec.js index a94e43b7f..63f850ab4 100644 --- a/cypress/integration/user_can_submit_comments_spec.js +++ b/cypress/integration/user_can_submit_comments_spec.js @@ -36,7 +36,6 @@ describe("Comments", () => { // attempt to add a comment cy.contains("More details").click(); - cy.get("#message").invoke('val', '') cy.contains("Create").click(); cy.get(".comments li").should("contain", "Comment 1"); cy.get(".comments li").should("have.length", 1); diff --git a/cypress/integration/user_can_submit_posts_spec.js b/cypress/integration/user_can_submit_posts_spec.js index 4a91656e2..4b0b4d2f3 100644 --- a/cypress/integration/user_can_submit_posts_spec.js +++ b/cypress/integration/user_can_submit_posts_spec.js @@ -1,4 +1,4 @@ -describe("Timeline", () => { +describe("Timeline Posts", () => { it("can submit posts, when signed in, and view them", () => { // sign up cy.task("wipe_database"); diff --git a/cypress/plugins/index.js b/cypress/plugins/index.js index e45e1596c..5943c9007 100644 --- a/cypress/plugins/index.js +++ b/cypress/plugins/index.js @@ -29,7 +29,6 @@ const mongoose = require("mongoose"); module.exports = (on) => { on('task', { 'wipe_database': async () => { - console.log("hello world"); mongoose.connect("mongodb://0.0.0.0/acebook_test", { useNewUrlParser: true, useUnifiedTopology: true, From d3c7d6d8a1cec0386b63b280bdb252a3bb23c797 Mon Sep 17 00:00:00 2001 From: Adam <110791742+TheMany172@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:01:37 +0000 Subject: [PATCH 41/71] Updated README With extra tips for set up and with general rules and ongoing definition for quality --- README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d3c16f78d..ba67e48b8 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,7 @@ It uses: ## Card wall -REPLACE THIS TEXT WITH A LINK TO YOUR CARD WALL - -HAS THIS CHANGED GONE THROUGH? +Link to Trello: https://trello.com/b/TpjSuBYO/jam-a-pc ## Quickstart @@ -33,6 +31,17 @@ HAS THIS CHANGED GONE THROUGH? 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 @@ -76,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 @@ -95,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 From cc4727963a3ab659d48c25a14bd046ca8c804f75 Mon Sep 17 00:00:00 2001 From: Adam <110791742+TheMany172@users.noreply.github.com> Date: Fri, 10 Feb 2023 14:02:33 +0000 Subject: [PATCH 42/71] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba67e48b8..757f6f40a 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ To be used as a guide, will fluctuate day to day as work needs 5. any issues? -**Quality** for the group is: +## Quality - for the group is: - understandable code - fully functional to the MVP - or above if time - looks nice as well From cddab7eea7a77dc72aa52c734fa51f1ed8e157b3 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Fri, 10 Feb 2023 14:29:42 +0000 Subject: [PATCH 43/71] pending filter --- controllers/users.js | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/users.js b/controllers/users.js index b89a83fbe..2bdc8d21b 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -39,6 +39,7 @@ const UsersController = { if(userId != sessionId) { user.friends = []; } + user.friends = user.friends.filter(object => object.status === "pending"); res.render("users/details", {user: user}); }); From 4ad6c51df6793c44633deee9bc32223731f74e11 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Fri, 10 Feb 2023 14:41:15 +0000 Subject: [PATCH 44/71] modified posts controller to just redirect to the same page rather than a different one --- controllers/posts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/posts.js b/controllers/posts.js index 7ac5a040d..b8b9da17a 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -19,7 +19,7 @@ const PostsController = { post.date = Date.now(); post.user_id = req.session.user._id; if (post.message === "" || post.message.length > 250) { - res.status(201).redirect("/posts"); + res.status(201).redirect("/posts/new"); } else { post.save((err) => { if (err) { From 895a80907d1bd9f30520c6e4c4863706d20e6a6a Mon Sep 17 00:00:00 2001 From: Adam Little Date: Fri, 10 Feb 2023 14:51:55 +0000 Subject: [PATCH 45/71] split test for blank post and post with just spaces into two, and amended users controller to include .length for password verification --- controllers/users.js | 2 +- .../integration/user_can_submit_posts_spec.js | 38 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index b89a83fbe..f5059f925 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -13,7 +13,7 @@ const UsersController = { throw err; } - if (user.email === "" || user.password < 8 || founduser != null) { + if (user.email === "" || user.password.length < 8 || founduser != null) { req.session.error = "INVALID USERNAME OR PASSWORD"; res.redirect("/users/new"); } else if (founduser === null) { diff --git a/cypress/integration/user_can_submit_posts_spec.js b/cypress/integration/user_can_submit_posts_spec.js index 4b0b4d2f3..f24a78bc5 100644 --- a/cypress/integration/user_can_submit_posts_spec.js +++ b/cypress/integration/user_can_submit_posts_spec.js @@ -43,16 +43,6 @@ describe("Timeline Posts", () => { cy.get("#new-post-form").submit(); cy.url().should("include", "/posts/new"); - // Submit a post with just spaces - this should not post - cy.visit("/posts"); - cy.contains("New post").click(); - - cy.get("#new-post-form").find('[type="text"]').type(" "); - cy.get('#new-post-form > [type="submit"]').click() - cy.url().should("include", "/posts/new"); - - - // CAN INSERT BACK IN FOR FORMATTING _ CURRENTLY RELYING ON HTML // submit a flawed post, spaces at front, spaces in middle, spaces at end @@ -63,4 +53,32 @@ describe("Timeline Posts", () => { // // eslint-disable-next-line no-invalid-regexp // cy.get('li > :nth-child(1)').should('have.text',"Hello, world!"); }); + it("cannot submit a post as just 'spaces'", () => { + // sign up + cy.task("wipe_database"); + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // DON'T submit a post, but press submit anyway + cy.visit("/posts"); + cy.contains("New post").click(); + cy.get("#new-post-form").submit(); + cy.url().should("include", "/posts/new"); + + // Submit a post with just spaces - this should not post + cy.visit("/posts"); + cy.contains("New post").click(); + cy.get("#new-post-form").find('[type="text"]').type(" "); + cy.get('#new-post-form > [type="submit"]').click() + cy.url().should("include", "/posts/new"); + + }); }); From f54ed1d62582db95dcda3ad812f01e03e82f92c1 Mon Sep 17 00:00:00 2001 From: Adam Little Date: Fri, 10 Feb 2023 15:17:17 +0000 Subject: [PATCH 46/71] modified controllers to fix the issue of posts with spaces --- controllers/posts.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/controllers/posts.js b/controllers/posts.js index b8b9da17a..636448120 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -20,6 +20,20 @@ const PostsController = { 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/new`); + }); + } else { + res.status(201).redirect(`/posts/new`); + } } else { post.save((err) => { if (err) { From 9188013e4f1e132723701fd6100ad54b8e4e1edd Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Fri, 10 Feb 2023 15:57:04 +0000 Subject: [PATCH 47/71] views changes --- views/posts/details.hbs | 5 ++++- views/posts/index.hbs | 1 + views/users/new.hbs | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/views/posts/details.hbs b/views/posts/details.hbs index 55b671ea7..c218b9c67 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -1,4 +1,7 @@ -

        {{post.message}}

        +

        Post

        + +User +{{post.message}}
        diff --git a/views/posts/index.hbs b/views/posts/index.hbs index e8a2e7c35..642c3aec5 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -2,6 +2,7 @@
        • {{#each posts}} + User Profile

          {{this.message}}

          {{this.likes}} likes

          diff --git a/views/users/new.hbs b/views/users/new.hbs index 324c4a4a4..01ed72a99 100644 --- a/views/users/new.hbs +++ b/views/users/new.hbs @@ -2,8 +2,8 @@ - - + +
        • {{this.error}}

          From 23830b79dc815bd99c30dd1704b69e3453b1d64e Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 10:13:12 +0000 Subject: [PATCH 48/71] working picture links --- controllers/users.js | 16 ++++++++++++++++ models/user.js | 1 + routes/users.js | 1 + views/users/details.hbs | 10 ++++++---- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index f5059f925..530021eb4 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -90,6 +90,22 @@ const UsersController = { res.status(201).redirect(`/users/${hostId}`); }); }, + + Picture: (req, res) => { + const hostId = req.params.id; + + User.findById(hostId, (err, user) => { + user.picture = req.body.picture; + + user.save((err) => { + if (err) { + throw err; + } + + res.status(201).redirect(`/users/${hostId}`); + }); + }); + }, }; module.exports = UsersController; diff --git a/models/user.js b/models/user.js index a753603f4..f8e99b4b0 100644 --- a/models/user.js +++ b/models/user.js @@ -4,6 +4,7 @@ const UserSchema = new mongoose.Schema({ email: String, password: String, friends: Array, + picture: String, }); const User = mongoose.model("User", UserSchema); diff --git a/routes/users.js b/routes/users.js index 6ead24d30..328de05d0 100644 --- a/routes/users.js +++ b/routes/users.js @@ -8,6 +8,7 @@ router.post("/", UsersController.Create); router.get("/:id", UsersController.Details); router.post("/:id/request", UsersController.Request); router.post("/:id/confirm", UsersController.Confirm); +router.post("/:id/picture", UsersController.Picture); router.post("/:id/deny", UsersController.Deny); module.exports = router; diff --git a/views/users/details.hbs b/views/users/details.hbs index bbe34afc0..bf4927636 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -2,12 +2,14 @@ - -
          - - + + + +
          + +

          Your friend requests

            {{#each user.friends}} From 0d08a1cbe7d203666b796c17ae740849e9a6fbce Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 10:21:53 +0000 Subject: [PATCH 49/71] only user can update their own picture --- controllers/users.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index 40c657428..2b6e57c9b 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -94,17 +94,21 @@ const UsersController = { Picture: (req, res) => { const hostId = req.params.id; + const currentId = req.session.user._id; User.findById(hostId, (err, user) => { - user.picture = req.body.picture; - - user.save((err) => { - if (err) { - throw err; - } - + if (currentId === hostId) { + user.save((err) => { + if (err) { + throw err; + } + + res.status(201).redirect(`/users/${hostId}`); + }); + } else { res.status(201).redirect(`/users/${hostId}`); - }); + } + user.picture = req.body.picture; }); }, }; From 9ec141ddb4558eaf8bfd00c89c7998d399a1317d Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 10:24:37 +0000 Subject: [PATCH 50/71] max picture size --- views/users/details.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/users/details.hbs b/views/users/details.hbs index bf4927636..a4a0ae86f 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -8,7 +8,7 @@ - +

            Your friend requests

              From 74c06679aa22d3dc9c69c26b3c8ade089a1c8039 Mon Sep 17 00:00:00 2001 From: Joao Date: Mon, 13 Feb 2023 11:07:33 +0000 Subject: [PATCH 51/71] fixed test after views change --- controllers/posts.js | 2 +- .../user_can_submit_comments_spec.js | 2 +- .../integration/user_can_submit_posts_spec.js | 57 +++- stylesheets/style.css | 278 ++++++++++++++++++ 4 files changed, 328 insertions(+), 11 deletions(-) create mode 100644 stylesheets/style.css diff --git a/controllers/posts.js b/controllers/posts.js index 636448120..998463c7a 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -29,7 +29,7 @@ const PostsController = { throw err; } - res.status(201).redirect(`/posts/new`); + res.status(201).redirect(`/posts/`); }); } else { res.status(201).redirect(`/posts/new`); diff --git a/cypress/integration/user_can_submit_comments_spec.js b/cypress/integration/user_can_submit_comments_spec.js index 63f850ab4..d1c8adbad 100644 --- a/cypress/integration/user_can_submit_comments_spec.js +++ b/cypress/integration/user_can_submit_comments_spec.js @@ -21,7 +21,7 @@ describe("Comments", () => { // add a comment cy.contains("More details").click(); - cy.get(".title").should("contain", "Hello,"); + cy.get("body").should("contain", "Hello,"); cy.get("#message").type("Comment 1"); cy.contains("Create").click(); cy.get(".comments li").should("contain", "Comment 1"); diff --git a/cypress/integration/user_can_submit_posts_spec.js b/cypress/integration/user_can_submit_posts_spec.js index f24a78bc5..939bc98e7 100644 --- a/cypress/integration/user_can_submit_posts_spec.js +++ b/cypress/integration/user_can_submit_posts_spec.js @@ -42,17 +42,57 @@ describe("Timeline Posts", () => { cy.contains("New post").click(); cy.get("#new-post-form").submit(); cy.url().should("include", "/posts/new"); + }); + + it("cannot submit a post as just 'spaces'", () => { + // sign up + cy.task("wipe_database"); + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + // DON'T submit a post, but press submit anyway + cy.visit("/posts"); + cy.contains("New post").click(); + cy.get("#new-post-form").submit(); + cy.url().should("include", "/posts/new"); + + // Submit a post with just spaces - this should not post + cy.visit("/posts"); + cy.contains("New post").click(); + cy.get("#new-post-form").find('[type="text"]').type(" "); + cy.get('#new-post-form > [type="submit"]').click() + cy.url().should("include", "/posts/new"); + }); - // CAN INSERT BACK IN FOR FORMATTING _ CURRENTLY RELYING ON HTML + it("a post with extra spaces will be trimmed", () => { + // sign up + cy.task("wipe_database"); + cy.visit("/users/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); - // submit a flawed post, spaces at front, spaces in middle, spaces at end - // cy.get("#new-post-form").find('[type="text"]').type(" Hello, world! "); - // cy.get('#new-post-form > [type="submit"]').click() - // - // // assert that the message exists, but with the spaces stripped - // // eslint-disable-next-line no-invalid-regexp - // cy.get('li > :nth-child(1)').should('have.text',"Hello, world!"); + // sign in + cy.visit("/sessions/new"); + cy.get("#email").type("someone@example.com"); + cy.get("#password").type("password"); + cy.get("#submit").click(); + + cy.visit("/posts"); + cy.contains("New post").click(); + cy.get("#new-post-form").find('[type="text"]').type(" Hello, world! "); + cy.get('#new-post-form > [type="submit"]').click() + cy.get('ul').should('contain.text',"Hello, world!"); }); + it("cannot submit a post as just 'spaces'", () => { // sign up cy.task("wipe_database"); @@ -79,6 +119,5 @@ describe("Timeline Posts", () => { cy.get("#new-post-form").find('[type="text"]').type(" "); cy.get('#new-post-form > [type="submit"]').click() cy.url().should("include", "/posts/new"); - }); }); diff --git a/stylesheets/style.css b/stylesheets/style.css new file mode 100644 index 000000000..1fd8b996c --- /dev/null +++ b/stylesheets/style.css @@ -0,0 +1,278 @@ +body +{ + text-align:center; + width:100%; + margin:0 auto; + padding:0px; + font-family:"lucida grande",tahoma,verdana,arial,sans-serif; + background: linear-gradient(white, #D3D8E8); +} +#header_wrapper +{ + width:100%; + min-width:980px; + background-color:#4c66a4; +} +#header +{ + width:980px; + margin:0px auto; + padding:0px; + height:85px; +} +#header li +{ + list-style-type:none; + float:left; + text-align:left; + color:white; +} +#header #sitename +{ + margin-top:25px; +} +#header #sitename a +{ + color:white; + text-decoration:none; + font-size:30px; + font-weight:900; +} +#header form +{ + margin-top:15px; + float:right; +} +#header form li +{ + font-size:13px; + margin-left:15px; +} +#header form li a +{ + color:#A9BCF5; + text-decoration:none; +} +#header form input[type="text"] +{ + margin-top:3px; + margin-bottom:3px; + width:150px; + border:1px solid #08298A; + height:25px; + padding-left:3px; +} +#header form input[type="password"] +{ + margin-top:3px; + margin-bottom:3px; + width:150px; + border:1px solid #08298A; + height:25px; + padding-left:3px; +} +#header form input[type="submit"] +{ + height:25px; + margin-top:20px; + background-color:#084B8A; + color:white; + border:1px solid #08298A; +} +#wrapper +{ + margin:0 auto; + padding:0px; + text-align:center; + width:980px; +} +#wrapper div +{ + float:left; + font-family: helvetica, arial, sans-serif; +} +#wrapper #div1 +{ + margin-top:30px; + width:590px; + text-align:left; +} +#wrapper #div1 p +{ + font-size:20px; + font-family:arial; + font-weight:bold; + margin:0px; + color:#0e385f; +} +#wrapper #div2 +{ + margin-top:10px; + width:390px; + text-align:left; +} +#wrapper #div2 h1 +{ + margin:0px; + font-size:37px; + color:#2E2E2E; +} +#wrapper #div2 p +{ + font-size:18px; + color:#2E2E2E; +} +#wrapper #div2 li +{ + list-style-type:none; + margin-top:10px; +} +#wrapper #div2 li #firstname +{ + width:49%; +} +#wrapper #div2 li #surname +{ + margin-left:2%; + width:49%; +} +#wrapper #div2 li input[type="text"] +{ + width:100%; + height:40px; + border-radius:5px; + padding-left:10px; + font-size:18px; + border:1px solid #BDBDBD; +} +#wrapper #div2 li input[type="password"] +{ + width:100%; + height:40px; + border-radius:5px; + padding-left:10px; + font-size:18px; + border:1px solid #BDBDBD; +} +#wrapper #div2 li select +{ + padding:4px; + float:left; +} +#wrapper #div2 li a +{ + margin-left:10px; + width:150px; + color:#045FB4; + text-decoration:none; + font-size:11px; + display: inline-block; + vertical-align: middle; + line-height:15px; +} +#wrapper #div2 li a:hover +{ + text-decoration:underline; +} +#wrapper #div2 li +{ + color:#2E2E2E; + font-size:18px; +} +#wrapper #div2 #terms +{ + color:#424242; + font-size:11px; +} +#wrapper #div2 #terms a +{ + display:inline; + margin:0px; +} +#wrapper #div2 li input[type="submit"] +{ + width:205px; + height:45px; + text-align:center; + font-size:19px; + margin-top: 10px; + margin-bottom: 10px; + font-family: 'Freight Sans Bold', helvetica, arial, sans-serif !important; + font-weight: bold !important; + background: linear-gradient(#67ae55, #578843); + background-color: #69a74e; + box-shadow: inset 0 1px 1px #a4e388; + border-color: #3b6e22 #3b6e22 #2c5115; + border: 1px solid; + border-radius: 5px; + color: #fff; + cursor: pointer; + display: inline-block; + position: relative; + text-shadow: 0 1px 2px rgba(0,0,0,.5); +} +#wrapper #div2 #create_page +{ + color:#424242; + font-size:13px; + font-weight:bold; +} +#wrapper #div2 #create_page a +{ + display:inline; + margin:0px; + font-size:13px; +} +#footer_wrapper +{ + width:100%; + clear:both; + float:left; + margin-top:30px; + min-width:995px; + background-color:white; + text-align:left; +} +#footer1 +{ + width:980px; + margin:0px auto; + padding:0px; + border-bottom:1px solid #E6E6E6; + height:30px; + line-height:30px; + font-size:12px; + color:#848484; +} +#footer1 a +{ + color:#365899; + display:inline; + margin-left:10px; + text-decoration:none; +} +#footer1 a:hover +{ + text-decoration:underline; +} +#footer2 +{ + width:980px; + margin:0px auto; + padding:0px; + font-size:12px; + color:#848484; +} +#footer2 a +{ + color:#365899; + display:inline-block; + margin:5px; + margin-left:0px; + min-width:80px; + text-decoration:none; +} +#footer2 a:hover +{ + text-decoration:underline; +} \ No newline at end of file From 7412172a8d7ed18546c0876bc834705387639ab0 Mon Sep 17 00:00:00 2001 From: Joao Date: Mon, 13 Feb 2023 11:12:10 +0000 Subject: [PATCH 52/71] fixed tests --- stylesheets/style.css | 278 ------------------------------------------ 1 file changed, 278 deletions(-) delete mode 100644 stylesheets/style.css diff --git a/stylesheets/style.css b/stylesheets/style.css deleted file mode 100644 index 1fd8b996c..000000000 --- a/stylesheets/style.css +++ /dev/null @@ -1,278 +0,0 @@ -body -{ - text-align:center; - width:100%; - margin:0 auto; - padding:0px; - font-family:"lucida grande",tahoma,verdana,arial,sans-serif; - background: linear-gradient(white, #D3D8E8); -} -#header_wrapper -{ - width:100%; - min-width:980px; - background-color:#4c66a4; -} -#header -{ - width:980px; - margin:0px auto; - padding:0px; - height:85px; -} -#header li -{ - list-style-type:none; - float:left; - text-align:left; - color:white; -} -#header #sitename -{ - margin-top:25px; -} -#header #sitename a -{ - color:white; - text-decoration:none; - font-size:30px; - font-weight:900; -} -#header form -{ - margin-top:15px; - float:right; -} -#header form li -{ - font-size:13px; - margin-left:15px; -} -#header form li a -{ - color:#A9BCF5; - text-decoration:none; -} -#header form input[type="text"] -{ - margin-top:3px; - margin-bottom:3px; - width:150px; - border:1px solid #08298A; - height:25px; - padding-left:3px; -} -#header form input[type="password"] -{ - margin-top:3px; - margin-bottom:3px; - width:150px; - border:1px solid #08298A; - height:25px; - padding-left:3px; -} -#header form input[type="submit"] -{ - height:25px; - margin-top:20px; - background-color:#084B8A; - color:white; - border:1px solid #08298A; -} -#wrapper -{ - margin:0 auto; - padding:0px; - text-align:center; - width:980px; -} -#wrapper div -{ - float:left; - font-family: helvetica, arial, sans-serif; -} -#wrapper #div1 -{ - margin-top:30px; - width:590px; - text-align:left; -} -#wrapper #div1 p -{ - font-size:20px; - font-family:arial; - font-weight:bold; - margin:0px; - color:#0e385f; -} -#wrapper #div2 -{ - margin-top:10px; - width:390px; - text-align:left; -} -#wrapper #div2 h1 -{ - margin:0px; - font-size:37px; - color:#2E2E2E; -} -#wrapper #div2 p -{ - font-size:18px; - color:#2E2E2E; -} -#wrapper #div2 li -{ - list-style-type:none; - margin-top:10px; -} -#wrapper #div2 li #firstname -{ - width:49%; -} -#wrapper #div2 li #surname -{ - margin-left:2%; - width:49%; -} -#wrapper #div2 li input[type="text"] -{ - width:100%; - height:40px; - border-radius:5px; - padding-left:10px; - font-size:18px; - border:1px solid #BDBDBD; -} -#wrapper #div2 li input[type="password"] -{ - width:100%; - height:40px; - border-radius:5px; - padding-left:10px; - font-size:18px; - border:1px solid #BDBDBD; -} -#wrapper #div2 li select -{ - padding:4px; - float:left; -} -#wrapper #div2 li a -{ - margin-left:10px; - width:150px; - color:#045FB4; - text-decoration:none; - font-size:11px; - display: inline-block; - vertical-align: middle; - line-height:15px; -} -#wrapper #div2 li a:hover -{ - text-decoration:underline; -} -#wrapper #div2 li -{ - color:#2E2E2E; - font-size:18px; -} -#wrapper #div2 #terms -{ - color:#424242; - font-size:11px; -} -#wrapper #div2 #terms a -{ - display:inline; - margin:0px; -} -#wrapper #div2 li input[type="submit"] -{ - width:205px; - height:45px; - text-align:center; - font-size:19px; - margin-top: 10px; - margin-bottom: 10px; - font-family: 'Freight Sans Bold', helvetica, arial, sans-serif !important; - font-weight: bold !important; - background: linear-gradient(#67ae55, #578843); - background-color: #69a74e; - box-shadow: inset 0 1px 1px #a4e388; - border-color: #3b6e22 #3b6e22 #2c5115; - border: 1px solid; - border-radius: 5px; - color: #fff; - cursor: pointer; - display: inline-block; - position: relative; - text-shadow: 0 1px 2px rgba(0,0,0,.5); -} -#wrapper #div2 #create_page -{ - color:#424242; - font-size:13px; - font-weight:bold; -} -#wrapper #div2 #create_page a -{ - display:inline; - margin:0px; - font-size:13px; -} -#footer_wrapper -{ - width:100%; - clear:both; - float:left; - margin-top:30px; - min-width:995px; - background-color:white; - text-align:left; -} -#footer1 -{ - width:980px; - margin:0px auto; - padding:0px; - border-bottom:1px solid #E6E6E6; - height:30px; - line-height:30px; - font-size:12px; - color:#848484; -} -#footer1 a -{ - color:#365899; - display:inline; - margin-left:10px; - text-decoration:none; -} -#footer1 a:hover -{ - text-decoration:underline; -} -#footer2 -{ - width:980px; - margin:0px auto; - padding:0px; - font-size:12px; - color:#848484; -} -#footer2 a -{ - color:#365899; - display:inline-block; - margin:5px; - margin-left:0px; - min-width:80px; - text-decoration:none; -} -#footer2 a:hover -{ - text-decoration:underline; -} \ No newline at end of file From 71b0b297fecdf0962f568a8dd9915f6c60fecf44 Mon Sep 17 00:00:00 2001 From: Adam <110791742+TheMany172@users.noreply.github.com> Date: Mon, 13 Feb 2023 11:16:30 +0000 Subject: [PATCH 53/71] Update user_can_submit_posts_spec.js removed duplicate test --- .../integration/user_can_submit_posts_spec.js | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/cypress/integration/user_can_submit_posts_spec.js b/cypress/integration/user_can_submit_posts_spec.js index 939bc98e7..38de1d18d 100644 --- a/cypress/integration/user_can_submit_posts_spec.js +++ b/cypress/integration/user_can_submit_posts_spec.js @@ -92,32 +92,4 @@ describe("Timeline Posts", () => { cy.get('#new-post-form > [type="submit"]').click() cy.get('ul').should('contain.text',"Hello, world!"); }); - - it("cannot submit a post as just 'spaces'", () => { - // sign up - cy.task("wipe_database"); - cy.visit("/users/new"); - cy.get("#email").type("someone@example.com"); - cy.get("#password").type("password"); - cy.get("#submit").click(); - - // sign in - cy.visit("/sessions/new"); - cy.get("#email").type("someone@example.com"); - cy.get("#password").type("password"); - cy.get("#submit").click(); - - // DON'T submit a post, but press submit anyway - cy.visit("/posts"); - cy.contains("New post").click(); - cy.get("#new-post-form").submit(); - cy.url().should("include", "/posts/new"); - - // Submit a post with just spaces - this should not post - cy.visit("/posts"); - cy.contains("New post").click(); - cy.get("#new-post-form").find('[type="text"]').type(" "); - cy.get('#new-post-form > [type="submit"]').click() - cy.url().should("include", "/posts/new"); - }); }); From 2bc160be4758fdd373a3fe671579e3907c0e00d2 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 14:06:54 +0000 Subject: [PATCH 54/71] working username and profile pic --- controllers/posts.js | 20 +++++++++++++++++--- views/posts/index.hbs | 13 +++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index 636448120..de24efb49 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -1,5 +1,6 @@ const Post = require("../models/post"); const Comment = require("../models/comment"); +const User = require("../models/user"); const PostsController = { Index: (req, res) => { @@ -7,9 +8,22 @@ const PostsController = { if (err) { throw err; } - - res.render("posts/index", { posts: posts }); - }).sort({date:-1}); + console.log(posts); + }).sort({date:-1}).then((post) => { + let collection = []; + for(let i = 0; i < post.length; i++) { + User.findById(post[i].user_id, (err, user) => { + if (err) { + throw err; + } + let regex = /^\w*[^@]/g; + let username = user.email.match(regex); + collection.push({post: post[i], picture: user.picture, username: username}) + }); + } + console.log(collection); + res.render("posts/index", { collection: collection}); + }); }, New: (req, res) => { res.render("posts/new", {}); diff --git a/views/posts/index.hbs b/views/posts/index.hbs index 642c3aec5..784b5d147 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -1,14 +1,15 @@

              Timeline

              • - {{#each posts}} - User Profile -

                {{this.message}}

                -

                {{this.likes}} likes

                -
                + {{#each collection}} + + {{this.username}} +

                {{this.post.message}}

                +

                {{this.post.likes}} likes

                +
                - More details + More details

                =====================

                {{/each}}
              • From c3e6154531434b3415a794e0fca838f30c4f0880 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 14:58:16 +0000 Subject: [PATCH 55/71] working order profile pic and username --- controllers/posts.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index de24efb49..6221e281d 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -8,22 +8,27 @@ const PostsController = { if (err) { throw err; } - console.log(posts); }).sort({date:-1}).then((post) => { let collection = []; - for(let i = 0; i < post.length; i++) { - User.findById(post[i].user_id, (err, user) => { + async function post_set(post, i) { + await User.findById(post[i].user_id, (err, user) => { + console.log(i); if (err) { throw err; } let regex = /^\w*[^@]/g; let username = user.email.match(regex); - collection.push({post: post[i], picture: user.picture, username: username}) - }); + collection.push({post: post[i], picture: user.picture, username: username}); + }) + } + async function increment(post) { + for(let i = 0; i < post.length; i++) { + await post_set(post, i); } - console.log(collection); res.render("posts/index", { collection: collection}); - }); + } + increment(post); + }) }, New: (req, res) => { res.render("posts/new", {}); From 4c4dbf57b5b7d245280121568f80203a3d505678 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 15:23:32 +0000 Subject: [PATCH 56/71] navbar --- controllers/posts.js | 8 ++++---- controllers/users.js | 4 ++-- views/home/index.hbs | 2 ++ views/layout.hbs | 3 --- views/posts/details.hbs | 10 ++++++++++ views/posts/index.hbs | 14 +++++++++++--- views/posts/new.hbs | 10 ++++++++++ views/users/details.hbs | 10 ++++++++++ views/users/new.hbs | 10 ++++++++++ 9 files changed, 59 insertions(+), 12 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index 6221e281d..cad37c34a 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -4,7 +4,7 @@ const User = require("../models/user"); const PostsController = { Index: (req, res) => { - Post.find((err, posts) => { + Post.find((err) => { if (err) { throw err; } @@ -25,13 +25,13 @@ const PostsController = { for(let i = 0; i < post.length; i++) { await post_set(post, i); } - res.render("posts/index", { collection: collection}); + 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); @@ -99,7 +99,7 @@ const PostsController = { if (err) { throw err; } - res.render("posts/details", {comments: comments, post: post}); + res.render("posts/details", {comments: comments, post: post, session_user: req.session.user}); }).where({post_id: postId}) )); }, diff --git a/controllers/users.js b/controllers/users.js index 2b6e57c9b..5aa0a6b99 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -2,7 +2,7 @@ const User = require("../models/user"); const UsersController = { New: (req, res) => { - res.render("users/new", {error: req.session.error}); + res.render("users/new", {error: req.session.error, session_user: req.session.user}); }, Create: (req, res) => { @@ -41,7 +41,7 @@ const UsersController = { } user.friends = user.friends.filter(object => object.status === "pending"); - res.render("users/details", {user: user}); + res.render("users/details", {user: user, session_user: req.session.user}); }); }, diff --git a/views/home/index.hbs b/views/home/index.hbs index 7ad30d847..fc1acc8ed 100644 --- a/views/home/index.hbs +++ b/views/home/index.hbs @@ -1,2 +1,4 @@

                {{title}}

                Welcome to {{title}}

                + +Log In \ No newline at end of file diff --git a/views/layout.hbs b/views/layout.hbs index 17645b71e..068eb6bee 100644 --- a/views/layout.hbs +++ b/views/layout.hbs @@ -5,9 +5,6 @@ -
                - -
                {{{body}}} diff --git a/views/posts/details.hbs b/views/posts/details.hbs index c218b9c67..6acf5aa5c 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -1,3 +1,13 @@ + +

                Post

                User diff --git a/views/posts/index.hbs b/views/posts/index.hbs index 784b5d147..3183bdf1c 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -1,3 +1,13 @@ + +

                Timeline

                • @@ -13,6 +23,4 @@

                  =====================

                  {{/each}}
                • -
                - -New post \ No newline at end of file +
              \ No newline at end of file diff --git a/views/posts/new.hbs b/views/posts/new.hbs index a71bc74bd..fb5b112d4 100644 --- a/views/posts/new.hbs +++ b/views/posts/new.hbs @@ -1,3 +1,13 @@ + +
              diff --git a/views/users/details.hbs b/views/users/details.hbs index a4a0ae86f..6de5c2c09 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -1,3 +1,13 @@ +
              +
              diff --git a/views/users/new.hbs b/views/users/new.hbs index 01ed72a99..4e19d4011 100644 --- a/views/users/new.hbs +++ b/views/users/new.hbs @@ -1,3 +1,13 @@ + +
              From 70dd0b31c6b1be95bddc66e7a5667cafb6f5dcd6 Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 13 Feb 2023 15:29:11 +0000 Subject: [PATCH 57/71] console log gone --- controllers/posts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/controllers/posts.js b/controllers/posts.js index cad37c34a..b696f8c70 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -12,7 +12,6 @@ const PostsController = { let collection = []; async function post_set(post, i) { await User.findById(post[i].user_id, (err, user) => { - console.log(i); if (err) { throw err; } From 8c56dfc8e90cc2a1c1e01d47ab963aa4574a52b2 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 15:53:42 +0000 Subject: [PATCH 58/71] rejigged img src --- app.js | 2 +- controllers/users.js | 3 +-- views/posts/details.hbs | 2 +- views/posts/index.hbs | 4 ++-- views/posts/new.hbs | 2 +- views/users/details.hbs | 2 +- views/users/new.hbs | 10 ---------- 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app.js b/app.js index a97fdad64..bb2057955 100644 --- a/app.js +++ b/app.js @@ -31,7 +31,7 @@ app.use( resave: false, saveUninitialized: false, cookie: { - expires: 60000000, + expires: 600000, }, }) ); diff --git a/controllers/users.js b/controllers/users.js index 5aa0a6b99..4e1e4f6a2 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -30,7 +30,6 @@ const UsersController = { Details: (req, res) => { const userId = req.params.id; const sessionId = req.session.user._id; - User.findById(userId, (err, user) => { if (err) { throw err; @@ -40,7 +39,7 @@ const UsersController = { user.friends = []; } user.friends = user.friends.filter(object => object.status === "pending"); - + res.render("users/details", {user: user, session_user: req.session.user}); }); }, diff --git a/views/posts/details.hbs b/views/posts/details.hbs index 6acf5aa5c..29f655f0a 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -2,7 +2,7 @@
            • -
            • +
            • User Page
            • New post
            • Home
            • diff --git a/views/posts/index.hbs b/views/posts/index.hbs index 3183bdf1c..d7fa3d638 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -2,7 +2,7 @@
            • -
            • +
            • User Page
            • New post
            • Home
            • @@ -12,7 +12,7 @@
              • {{#each collection}} - + {{this.username}}

                {{this.post.message}}

                {{this.post.likes}} likes

                diff --git a/views/posts/new.hbs b/views/posts/new.hbs index fb5b112d4..73917e782 100644 --- a/views/posts/new.hbs +++ b/views/posts/new.hbs @@ -2,7 +2,7 @@
              • -
              • +
              • User Page
              • New post
              • Home
              • diff --git a/views/users/details.hbs b/views/users/details.hbs index 6de5c2c09..9e43aff36 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -2,7 +2,7 @@
              • -
              • +
              • User Page
              • New post
              • Home
              • diff --git a/views/users/new.hbs b/views/users/new.hbs index 4e19d4011..01ed72a99 100644 --- a/views/users/new.hbs +++ b/views/users/new.hbs @@ -1,13 +1,3 @@ - -
                From 7cce83669639f29f47144905334db21607d0245f Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 15:59:01 +0000 Subject: [PATCH 59/71] fixed issue --- views/users/details.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/views/users/details.hbs b/views/users/details.hbs index 9e43aff36..011c03f93 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -8,7 +8,7 @@
              • Home
              - + @@ -18,7 +18,7 @@ - +

              Your friend requests

                From 4b5b5e5e3c0150125dfe6b4c53ae44bd75453292 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 16:21:19 +0000 Subject: [PATCH 60/71] pics all in order --- controllers/posts.js | 3 ++- controllers/users.js | 4 ++-- models/user.js | 2 +- views/posts/details.hbs | 2 +- views/posts/index.hbs | 4 ++-- views/posts/new.hbs | 2 +- views/users/details.hbs | 4 ++-- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index cad37c34a..64c06bdf1 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -9,10 +9,11 @@ const PostsController = { throw err; } }).sort({date:-1}).then((post) => { + console.log(post); let collection = []; async function post_set(post, i) { await User.findById(post[i].user_id, (err, user) => { - console.log(i); + console.log(user); if (err) { throw err; } diff --git a/controllers/users.js b/controllers/users.js index 4e1e4f6a2..c4e905ca0 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -39,7 +39,7 @@ const UsersController = { user.friends = []; } user.friends = user.friends.filter(object => object.status === "pending"); - + res.render("users/details", {user: user, session_user: req.session.user}); }); }, @@ -101,7 +101,7 @@ const UsersController = { if (err) { throw err; } - + req.session.user = user; res.status(201).redirect(`/users/${hostId}`); }); } else { diff --git a/models/user.js b/models/user.js index f8e99b4b0..3fe992e71 100644 --- a/models/user.js +++ b/models/user.js @@ -4,7 +4,7 @@ const UserSchema = new mongoose.Schema({ email: String, password: String, friends: Array, - picture: String, + picture: {type: String, default: "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png"}, }); const User = mongoose.model("User", UserSchema); diff --git a/views/posts/details.hbs b/views/posts/details.hbs index 29f655f0a..c00ae6b24 100644 --- a/views/posts/details.hbs +++ b/views/posts/details.hbs @@ -2,7 +2,7 @@
              • -
              • +
              • User Page
              • New post
              • Home
              • diff --git a/views/posts/index.hbs b/views/posts/index.hbs index d7fa3d638..daef15171 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -2,7 +2,7 @@
              • -
              • +
              • User Page
              • New post
              • Home
              • @@ -12,7 +12,7 @@
                • {{#each collection}} - + {{this.username}}

                  {{this.post.message}}

                  {{this.post.likes}} likes

                  diff --git a/views/posts/new.hbs b/views/posts/new.hbs index 73917e782..3e088fd0a 100644 --- a/views/posts/new.hbs +++ b/views/posts/new.hbs @@ -2,7 +2,7 @@
                • -
                • +
                • User Page
                • New post
                • Home
                • diff --git a/views/users/details.hbs b/views/users/details.hbs index 011c03f93..eacfc8f8e 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -2,7 +2,7 @@
                • -
                • +
                • User Page
                • New post
                • Home
                • @@ -18,7 +18,7 @@ - +

                  Your friend requests

                    From fb52e90cf3ee8c7f244d868f315b22c915f23618 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 16:24:45 +0000 Subject: [PATCH 61/71] removed redundant code --- controllers/posts.js | 2 -- controllers/users.js | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/controllers/posts.js b/controllers/posts.js index 64c06bdf1..b696f8c70 100644 --- a/controllers/posts.js +++ b/controllers/posts.js @@ -9,11 +9,9 @@ const PostsController = { throw err; } }).sort({date:-1}).then((post) => { - console.log(post); let collection = []; async function post_set(post, i) { await User.findById(post[i].user_id, (err, user) => { - console.log(user); if (err) { throw err; } diff --git a/controllers/users.js b/controllers/users.js index c4e905ca0..2588f8cca 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -69,11 +69,10 @@ const UsersController = { const theirId = req.params.id; const hostId = req.session.user._id; - User.findOneAndUpdate({"_id": hostId, "friends.user_id": theirId}, {"$set": {"friends.$.status": "confirmed"}}, (err, user) => { + User.findOneAndUpdate({"_id": hostId, "friends.user_id": theirId}, {"$set": {"friends.$.status": "confirmed"}}, (err) => { if (err) { throw err; } - console.log(user); res.status(201).redirect(`/users/${hostId}`); }); }, @@ -82,11 +81,10 @@ const UsersController = { const theirId = req.params.id; const hostId = req.session.user._id; - User.findOneAndUpdate({"_id": hostId, "friends.user_id": theirId}, {"$set": {"friends.$.status": "denied"}}, (err, user) => { + User.findOneAndUpdate({"_id": hostId, "friends.user_id": theirId}, {"$set": {"friends.$.status": "denied"}}, (err) => { if (err) { throw err; } - console.log(user); res.status(201).redirect(`/users/${hostId}`); }); }, From 3bcc9186575690f56e65297ad71167f5fc66c8a8 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 16:44:30 +0000 Subject: [PATCH 62/71] cant add self as friend, button remains --- controllers/users.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index 2588f8cca..39080025c 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -52,14 +52,17 @@ const UsersController = { if (err) { throw err; } - if (user.friends.filter(object => object.user_id === currentId).length === 0) { - user.friends.push({user_id: `${currentId}`, status: "pending"}) - - user.save((err) => { - if (err) { - throw err; - } - }); + if (targetId != currentId) + { + if (user.friends.filter(object => object.user_id === currentId).length === 0) { + user.friends.push({user_id: `${currentId}`, status: "pending"}) + + user.save((err) => { + if (err) { + throw err; + } + }); + } } res.status(201).redirect(`/users/${targetId}`); }); From 42edca4fa1a039a3f530aab498b672e973d96979 Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 17:06:47 +0000 Subject: [PATCH 63/71] adding pictures to posts --- models/post.js | 1 + views/posts/index.hbs | 1 + views/posts/new.hbs | 2 ++ views/users/details.hbs | 2 +- 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/models/post.js b/models/post.js index 5cf0b1aff..e10426c8d 100644 --- a/models/post.js +++ b/models/post.js @@ -6,6 +6,7 @@ const PostSchema = new mongoose.Schema({ liked_by: [], date: Date, user_id: String, + picture: { type: String, default: "none" }, }); const Post = mongoose.model("Post", PostSchema); diff --git a/views/posts/index.hbs b/views/posts/index.hbs index daef15171..d7e1e62b8 100644 --- a/views/posts/index.hbs +++ b/views/posts/index.hbs @@ -15,6 +15,7 @@ {{this.username}}

                    {{this.post.message}}

                    +

                    {{this.post.likes}} likes

                    diff --git a/views/posts/new.hbs b/views/posts/new.hbs index 3e088fd0a..7b47b6cc6 100644 --- a/views/posts/new.hbs +++ b/views/posts/new.hbs @@ -11,5 +11,7 @@ + +
                    diff --git a/views/users/details.hbs b/views/users/details.hbs index eacfc8f8e..ea7a990e8 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -18,7 +18,7 @@ - +

                    Your friend requests

                      From 20f83059d5e9dc4622223aca3e59b78b2e3e724f Mon Sep 17 00:00:00 2001 From: PDyson1400 Date: Mon, 13 Feb 2023 17:09:29 +0000 Subject: [PATCH 64/71] your -> incoming friends requests --- views/users/details.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/users/details.hbs b/views/users/details.hbs index ea7a990e8..70ef49c78 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -20,7 +20,7 @@ -

                      Your friend requests

                      +

                      Incoming friend requests

                        {{#each user.friends}}
                      • {{this.user_id}}
                      • From bab8d9345e13ddc5838bec2f3f60afaf8c81153f Mon Sep 17 00:00:00 2001 From: Cristiano Silva Date: Tue, 14 Feb 2023 09:10:47 +0000 Subject: [PATCH 65/71] test --- controllers/users.js | 19 ++++++++++++------- views/users/details.hbs | 10 +++++++--- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/controllers/users.js b/controllers/users.js index 2588f8cca..c12b0bc6e 100644 --- a/controllers/users.js +++ b/controllers/users.js @@ -30,17 +30,22 @@ const UsersController = { Details: (req, res) => { const userId = req.params.id; const sessionId = req.session.user._id; + User.findById(userId, (err, user) => { if (err) { throw err; } - - if(userId != sessionId) { - user.friends = []; - } - user.friends = user.friends.filter(object => object.status === "pending"); - - res.render("users/details", {user: user, session_user: req.session.user}); + + const isSessionUser = userId !== sessionId; + console.log(isSessionUser); + + user.friends = user.friends.filter(friend => friend.status === "pending"); + + res.render("users/details", { + user: user, + session_user: req.session.user, + is_session_user: isSessionUser + }); }); }, diff --git a/views/users/details.hbs b/views/users/details.hbs index eacfc8f8e..e8e32bf25 100644 --- a/views/users/details.hbs +++ b/views/users/details.hbs @@ -8,9 +8,13 @@
                      • Home
                      -
                      - -
                      +{{#unless is_session_user}} +
                    • +
                      + +
                      +
                    • +{{/unless}}
                    -{{#unless is_session_user}} +{{#if is_session_user}}
                  • -{{/unless}} +{{/if}}