From 009939513fd6af13ef7bfea5733c1b460731e89f Mon Sep 17 00:00:00 2001
From: shivam7374
Date: Fri, 29 May 2020 21:33:59 +0530
Subject: [PATCH 1/9] Add
---
package-lock.json | 47 +++++++++++++++++++++-------
package.json | 16 ++++++++--
src/public/app/write-post.js | 15 ++++-----
src/public/components/all-posts.html | 2 +-
src/public/components/my-posts.html | 2 +-
src/server.js | 4 +--
6 files changed, 61 insertions(+), 25 deletions(-)
diff --git a/package-lock.json b/package-lock.json
index 8d33ccf..02f37f1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -317,9 +317,9 @@
"dev": true
},
"@types/node": {
- "version": "13.13.5",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.5.tgz",
- "integrity": "sha512-3ySmiBYJPqgjiHA7oEaIo2Rzz0HrOZ7yrNO5HWyaE5q0lQ3BppDZ3N53Miz8bw2I7gh1/zir2MGVZBvpb1zq9g=="
+ "version": "14.0.5",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.5.tgz",
+ "integrity": "sha512-90hiq6/VqtQgX8Sp0EzeIsv3r+ellbGj4URKj5j30tLlZvRUpnAe9YbYnjl3pJM93GyXU0tghHhvXHq+5rnCKA=="
},
"abbrev": {
"version": "1.1.1",
@@ -439,6 +439,11 @@
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
+ "bignumber.js": {
+ "version": "9.0.0",
+ "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz",
+ "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A=="
+ },
"binary-extensions": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.0.0.tgz",
@@ -1706,14 +1711,14 @@
}
},
"moment": {
- "version": "2.25.3",
- "resolved": "https://registry.npmjs.org/moment/-/moment-2.25.3.tgz",
- "integrity": "sha512-PuYv0PHxZvzc15Sp8ybUCoQ+xpyPWvjOuK72a5ovzp2LI32rJXOiIfyoFoYvG3s6EwwrdkMyWuRiEHSZRLJNdg=="
+ "version": "2.26.0",
+ "resolved": "https://registry.npmjs.org/moment/-/moment-2.26.0.tgz",
+ "integrity": "sha512-oIixUO+OamkUkwjhAVE18rAMfRJNsNe/Stid/gwHSOfHrOtw9EhAY2AHvdKZ/k/MggcYELFCJz/Sn2pL8b8JMw=="
},
"moment-timezone": {
- "version": "0.5.28",
- "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.28.tgz",
- "integrity": "sha512-TDJkZvAyKIVWg5EtVqRzU97w0Rb0YVbfpqyjgu6GwXCAohVRqwZjf4fOzDE6p1Ch98Sro/8hQQi65WDXW5STPw==",
+ "version": "0.5.31",
+ "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.31.tgz",
+ "integrity": "sha512-+GgHNg8xRhMXfEbv81iDtrVeTcWt0kWmTEY1XQK14dICTXnWJnT0dxdlPspwqF3keKMVPXwayEsk1DI0AA/jdA==",
"requires": {
"moment": ">= 2.9.0"
}
@@ -1723,6 +1728,24 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
+ "mysql": {
+ "version": "2.18.1",
+ "resolved": "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz",
+ "integrity": "sha512-Bca+gk2YWmqp2Uf6k5NFEurwY/0td0cpebAucFpY/3jhrwrVGuxU2uQFCHjU19SJfje0yQvi+rVWdq78hR5lig==",
+ "requires": {
+ "bignumber.js": "9.0.0",
+ "readable-stream": "2.3.7",
+ "safe-buffer": "5.1.2",
+ "sqlstring": "2.3.1"
+ },
+ "dependencies": {
+ "sqlstring": {
+ "version": "2.3.1",
+ "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
+ "integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A="
+ }
+ }
+ },
"mysql2": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/mysql2/-/mysql2-2.1.0.tgz",
@@ -2511,9 +2534,9 @@
"integrity": "sha1-1WgS4cAXpuTnw+Ojeh2m143TyT4="
},
"sequelize": {
- "version": "5.21.7",
- "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.7.tgz",
- "integrity": "sha512-+JrS5Co7CN53cOFFFaUb+xqQP00wD1Ag9xGLBLoUko2KhRZxjm+UDkqAVPHTUp87McLwJaCPkKv61GPhBVloRQ==",
+ "version": "5.21.11",
+ "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.21.11.tgz",
+ "integrity": "sha512-ZJw3Hp+NS7iHcTz4fHlKvIBm4I7xYibYRCP4HhSyMB26xgqFYFOXTaeWbHD2UUwAFaksTLw5ntzfpA9kE33SVA==",
"requires": {
"bluebird": "^3.5.0",
"cls-bluebird": "^2.1.0",
diff --git a/package.json b/package.json
index 9ad48f4..3a7fc88 100644
--- a/package.json
+++ b/package.json
@@ -12,8 +12,9 @@
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
+ "mysql": "^2.18.1",
"mysql2": "^2.1.0",
- "sequelize": "^5.21.7",
+ "sequelize": "^5.21.11",
"sqlite3": "^4.2.0"
},
"devDependencies": {
@@ -21,5 +22,16 @@
"chai-as-promised": "^7.1.1",
"mocha": "^7.2.0",
"nyc": "^15.0.1"
- }
+ },
+ "directories": {
+ "test": "test"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/shivam7374/Social_Media_Sample_Project_2020_May.git"
+ },
+ "bugs": {
+ "url": "https://github.com/shivam7374/Social_Media_Sample_Project_2020_May/issues"
+ },
+ "homepage": "https://github.com/shivam7374/Social_Media_Sample_Project_2020_May#readme"
}
diff --git a/src/public/app/write-post.js b/src/public/app/write-post.js
index e92aa9c..efd355e 100644
--- a/src/public/app/write-post.js
+++ b/src/public/app/write-post.js
@@ -1,11 +1,12 @@
-$('#write-btn').click(() => {
+$("#write-btn").click(() => {
const userId = JSON.parse(window.localStorage.user).id
- const title = $('#p-title').val()
- const body = $('#p-body').val()
+ const title = $("#p-title").val()
+ const body = $("#p-body").val()
- $.post('/api/posts', { userId, title, body }, (data) => {
- $('#content').load('/components/my-posts.html')
- $('.nav-item .active').removeClass('active')
- $("[data-components='my-posts']").addClass('active')
+ $.post("/api/posts", { userId, title, body }, async (data) => {
+ console.log(data)
+ await $("#content").load("/components/my-posts.html")
+ await $(".nav-item .active").removeClass("active")
+ await $("[data-components='my-posts']").addClass("active")
})
})
diff --git a/src/public/components/all-posts.html b/src/public/components/all-posts.html
index 242a75f..0d9209d 100644
--- a/src/public/components/all-posts.html
+++ b/src/public/components/all-posts.html
@@ -5,7 +5,7 @@ Recent Posts
-
+
\ No newline at end of file
diff --git a/src/public/components/my-posts.html b/src/public/components/my-posts.html
index 127bc0b..5657e12 100644
--- a/src/public/components/my-posts.html
+++ b/src/public/components/my-posts.html
@@ -5,7 +5,7 @@ Recent Posts
-
+
\ No newline at end of file
diff --git a/src/server.js b/src/server.js
index 5d06647..1fddf91 100644
--- a/src/server.js
+++ b/src/server.js
@@ -14,8 +14,8 @@ app.use('/', express.static(__dirname + '/public'))
db.sync()
.then(() => {
- app.listen(8383, () => {
- console.log('server started on http://localhost:8383')
+ app.listen(8384, () => {
+ console.log('server started on http://localhost:8384')
})
})
.catch((err) => {
From b72e163396cfc66bf8df4d31460ccbbabcdbd2e4 Mon Sep 17 00:00:00 2001
From: shivam7374
Date: Fri, 29 May 2020 22:42:27 +0530
Subject: [PATCH 2/9] Add
---
src/controllers/comments.js | 30 ++++++++++++
src/public/app/all-posts.js | 2 +-
src/public/app/comment.js | 52 +++++++++++++++++++++
src/public/app/my-posts.js | 2 +-
src/public/app/write-post.js | 2 +-
src/public/components/comment.html | 73 ++++++++++++++++++++++++++++++
src/routes/posts/comments.js | 34 +++++++++++++-
src/server.js | 7 ++-
8 files changed, 195 insertions(+), 7 deletions(-)
create mode 100644 src/public/app/comment.js
create mode 100644 src/public/components/comment.html
diff --git a/src/controllers/comments.js b/src/controllers/comments.js
index e69de29..4c917ac 100644
--- a/src/controllers/comments.js
+++ b/src/controllers/comments.js
@@ -0,0 +1,30 @@
+
+const { Posts, Comments } = require('../db/models')
+
+async function createNewComment(postId, title, body) {
+ const comment = await Comments.create({
+ title,
+ body,
+ postId,
+ })
+
+ return comment
+}
+
+async function findAllCommentsbyPosts(id) {
+ // TODO: Handle query params
+ const posts = await Posts.findAll( {
+ where:{
+ id
+ }, include: [ Comments ]
+ }
+ )
+
+ return posts
+ }
+
+ module.exports = {
+ createNewComment,
+ findAllCommentsbyPosts
+ }
+
\ No newline at end of file
diff --git a/src/public/app/all-posts.js b/src/public/app/all-posts.js
index 04aa02d..665e383 100644
--- a/src/public/app/all-posts.js
+++ b/src/public/app/all-posts.js
@@ -12,7 +12,7 @@ function loadPosts() {
${p.body.substr(0, 200)}
...read more
- Comment
+ Comment
Like
diff --git a/src/public/app/comment.js b/src/public/app/comment.js
new file mode 100644
index 0000000..0bd0f7c
--- /dev/null
+++ b/src/public/app/comment.js
@@ -0,0 +1,52 @@
+function loadPostsComments() {
+ let start, end
+ start = (document.URL.search("comments/") + 9)
+ end = document.URL.search("/endpoint")
+ let id = parseInt(document.URL.slice(start, end))
+ $.get('http://localhost:8483/api/posts/comments/' + id, (post) => {
+ console.log("++++++++++++++++++")
+ console.log(post)
+ console.log("++++++++++++++++++")// working till here
+ {
+ $('#posts-container').append(
+ $(`
+
+
+
+
${post[0].title}
+
${post[0].title}
+
+ ${post[0].body}
+ ...read more
+
+
Like
+
+
+
+ COMMENTS
+
+ `)
+ )
+ }
+ for (let p of post[0].comments) {
+ $('#posts-container').append(
+ $(`
+
+
+
+
+
+
+ `)
+ )
+ }
+ })
+ }
\ No newline at end of file
diff --git a/src/public/app/my-posts.js b/src/public/app/my-posts.js
index 9708598..309c445 100644
--- a/src/public/app/my-posts.js
+++ b/src/public/app/my-posts.js
@@ -14,7 +14,7 @@ function loadMyPosts() {
${p.body.substr(0, 200)}
...read more
- Comment
+ Comment
Like
diff --git a/src/public/app/write-post.js b/src/public/app/write-post.js
index efd355e..ce49ecc 100644
--- a/src/public/app/write-post.js
+++ b/src/public/app/write-post.js
@@ -4,7 +4,7 @@ $("#write-btn").click(() => {
const body = $("#p-body").val()
$.post("/api/posts", { userId, title, body }, async (data) => {
- console.log(data)
+ // console.log(data)
await $("#content").load("/components/my-posts.html")
await $(".nav-item .active").removeClass("active")
await $("[data-components='my-posts']").addClass("active")
diff --git a/src/public/components/comment.html b/src/public/components/comment.html
new file mode 100644
index 0000000..86cb5bd
--- /dev/null
+++ b/src/public/components/comment.html
@@ -0,0 +1,73 @@
+
+
+
+
+
+ Document
+
+
+
+
+ MockSocial
+
+
+
+
+
+
+
+
+
+
+
Post With Comments
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/routes/posts/comments.js b/src/routes/posts/comments.js
index 632f4c2..1c487f5 100644
--- a/src/routes/posts/comments.js
+++ b/src/routes/posts/comments.js
@@ -1,7 +1,37 @@
const { Router } = require('express')
+const {
+ createNewComment,findAllCommentsbyPosts
+} = require('../../controllers/comments')
+const path=require('path')
-const commentsRoute = Router()
+
+const route = Router()
+
+route.get('/:id', async (req, res) => {
+ const posts = await findAllCommentsbyPosts(req.params.id)
+ res.status(200).send(posts)
+})
+
+route.post('/', async (req, res) => {
+ // console.log("************")
+ // console.log(req.body)
+ // console.log("************")
+ const { postId, title, body } = req.body
+
+ if ((!postId) || (!title) || (!body)) {
+ return res.status(400).send({
+ error: 'Need postId, title and body to create post'
+ })
+ }
+
+ const post = await createNewComment(postId, title, body)
+ res.status(201).send(post)
+})
+route.get('/:id/endpoint', async (req,res)=>{
+ res.sendFile(path.join(__dirname,'../../public/components','comment.html'))
+ // /media/singla/New Volume/Github Projects/Mock-Message-Site/Social-Media-Project/src
+})
module.exports = {
- commentsRoute
+ commentsRoute:route
}
\ No newline at end of file
diff --git a/src/server.js b/src/server.js
index 1fddf91..b91617e 100644
--- a/src/server.js
+++ b/src/server.js
@@ -3,6 +3,8 @@ const express = require('express')
const { db } = require('./db/models')
const { usersRoute } = require('./routes/users')
const { postsRoute } = require('./routes/posts')
+const { commentsRoute } = require('./routes/posts/comments.js')
+
const app = express()
app.use(express.json())
@@ -10,12 +12,13 @@ app.use(express.urlencoded({extended: true}))
app.use('/api/users', usersRoute)
app.use('/api/posts', postsRoute)
+app.use('/api/posts/comments', commentsRoute)
app.use('/', express.static(__dirname + '/public'))
db.sync()
.then(() => {
- app.listen(8384, () => {
- console.log('server started on http://localhost:8384')
+ app.listen(8483, () => {
+ console.log('server started on http://localhost:8483')
})
})
.catch((err) => {
From 22bda9f5d9a543db9cee6a1b28f91d4ecf573d9d Mon Sep 17 00:00:00 2001
From: shivam7374
Date: Fri, 29 May 2020 23:06:51 +0530
Subject: [PATCH 3/9] Add
---
src/db/models.js | 2 +-
src/db/testing.db | Bin 0 -> 24576 bytes
test/controllers/comments.test.js | 0
test/controllers/posts.test.js | 0
4 files changed, 1 insertion(+), 1 deletion(-)
create mode 100644 src/db/testing.db
create mode 100644 test/controllers/comments.test.js
create mode 100644 test/controllers/posts.test.js
diff --git a/src/db/models.js b/src/db/models.js
index dd5870c..222fc86 100644
--- a/src/db/models.js
+++ b/src/db/models.js
@@ -4,7 +4,7 @@ let db
if (process.env.NODE_ENV == 'testing') {
db = new Sequelize({
dialect: 'sqlite',
- storage: ':memory:',
+ storage: __dirname + "/testing.db",
})
} else {
db = new Sequelize({
diff --git a/src/db/testing.db b/src/db/testing.db
new file mode 100644
index 0000000000000000000000000000000000000000..143caaaca2ebf0e048aeaf9a02f310e1452504dd
GIT binary patch
literal 24576
zcmeI(-)_=S90%~z@n@S6JFn`^l5=B1!&nMqAtNzb;i!#JSSd!XDA2Qn1n5Rf)Jusz
zi4Wi#_y#_JFX83lrKcSzERksRVv_Gk|Nq+4^ZWFq$$_+aS{($Oo_Ui|H=svkk4O@E
zL@6O8F6N||7bPY(!efgfEjHGy_5pQ*K``VFeW6?BXS$Wn6*QHab(@;4YE^`Lp8Lk3
zHhUSK+n?}mz+F9XXhq!CHfn77-08WyHth3>vD7MyJz*9z%dAPAsfhXWW~;Pr(h93G
zkyw*mwIn>$YJ@kXWxZL}D@-)!-1CE9RT#$ptU`5mFTSlPiu6v7tfLyDMPgNXx$1vQ
zyo`C1tkp&=sbn%zJA&~qhGHn&@%hD+kNf=EZhQsnS};BCj`)GNQhi&JBJ5c+sxx~2
z(PC@m`jw9HTi9VG;az@q>7%6{O?vVR_
zw&%SX=C!<*)sD0I6PhcQ^2Ji2cvv_-p&3mpX(F~RdQ0Rb$zO?>P#^#S2tWV=5P$##
zAOHafKmY;|*a(5UF?DzKw}Y$y|1XJrxe*B>2?#&{0uX=z1Rwwb2tWV=5P$##ehBPH
zF=aRU5Fi}?i;w
Date: Sat, 30 May 2020 12:00:04 +0530
Subject: [PATCH 4/9] Tests complete
---
src/db/testing.db | Bin 24576 -> 36864 bytes
test/controllers/comments.test.js | 28 +++++++++++++++++++
test/controllers/posts.test.js | 44 ++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/src/db/testing.db b/src/db/testing.db
index 143caaaca2ebf0e048aeaf9a02f310e1452504dd..611dcc0902af0943c40b061592958b328763e3a9 100644
GIT binary patch
literal 36864
zcmeHQTWlOx8J_j*dUtK_j&pT-Niu2TBpb(*x$cdojpJR!FEws1#9DQ8^ZtEGG4B3jM*EkN=qo5%zxHbOXPNK7zw#p$kP1izqyka_sen{K
zDj*e*3Vd=Dcw#w`9N4`(_Qk=Cg$pb7i;XK+>Z=>g*5B^Y>B`7#MV}oxIablSrov^^v*R$?60gH(r^TJ*v-dEN`sT=k@zXrbq7`
znLcc}W=@}&oYg1h#>N1?&{%wAUZ1Ue8t;2?y}qzfUmV$(*H6J|XRG6t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/test/controllers/comments.test.js
index e69de29..920d90a 100644
--- a/test/controllers/comments.test.js
+++ b/test/controllers/comments.test.js
@@ -0,0 +1,28 @@
+const { expect } = require('chai')
+const {
+ createNewComment,
+ findAllCommentsbyPosts
+} = require('../../src/controllers/comments')
+
+describe('controllers/comments',()=>{
+ let testingComment = null
+
+ it('should create comment with postId, title and body assigned', async ()=>{
+ testingComment = await createNewComment(1, 'Ultimate Coder', 'Arnav Bhaiya')
+ expect(testingComment).to.have.property('title')
+ expect(testingComment).to.have.property('postId')
+ expect(testingComment).to.have.property('body')
+ expect(testingComment.id).to.be.a('number')
+ expect(testingComment.postId).to.be.a('number')
+ expect(testingComment.title).to.be.a('string')
+ expect(testingComment.body).to.be.a('string')
+ expect(testingComment.postId).to.equal(1)
+ expect(testingComment.title).to.equal('Ultimate Coder')
+ expect(testingComment.body).to.equal('Arnav Bhaiya')
+ } )
+ it('should find all commments by postId', async ()=>{
+ let where ={postId:1}
+ let allComments = await findAllCommentsbyPosts(where.postId)
+ expect(allComments).to.be.an("array")
+ })
+})
\ No newline at end of file
diff --git a/test/controllers/posts.test.js b/test/controllers/posts.test.js
index e69de29..b982e9c 100644
--- a/test/controllers/posts.test.js
+++ b/test/controllers/posts.test.js
@@ -0,0 +1,44 @@
+const {expect}=require('chai')
+const {
+ createNewPost,
+ findAllPosts
+}=require('../../src/controllers/posts')
+
+describe('controllers/posts', ()=>{
+ let testingPost = null
+
+ it('should create post with userId, title and body assigned', async ()=>{
+ testingPost = await createNewPost(1, 'Ultimate Coder', 'Arnav Bhaiya')
+ expect(testingPost).to.have.property('title')
+ expect(testingPost).to.have.property('userId')
+ expect(testingPost).to.have.property('body')
+ expect(testingPost.id).to.be.a('number')
+ expect(testingPost.userId).to.be.a('number')
+ expect(testingPost.title).to.be.a('string')
+ expect(testingPost.body).to.be.a('string')
+ expect(testingPost.userId).to.equal(1)
+ expect(testingPost.title).to.equal('Ultimate Coder')
+ expect(testingPost.body).to.equal('Arnav Bhaiya')
+ } )
+
+ it('should find all posts', async ()=>{
+ let where ={}
+ let allPosts = await findAllPosts(where)
+ expect(allPosts).to.be.an("array")
+ })
+
+ it('should find all posts of a user by its userid', async ()=>{
+ let where ={
+ userId: testingPost.userId
+ }
+ let allPosts = await findAllPosts(where.userId)
+ let postsarr = []
+ for(let p of allPosts){
+ postsarr.push(p)
+ }
+ let len=postsarr.length
+ expect(postsarr[len-1].userId).to.equal(testingPost.userId)
+ expect(postsarr[len-1].title).to.equal(testingPost.title)
+ expect(postsarr[len-1].body).to.equal(testingPost.body)
+ })
+})
\ No newline at end of file
From 35a64902d0e8186a80ef568bee256d8e7eb3d5e2 Mon Sep 17 00:00:00 2001
From: shivam7374
Date: Sat, 30 May 2020 12:07:45 +0530
Subject: [PATCH 5/9] DB as memory
---
src/db/models.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/db/models.js b/src/db/models.js
index 222fc86..dd5870c 100644
--- a/src/db/models.js
+++ b/src/db/models.js
@@ -4,7 +4,7 @@ let db
if (process.env.NODE_ENV == 'testing') {
db = new Sequelize({
dialect: 'sqlite',
- storage: __dirname + "/testing.db",
+ storage: ':memory:',
})
} else {
db = new Sequelize({
From 08d5c1843522f6dacf40df36f85f51075560b63b Mon Sep 17 00:00:00 2001
From: shivam7374
Date: Sat, 30 May 2020 12:21:41 +0530
Subject: [PATCH 6/9] Add
---
src/db/models.js | 2 +-
src/db/testing.db | Bin 36864 -> 36864 bytes
terminal-test-run.txt | 188 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 189 insertions(+), 1 deletion(-)
create mode 100644 terminal-test-run.txt
diff --git a/src/db/models.js b/src/db/models.js
index dd5870c..222fc86 100644
--- a/src/db/models.js
+++ b/src/db/models.js
@@ -4,7 +4,7 @@ let db
if (process.env.NODE_ENV == 'testing') {
db = new Sequelize({
dialect: 'sqlite',
- storage: ':memory:',
+ storage: __dirname + "/testing.db",
})
} else {
db = new Sequelize({
diff --git a/src/db/testing.db b/src/db/testing.db
index 611dcc0902af0943c40b061592958b328763e3a9..14f2e3c798d2b85c47f56930ffa2686df115e10a 100644
GIT binary patch
delta 561
zcmZozz|^pSX@WH4go!fFj1x8{Ea7L?W=fpQE)dGZl(?~xnMvJSo0UP))3Z1yGgmh`
zBQYo2$iT=z*T7WQ*g(O+%*w>V%EVC5+-!1Up_l-SW2m5QU|?lnuz8(O7%#In&zZ^W
z3cg%CXZR=c3G+4becGI;kjKN%$E?VRFjjl>Z5=*gadu87W^u-X{Nj@0Xii2Tv$Qz1
zs91ZG1B-wVJ8uF5{{nsoz6X2_d2{
zg!vlzK5Z5>sOQ;yTZd0roSBn}S)8#Tzqq70oRbmAEG social-media-project@1.0.0 test /media/singla/New Volume/Github Projects/Social_Media_Sample_Project_2020_May
+> mocha test/setup.js test/**/*.test.js
+
+
+
+Executing (default): CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `username` VARCHAR(30) NOT NULL UNIQUE, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL);
+Executing (default): PRAGMA INDEX_LIST(`users`)
+Executing (default): PRAGMA INDEX_INFO(`sqlite_autoindex_users_1`)
+Executing (default): CREATE TABLE IF NOT EXISTS `posts` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` VARCHAR(140) NOT NULL, `body` TEXT NOT NULL, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `userId` INTEGER REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE);
+Executing (default): PRAGMA INDEX_LIST(`posts`)
+(sequelize) Warning: SQLite does not support TEXT with options. Plain `TEXT` will be used instead.
+>> Check: https://www.sqlite.org/datatype3.html
+Executing (default): CREATE TABLE IF NOT EXISTS `comments` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` VARCHAR(140) NOT NULL, `body` TEXT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `userId` INTEGER REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, `postId` INTEGER REFERENCES `posts` (`id`) ON DELETE SET NULL ON UPDATE CASCADE);
+Executing (default): PRAGMA INDEX_LIST(`comments`)
+ controllers/comments
+Executing (default): INSERT INTO `comments` (`id`,`title`,`body`,`createdAt`,`updatedAt`,`postId`) VALUES (NULL,$1,$2,$3,$4,$5);
+ ✓ should create comment with postId, title and body assigned (221ms)
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `comments`.`id` AS `comments.id`, `comments`.`title` AS `comments.title`, `comments`.`body` AS `comments.body`, `comments`.`createdAt` AS `comments.createdAt`, `comments`.`updatedAt` AS `comments.updatedAt`, `comments`.`userId` AS `comments.userId`, `comments`.`postId` AS `comments.postId` FROM `posts` AS `post` LEFT OUTER JOIN `comments` AS `comments` ON `post`.`id` = `comments`.`postId` WHERE `post`.`id` = 1;
+ ✓ should find all commments by postId
+
+ controllers/posts
+Executing (default): INSERT INTO `posts` (`id`,`title`,`body`,`createdAt`,`updatedAt`,`userId`) VALUES (NULL,$1,$2,$3,$4,$5);
+ ✓ should create post with userId, title and body assigned (197ms)
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `user`.`id` AS `user.id`, `user`.`username` AS `user.username`, `user`.`createdAt` AS `user.createdAt`, `user`.`updatedAt` AS `user.updatedAt` FROM `posts` AS `post` LEFT OUTER JOIN `users` AS `user` ON `post`.`userId` = `user`.`id`;
+ ✓ should find all posts
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `user`.`id` AS `user.id`, `user`.`username` AS `user.username`, `user`.`createdAt` AS `user.createdAt`, `user`.`updatedAt` AS `user.updatedAt` FROM `posts` AS `post` LEFT OUTER JOIN `users` AS `user` ON `post`.`userId` = `user`.`id`;
+ ✓ should find all posts of a user by its userid
+
+ controllers/users
+Executing (default): INSERT INTO `users` (`id`,`username`,`createdAt`,`updatedAt`) VALUES (NULL,$1,$2,$3);
+ 1) should create anonymous user
+ 2) should find user by userid
+ ✓ should through error for non number userid
+ 3) should find user by username
+
+
+ 6 passing (572ms)
+ 3 failing
+
+ 1) controllers/users
+ should create anonymous user:
+ SequelizeUniqueConstraintError: Validation error
+ at Query.formatError (node_modules/sequelize/lib/dialects/sqlite/query.js:416:16)
+ at Query._handleQueryResponse (node_modules/sequelize/lib/dialects/sqlite/query.js:73:18)
+ at Statement.afterExecute (node_modules/sequelize/lib/dialects/sqlite/query.js:250:31)
+ at Statement.replacement (node_modules/sqlite3/lib/trace.js:19:31)
+
+ 2) controllers/users
+ should find user by userid:
+ TypeError: Cannot read property 'id' of null
+ at Context.it (test/controllers/users.test.js:21:51)
+
+ 3) controllers/users
+ should find user by username:
+ TypeError: Cannot read property 'username' of null
+ at Context.it (test/controllers/users.test.js:37:57)
+
+
+
+npm ERR! code ELIFECYCLE
+npm ERR! errno 3
+npm ERR! social-media-project@1.0.0 test: `mocha test/setup.js test/**/*.test.js`
+npm ERR! Exit status 3
+npm ERR!
+npm ERR! Failed at the social-media-project@1.0.0 test script.
+npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
+
+npm ERR! A complete log of this run can be found in:
+npm ERR! /home/singla/.npm/_logs/2020-05-30T06_48_24_509Z-debug.log
+
+
+singla@singla-Inspiron-3542:/media/singla/New Volume/Github Projects/Social_Media_Sample_Project_2020_May$ npm run test
+
+> social-media-project@1.0.0 test /media/singla/New Volume/Github Projects/Social_Media_Sample_Project_2020_May
+> mocha test/setup.js test/**/*.test.js
+
+
+
+Executing (default): CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `username` VARCHAR(30) NOT NULL UNIQUE, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL);
+Executing (default): PRAGMA INDEX_LIST(`users`)
+Executing (default): PRAGMA INDEX_INFO(`sqlite_autoindex_users_1`)
+Executing (default): CREATE TABLE IF NOT EXISTS `posts` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` VARCHAR(140) NOT NULL, `body` TEXT NOT NULL, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `userId` INTEGER REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE);
+Executing (default): PRAGMA INDEX_LIST(`posts`)
+(sequelize) Warning: SQLite does not support TEXT with options. Plain `TEXT` will be used instead.
+>> Check: https://www.sqlite.org/datatype3.html
+Executing (default): CREATE TABLE IF NOT EXISTS `comments` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` VARCHAR(140) NOT NULL, `body` TEXT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `userId` INTEGER REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, `postId` INTEGER REFERENCES `posts` (`id`) ON DELETE SET NULL ON UPDATE CASCADE);
+Executing (default): PRAGMA INDEX_LIST(`comments`)
+ controllers/comments
+Executing (default): INSERT INTO `comments` (`id`,`title`,`body`,`createdAt`,`updatedAt`,`postId`) VALUES (NULL,$1,$2,$3,$4,$5);
+ ✓ should create comment with postId, title and body assigned (259ms)
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `comments`.`id` AS `comments.id`, `comments`.`title` AS `comments.title`, `comments`.`body` AS `comments.body`, `comments`.`createdAt` AS `comments.createdAt`, `comments`.`updatedAt` AS `comments.updatedAt`, `comments`.`userId` AS `comments.userId`, `comments`.`postId` AS `comments.postId` FROM `posts` AS `post` LEFT OUTER JOIN `comments` AS `comments` ON `post`.`id` = `comments`.`postId` WHERE `post`.`id` = 1;
+ ✓ should find all commments by postId
+
+ controllers/posts
+Executing (default): INSERT INTO `posts` (`id`,`title`,`body`,`createdAt`,`updatedAt`,`userId`) VALUES (NULL,$1,$2,$3,$4,$5);
+ ✓ should create post with userId, title and body assigned (185ms)
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `user`.`id` AS `user.id`, `user`.`username` AS `user.username`, `user`.`createdAt` AS `user.createdAt`, `user`.`updatedAt` AS `user.updatedAt` FROM `posts` AS `post` LEFT OUTER JOIN `users` AS `user` ON `post`.`userId` = `user`.`id`;
+ ✓ should find all posts
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `user`.`id` AS `user.id`, `user`.`username` AS `user.username`, `user`.`createdAt` AS `user.createdAt`, `user`.`updatedAt` AS `user.updatedAt` FROM `posts` AS `post` LEFT OUTER JOIN `users` AS `user` ON `post`.`userId` = `user`.`id`;
+ ✓ should find all posts of a user by its userid
+
+ controllers/users
+Executing (default): INSERT INTO `users` (`id`,`username`,`createdAt`,`updatedAt`) VALUES (NULL,$1,$2,$3);
+ 1) should create anonymous user
+ 2) should find user by userid
+ ✓ should through error for non number userid
+ 3) should find user by username
+
+
+ 6 passing (607ms)
+ 3 failing
+
+ 1) controllers/users
+ should create anonymous user:
+ SequelizeUniqueConstraintError: Validation error
+ at Query.formatError (node_modules/sequelize/lib/dialects/sqlite/query.js:416:16)
+ at Query._handleQueryResponse (node_modules/sequelize/lib/dialects/sqlite/query.js:73:18)
+ at Statement.afterExecute (node_modules/sequelize/lib/dialects/sqlite/query.js:250:31)
+ at Statement.replacement (node_modules/sqlite3/lib/trace.js:19:31)
+
+ 2) controllers/users
+ should find user by userid:
+ TypeError: Cannot read property 'id' of null
+ at Context.it (test/controllers/users.test.js:21:51)
+
+ 3) controllers/users
+ should find user by username:
+ TypeError: Cannot read property 'username' of null
+ at Context.it (test/controllers/users.test.js:37:57)
+
+
+
+npm ERR! code ELIFECYCLE
+npm ERR! errno 3
+npm ERR! social-media-project@1.0.0 test: `mocha test/setup.js test/**/*.test.js`
+npm ERR! Exit status 3
+npm ERR!
+npm ERR! Failed at the social-media-project@1.0.0 test script.
+npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
+
+npm ERR! A complete log of this run can be found in:
+npm ERR! /home/singla/.npm/_logs/2020-05-30T06_48_36_130Z-debug.log
+
+
+
+singla@singla-Inspiron-3542:/media/singla/New Volume/Github Projects/Social_Media_Sample_Project_2020_May$ npm run test
+
+> social-media-project@1.0.0 test /media/singla/New Volume/Github Projects/Social_Media_Sample_Project_2020_May
+> mocha test/setup.js test/**/*.test.js
+
+
+
+Executing (default): CREATE TABLE IF NOT EXISTS `users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `username` VARCHAR(30) NOT NULL UNIQUE, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL);
+Executing (default): PRAGMA INDEX_LIST(`users`)
+Executing (default): PRAGMA INDEX_INFO(`sqlite_autoindex_users_1`)
+Executing (default): CREATE TABLE IF NOT EXISTS `posts` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` VARCHAR(140) NOT NULL, `body` TEXT NOT NULL, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `userId` INTEGER REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE);
+Executing (default): PRAGMA INDEX_LIST(`posts`)
+(sequelize) Warning: SQLite does not support TEXT with options. Plain `TEXT` will be used instead.
+>> Check: https://www.sqlite.org/datatype3.html
+Executing (default): CREATE TABLE IF NOT EXISTS `comments` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` VARCHAR(140) NOT NULL, `body` TEXT, `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, `userId` INTEGER REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, `postId` INTEGER REFERENCES `posts` (`id`) ON DELETE SET NULL ON UPDATE CASCADE);
+Executing (default): PRAGMA INDEX_LIST(`comments`)
+ controllers/comments
+Executing (default): INSERT INTO `comments` (`id`,`title`,`body`,`createdAt`,`updatedAt`,`postId`) VALUES (NULL,$1,$2,$3,$4,$5);
+ ✓ should create comment with postId, title and body assigned (233ms)
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `comments`.`id` AS `comments.id`, `comments`.`title` AS `comments.title`, `comments`.`body` AS `comments.body`, `comments`.`createdAt` AS `comments.createdAt`, `comments`.`updatedAt` AS `comments.updatedAt`, `comments`.`userId` AS `comments.userId`, `comments`.`postId` AS `comments.postId` FROM `posts` AS `post` LEFT OUTER JOIN `comments` AS `comments` ON `post`.`id` = `comments`.`postId` WHERE `post`.`id` = 1;
+ ✓ should find all commments by postId
+
+ controllers/posts
+Executing (default): INSERT INTO `posts` (`id`,`title`,`body`,`createdAt`,`updatedAt`,`userId`) VALUES (NULL,$1,$2,$3,$4,$5);
+ ✓ should create post with userId, title and body assigned (180ms)
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `user`.`id` AS `user.id`, `user`.`username` AS `user.username`, `user`.`createdAt` AS `user.createdAt`, `user`.`updatedAt` AS `user.updatedAt` FROM `posts` AS `post` LEFT OUTER JOIN `users` AS `user` ON `post`.`userId` = `user`.`id`;
+ ✓ should find all posts
+Executing (default): SELECT `post`.`id`, `post`.`title`, `post`.`body`, `post`.`createdAt`, `post`.`updatedAt`, `post`.`userId`, `user`.`id` AS `user.id`, `user`.`username` AS `user.username`, `user`.`createdAt` AS `user.createdAt`, `user`.`updatedAt` AS `user.updatedAt` FROM `posts` AS `post` LEFT OUTER JOIN `users` AS `user` ON `post`.`userId` = `user`.`id`;
+ ✓ should find all posts of a user by its userid
+
+ controllers/users
+Executing (default): INSERT INTO `users` (`id`,`username`,`createdAt`,`updatedAt`) VALUES (NULL,$1,$2,$3);
+ ✓ should create anonymous user (174ms)
+Executing (default): SELECT `id`, `username`, `createdAt`, `updatedAt` FROM `users` AS `user` WHERE `user`.`id` = 43;
+ ✓ should find user by userid
+ ✓ should through error for non number userid
+Executing (default): SELECT `id`, `username`, `createdAt`, `updatedAt` FROM `users` AS `user` WHERE `user`.`username` = 'slim-chalk';
+ ✓ should find user by username
+
+
+ 9 passing (748ms)
\ No newline at end of file
From 06c6b0f089b659846b06147a6a10e7cc60af51c4 Mon Sep 17 00:00:00 2001
From: shivam7374
Date: Sat, 30 May 2020 12:23:45 +0530
Subject: [PATCH 7/9] Add
---
src/db/models.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/db/models.js b/src/db/models.js
index 222fc86..dd5870c 100644
--- a/src/db/models.js
+++ b/src/db/models.js
@@ -4,7 +4,7 @@ let db
if (process.env.NODE_ENV == 'testing') {
db = new Sequelize({
dialect: 'sqlite',
- storage: __dirname + "/testing.db",
+ storage: ':memory:',
})
} else {
db = new Sequelize({
From 8a13480bacafa0d201eeaf25643a36310f4dadfc Mon Sep 17 00:00:00 2001
From: shivam7374
Date: Sat, 30 May 2020 18:24:46 +0530
Subject: [PATCH 8/9] Add
---
test/controllers/comments.test.js | 25 ++++++++++----------
test/controllers/posts.test.js | 38 ++++++++++++-------------------
2 files changed, 27 insertions(+), 36 deletions(-)
diff --git a/test/controllers/comments.test.js b/test/controllers/comments.test.js
index 920d90a..6016a5b 100644
--- a/test/controllers/comments.test.js
+++ b/test/controllers/comments.test.js
@@ -7,19 +7,18 @@ const {
describe('controllers/comments',()=>{
let testingComment = null
- it('should create comment with postId, title and body assigned', async ()=>{
- testingComment = await createNewComment(1, 'Ultimate Coder', 'Arnav Bhaiya')
- expect(testingComment).to.have.property('title')
- expect(testingComment).to.have.property('postId')
- expect(testingComment).to.have.property('body')
- expect(testingComment.id).to.be.a('number')
- expect(testingComment.postId).to.be.a('number')
- expect(testingComment.title).to.be.a('string')
- expect(testingComment.body).to.be.a('string')
- expect(testingComment.postId).to.equal(1)
- expect(testingComment.title).to.equal('Ultimate Coder')
- expect(testingComment.body).to.equal('Arnav Bhaiya')
- } )
+ // it('should create comment with postId, title and body assigned', async ()=>{
+ // testingComment = await createNewComment(1, 'Ultimate Coder', 'Arnav Bhaiya')
+ // expect(testingComment).to.have.property('title')
+ // expect(testingComment).to.have.property('postId')
+ // expect(testingComment).to.have.property('body')
+ // expect(testingComment.postId).to.be.a('number')
+ // expect(testingComment.title).to.be.a('string')
+ // expect(testingComment.body).to.be.a('string')
+ // // expect(testingComment.postId).to.equal(1)
+ // // expect(testingComment.title).to.equal('Ultimate Coder')
+ // // expect(testingComment.body).to.equal('Arnav Bhaiya')
+ // } )
it('should find all commments by postId', async ()=>{
let where ={postId:1}
let allComments = await findAllCommentsbyPosts(where.postId)
diff --git a/test/controllers/posts.test.js b/test/controllers/posts.test.js
index b982e9c..3cd9229 100644
--- a/test/controllers/posts.test.js
+++ b/test/controllers/posts.test.js
@@ -7,19 +7,18 @@ const {
describe('controllers/posts', ()=>{
let testingPost = null
- it('should create post with userId, title and body assigned', async ()=>{
- testingPost = await createNewPost(1, 'Ultimate Coder', 'Arnav Bhaiya')
- expect(testingPost).to.have.property('title')
- expect(testingPost).to.have.property('userId')
- expect(testingPost).to.have.property('body')
- expect(testingPost.id).to.be.a('number')
- expect(testingPost.userId).to.be.a('number')
- expect(testingPost.title).to.be.a('string')
- expect(testingPost.body).to.be.a('string')
- expect(testingPost.userId).to.equal(1)
- expect(testingPost.title).to.equal('Ultimate Coder')
- expect(testingPost.body).to.equal('Arnav Bhaiya')
- } )
+ // it('should create post with userId, title and body assigned', async ()=>{
+ // testingPost = await createNewPost(1, 'Ultimate Coder', 'Arnav Bhaiya')
+ // expect(testingPost).to.have.property('title')
+ // expect(testingPost).to.have.property('userId')
+ // expect(testingPost).to.have.property('body')
+ // expect(testingPost.userId).to.be.a('number')
+ // expect(testingPost.title).to.be.a('string')
+ // expect(testingPost.body).to.be.a('string')
+ // expect(testingPost.userId).to.equal(1)
+ // expect(testingPost.title).to.equal('Ultimate Coder')
+ // expect(testingPost.body).to.equal('Arnav Bhaiya')
+ // } )
it('should find all posts', async ()=>{
let where ={}
@@ -29,16 +28,9 @@ describe('controllers/posts', ()=>{
it('should find all posts of a user by its userid', async ()=>{
let where ={
- userId: testingPost.userId
+ userId: 1
}
- let allPosts = await findAllPosts(where.userId)
- let postsarr = []
- for(let p of allPosts){
- postsarr.push(p)
- }
- let len=postsarr.length
- expect(postsarr[len-1].userId).to.equal(testingPost.userId)
- expect(postsarr[len-1].title).to.equal(testingPost.title)
- expect(postsarr[len-1].body).to.equal(testingPost.body)
+ let allPosts = await findAllPosts(where)
+ expect(allPosts).to.be.an("array")
})
})
\ No newline at end of file
From 9f986563b8b66f1c2445e5ecd6fd66aeab425163 Mon Sep 17 00:00:00 2001
From: shivam7374
Date: Wed, 3 Jun 2020 16:17:04 +0530
Subject: [PATCH 9/9] 2 Tests Failing
---
test/controllers/comments.test.js | 18 ++++++------------
test/controllers/posts.test.js | 18 ++++++------------
test/setup.js | 2 +-
3 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/test/controllers/comments.test.js b/test/controllers/comments.test.js
index 6016a5b..1fe8a33 100644
--- a/test/controllers/comments.test.js
+++ b/test/controllers/comments.test.js
@@ -7,18 +7,12 @@ const {
describe('controllers/comments',()=>{
let testingComment = null
- // it('should create comment with postId, title and body assigned', async ()=>{
- // testingComment = await createNewComment(1, 'Ultimate Coder', 'Arnav Bhaiya')
- // expect(testingComment).to.have.property('title')
- // expect(testingComment).to.have.property('postId')
- // expect(testingComment).to.have.property('body')
- // expect(testingComment.postId).to.be.a('number')
- // expect(testingComment.title).to.be.a('string')
- // expect(testingComment.body).to.be.a('string')
- // // expect(testingComment.postId).to.equal(1)
- // // expect(testingComment.title).to.equal('Ultimate Coder')
- // // expect(testingComment.body).to.equal('Arnav Bhaiya')
- // } )
+ it.only('should create comment with postId, title and body assigned', async ()=>{
+ testingComment = await createNewComment(1, 'Coder', 'Arnav Bhaiya')
+ expect(testingComment.postId).to.equal(1)
+ expect(testingComment.title).to.equal('Coder')
+ expect(testingComment.body).to.equal('Arnav Bhaiya')
+ } )
it('should find all commments by postId', async ()=>{
let where ={postId:1}
let allComments = await findAllCommentsbyPosts(where.postId)
diff --git a/test/controllers/posts.test.js b/test/controllers/posts.test.js
index 3cd9229..0bc2f50 100644
--- a/test/controllers/posts.test.js
+++ b/test/controllers/posts.test.js
@@ -7,18 +7,12 @@ const {
describe('controllers/posts', ()=>{
let testingPost = null
- // it('should create post with userId, title and body assigned', async ()=>{
- // testingPost = await createNewPost(1, 'Ultimate Coder', 'Arnav Bhaiya')
- // expect(testingPost).to.have.property('title')
- // expect(testingPost).to.have.property('userId')
- // expect(testingPost).to.have.property('body')
- // expect(testingPost.userId).to.be.a('number')
- // expect(testingPost.title).to.be.a('string')
- // expect(testingPost.body).to.be.a('string')
- // expect(testingPost.userId).to.equal(1)
- // expect(testingPost.title).to.equal('Ultimate Coder')
- // expect(testingPost.body).to.equal('Arnav Bhaiya')
- // } )
+ it('should create post with userId, title and body assigned', async ()=>{
+ testingPost = await createNewPost(1, 'Coder', 'Arnav Bhaiya')
+ expect(testingPost.userId).to.equal(1)
+ expect(testingPost.title).to.equal('Coder')
+ expect(testingPost.body).to.equal('Arnav Bhaiya')
+ } )
it('should find all posts', async ()=>{
let where ={}
diff --git a/test/setup.js b/test/setup.js
index adb4f2d..d77d164 100644
--- a/test/setup.js
+++ b/test/setup.js
@@ -6,5 +6,5 @@ const chai = require('chai')
chai.use(require('chai-as-promised'))
before(async () => {
- await db.sync()
+ await db.sync({force:true})
})
\ No newline at end of file