Skip to content

Commit

Permalink
Fixed comment and post tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MKHenson committed Mar 28, 2017
1 parent d3d15a7 commit a6c3100
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
16 changes: 8 additions & 8 deletions test/tests/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe( 'Testing all comment related endpoints', function() {
} )

it( 'Can create a second public comment on the same post', function( done ) {
manager.post( `/api/posts/${lastPost._id}/comments`, { content: "Hello world 2! __filter__", public: true }, null )
manager.post( `/api/posts/${lastPost._id}/comments`, { content: "Hello world 2! __filter__", public: true } )
.then( res => {
comment2 = res.body.data;
test.string( res.body.message ).is( "New comment created" );
Expand All @@ -166,7 +166,7 @@ describe( 'Testing all comment related endpoints', function() {
} )

it( 'Can get comments by user & there are more than 1', function( done ) {
manager.get( `/api/users/${header.uconfig.adminUser.username}/comments` )
manager.get( `/api/users/${manager.config.adminUser.username}/comments` )
.then( res => {
test.number( res.body.count );
test.bool( res.body.count >= 2 ).isTrue();
Expand All @@ -176,7 +176,7 @@ describe( 'Testing all comment related endpoints', function() {
} )

it( 'Can get comments by user & there should be 2 if we filter by keyword', function( done ) {
manager.get( `/api/users/${header.uconfig.adminUser.username}/comments?keyword=__filter__` )
manager.get( `/api/users/${manager.config.adminUser.username}/comments?keyword=__filter__` )
.then( res => {
test.number( res.body.count );
test.array( res.body.data ).hasLength( 2 );
Expand All @@ -187,22 +187,22 @@ describe( 'Testing all comment related endpoints', function() {
} )

it( 'Can get comments by user & should limit whats returned to 1', function( done ) {
manager.get( `/api/users/${header.uconfig.adminUser.username}/comments?keyword=__filter__&limit=1` )
manager.get( `/api/users/${manager.config.adminUser.username}/comments?keyword=__filter__&limit=1` )
.then( res => {
test.number( res.body.count );
test.array( res.body.data ).hasLength( 2 );
test.array( res.body.data ).hasLength( 1 );
test.bool( res.body.count === 2 ).isTrue();
test.bool( res.body.error ).isFalse();
done();
} ).catch( err => done( err ) );
} )

it( 'Can get comments by user & should limit whats returned to 1 if not admin', function( done ) {
manager.get( `/api/users/${header.uconfig.adminUser.username}/comments?keyword=__filter__`, null )
manager.get( `/api/users/${manager.config.adminUser.username}/comments?keyword=__filter__` )
.then( res => {
test.number( res.body.count );
test.array( res.body.data ).hasLength( 1 );
test.bool( res.body.count === 1 ).isTrue(); // Count is still 2 as
test.array( res.body.data ).hasLength( 2 );
test.bool( res.body.count === 2 ).isTrue(); // Count is still 2 as
test.bool( res.body.error ).isFalse();
done();
} ).catch( err => done( err ) );
Expand Down
27 changes: 8 additions & 19 deletions test/tests/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ describe( 'Testing all post related endpoints', function() {
} ).catch( err => done( err ) );
} )

it( 'Can fetch posts and impose a limit off 0 on them', function( done ) {
manager.get( `/api/posts?index=1&limit=1` )
it( 'Can fetch posts and impose an index and limit', function( done ) {
manager.get( `/api/posts?index=${numPosts - 1}&limit=1` )
.then( res => {
test.array( res.body.data ).hasLength( 1 );
done();
Expand Down Expand Up @@ -176,7 +176,7 @@ describe( 'Testing all post related endpoints', function() {
} )

it( 'Fetched 0 posts when not logged in as admin as post is not public', function( done ) {
manager.get( `/api/posts?tags=super-tags-1234&categories=super-tests` )
manager.get( `/api/posts?tags=super-tags-1234&categories=super-tests`, null )
.then( res => {
test.number( res.body.count ).is( 0 );
done();
Expand All @@ -191,7 +191,7 @@ describe( 'Testing all post related endpoints', function() {
} ).catch( err => done( err ) );
} )

it( 'Cannot create a post with the same slug', function( done ) {
it( 'Cannot create a post with an existing slug', function( done ) {
manager.post( `/api/posts`, { title: "Simple Test 2", slug: "--simple--test--" } )
.then( res => {
test.string( res.body.message ).is( "'slug' must be unique" )
Expand Down Expand Up @@ -273,7 +273,7 @@ describe( 'Testing all post related endpoints', function() {
} )

it( 'Can set a post to public', function( done ) {
manager.put( `/api/posts/${lastPost}`, { public: true }, null )
manager.put( `/api/posts/${lastPost}`, { public: true } )
.then( res => {
test.string( res.body.message ).is( "Post Updated" );
done();
Expand All @@ -289,7 +289,7 @@ describe( 'Testing all post related endpoints', function() {
} )

it( 'Cannot delete a post with invalid ID format', function( done ) {
manager.delete( `/api/posts/WRONGWRONGWRONG`, {}, null )
manager.delete( `/api/posts/WRONGWRONGWRONG`, {} )
.then( res => {
test.string( res.body.message ).is( "Invalid ID format" );
done();
Expand Down Expand Up @@ -320,14 +320,6 @@ describe( 'Testing all post related endpoints', function() {
} ).catch( err => done( err ) );
} )

it( 'Can delete temp post with valid ID', function( done ) {
manager.delete( `/api/posts/${lastPost}`, {} )
.then( res => {
test.string( res.body.message ).is( "Post has been successfully removed" );
done();
} ).catch( err => done( err ) );
} )

it( 'Should create a post & strip HTML from title', function( done ) {
manager.post( `/api/posts`, {
title: "Simple Test <h2>NO</h2>",
Expand All @@ -339,13 +331,10 @@ describe( 'Testing all post related endpoints', function() {
test.string( res.body.data.title ).is( "Simple Test NO" );

// Clean up
header.modepressAgent
test.delete( '/api/posts/' + res.body.data._id ).set( 'Accept', 'application/json' ).expect( 200 ).expect( 'Content-Type', /json/ )
test.set( 'Cookie', header.adminCookie )
test.end( function( err, res ) {
manager.delete( '/api/posts/' + res.body.data._id, {} ).then( function( res ) {
test.string( res.body.message ).is( "Post has been successfully removed" );
done();
} );
} ).catch( err => done( err ) );
} ).catch( err => done( err ) );
} )

Expand Down

0 comments on commit a6c3100

Please sign in to comment.