Skip to content

Commit

Permalink
Updated comments test coverage, includes basic endpoints as well as f…
Browse files Browse the repository at this point in the history
…oreign key/id arrays
  • Loading branch information
MKHenson committed May 26, 2016
1 parent 3b4f65c commit 560801f
Showing 1 changed file with 83 additions and 5 deletions.
88 changes: 83 additions & 5 deletions server/test/tests/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Testing all comment related endpoints', function() {

it('Cannot create a comment without a post that actually exists', function(done) {
header.modepressAgent
.post('/api/posts/123456789012345678901234/comments/123456789012345678901234').set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.post('/api/posts/123456789012345678901234/comments').set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.set('Cookie', header.adminCookie)
.send( { } )
.end(function(err, res) {
Expand All @@ -89,6 +89,21 @@ describe('Testing all comment related endpoints', function() {
});
})

it('Cannot create a comment without a post that actually exists', function(done) {
header.modepressAgent
.post('/api/posts/123456789012345678901234/comments/123456789012345678901234').set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.set('Cookie', header.adminCookie)
.send( { } )
.end(function(err, res) {
if (err)
return done(err);

test.string(res.body.message).is("No comment exists with the id 123456789012345678901234")
test.bool(res.body.error).isTrue()
done();
});
})

it('Can create a temp post', function(done) {
header.modepressAgent
.post('/api/posts/create-post').set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
Expand Down Expand Up @@ -136,6 +151,7 @@ describe('Testing all comment related endpoints', function() {
test.value(res.body.data.parent).isNull()
test.string(res.body.data.post).is(lastPost._id)
test.string(res.body.data.content).is("Hello world! __filter__")
test.array(res.body.data.children).hasLength(0)
test.bool(res.body.data.public).isFalse()
test.number(res.body.data.createdOn)
test.number(res.body.data.lastUpdated)
Expand Down Expand Up @@ -302,7 +318,39 @@ describe('Testing all comment related endpoints', function() {
});
})

it('Can get a comment with parent & post, and both properties are ids', function(done) {
it('Can create a fourth public comment on the same post, with a parent comment', function(done) {
header.modepressAgent
.post(`/api/posts/${lastPost._id}/comments/${comment._id}`).set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.set('Cookie', header.adminCookie)
.send( { content: "Hello world 4! __filter__", public: true } )
.end(function(err, res) {
if (err)
return done(err);

comment4 = res.body.data;
test.string(res.body.message).is("New comment created")
done();
});
})

it('Can get the parent comment and has previously created comment as child', function(done) {
header.modepressAgent
.get(`/api/comments/${comment._id}`).set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.set('Cookie', header.adminCookie)
.end(function(err, res) {
if (err)
return done(err);

test.string(res.body.message).is("Found 1 comments")
test.string(res.body.data._id).is(comment._id)
test.array(res.body.data.children).contains([comment3._id, comment4._id])
//test.array(res.body.data.children).contains(comment4._id)
test.bool(res.body.error).isFalse()
done();
});
})

it('Can get a comment with parent & post, and both properties are just ids (not expanded)', function(done) {
header.modepressAgent
.get(`/api/comments/${comment3._id}`).set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.set('Cookie', header.adminCookie)
Expand All @@ -319,7 +367,7 @@ describe('Testing all comment related endpoints', function() {
});
})

it('Can get a comment with parent & post, and both properties are the respective objects', function(done) {
it('Can get a comment with parent & post, and both properties are the respective objects (expanded)', function(done) {
header.modepressAgent
.get(`/api/comments/${comment3._id}?expanded=true`).set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.set('Cookie', header.adminCookie)
Expand All @@ -329,8 +377,7 @@ describe('Testing all comment related endpoints', function() {

test.string(res.body.message).is("Found 1 comments")
test.string(res.body.data._id).is(comment3._id)
test.string(res.body.data.parent._id).is(comment._id)
test.string(res.body.data.parent.post).is(lastPost._id)
test.string(res.body.data.parent).is(comment._id)
test.string(res.body.data.post._id).is(lastPost._id)
test.bool(res.body.error).isFalse()
done();
Expand Down Expand Up @@ -379,6 +426,37 @@ describe('Testing all comment related endpoints', function() {
});
})

it('Can delete the fourth comment', function(done) {
header.modepressAgent
.delete(`/api/users/${header.uconfig.adminUser.username}/comments/${comment4._id}`).set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.set('Cookie', header.adminCookie)
.end(function(err, res) {
if (err)
return done(err);

test.string(res.body.message).is("Comment has been successfully removed")
test.bool(res.body.error).isFalse()
done();
});
})

it('Can get parent comment and comment 4 has been removed', function(done) {
header.modepressAgent
.get(`/api/comments/${comment._id}`).set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
.set('Cookie', header.adminCookie)
.end(function(err, res) {
if (err)
return done(err);

test.string(res.body.message).is("Found 1 comments")
test.string(res.body.data._id).is(comment._id)
test.array(res.body.data.children).contains([comment3._id])
test.array(res.body.data.children).notContains([comment4._id])
test.bool(res.body.error).isFalse()
done();
});
})

it('Can delete an existing comment', function(done) {
header.modepressAgent
.delete(`/api/users/${header.uconfig.adminUser.username}/comments/${comment._id}`).set('Accept', 'application/json').expect(200).expect('Content-Type', /json/)
Expand Down

0 comments on commit 560801f

Please sign in to comment.