diff --git a/services/comments.js b/services/comments.js index d82f5046d..e18e04970 100644 --- a/services/comments.js +++ b/services/comments.js @@ -13,15 +13,11 @@ const { COMMENTS_NEW, COMMENTS_EDIT } = require('./events/constants'); module.exports = class CommentsService { /** * Creates a new Comment that came from a public source. - * @param {Mixed} input either a single comment or an array of comments. + * @param {Object} input either a single comment or an array of comments. * @return {Promise} */ static async publicCreate(input) { - // Check to see if this is an array of comments, if so map it out. - if (Array.isArray(input)) { - return Promise.all(input.map(CommentsService.publicCreate)); - } - + // Extract the parent_id from the comment, if there is one. const { status = 'NONE', parent_id = null } = input; // Check to see if we are replying to a comment, and if that comment is @@ -33,8 +29,8 @@ module.exports = class CommentsService { } } - // Turn the comment into a new object. - const comment = new CommentModel( + // Create the comment in the database. + const comment = await CommentModel.create( merge( { status_history: status @@ -56,9 +52,6 @@ module.exports = class CommentsService { ) ); - // Save the comment to the database. - await comment.save(); - // Emit that the comment was created! await events.emitAsync(COMMENTS_NEW, comment); diff --git a/test/server/graph/queries/asset.js b/test/server/graph/queries/asset.js index af19e4f69..f976bd37d 100644 --- a/test/server/graph/queries/asset.js +++ b/test/server/graph/queries/asset.js @@ -34,12 +34,14 @@ describe('graph.queries.asset', () => { username: 'usernameC', }, ]); - comments = await CommentsService.publicCreate( - [0, 0, 1, 1].map(idx => ({ - author_id: users[idx].id, - asset_id: assets[idx].id, - body: `hello there! ${String(Math.random()).slice(2)}`, - })) + comments = await Promise.all( + [0, 0, 1, 1].map(idx => + CommentsService.publicCreate({ + author_id: users[idx].id, + asset_id: assets[idx].id, + body: `hello there! ${String(Math.random()).slice(2)}`, + }) + ) ); }); diff --git a/test/server/services/assets.js b/test/server/services/assets.js index c071b5634..923f28751 100644 --- a/test/server/services/assets.js +++ b/test/server/services/assets.js @@ -176,28 +176,30 @@ describe('services.AssetsService', () => { ); // Create some comments on both assets. - await CommentsService.publicCreate([ - { - asset_id: '1', - body: 'This is a comment!', - status: 'ACCEPTED', - }, - { - asset_id: '1', - body: 'This is a comment!', - status: 'ACCEPTED', - }, - { - asset_id: '2', - body: 'This is a comment!', - status: 'ACCEPTED', - }, - { - asset_id: '2', - body: 'This is a comment!', - status: 'ACCEPTED', - }, - ]); + await Promise.all( + [ + { + asset_id: '1', + body: 'This is a comment!', + status: 'ACCEPTED', + }, + { + asset_id: '1', + body: 'This is a comment!', + status: 'ACCEPTED', + }, + { + asset_id: '2', + body: 'This is a comment!', + status: 'ACCEPTED', + }, + { + asset_id: '2', + body: 'This is a comment!', + status: 'ACCEPTED', + }, + ].map(comment => CommentsService.publicCreate(comment)) + ); // Merge all the comments from asset 1 into asset 2, followed by deleting // asset 1. diff --git a/test/server/services/comments.js b/test/server/services/comments.js index b0af0b0e0..2d0b37163 100644 --- a/test/server/services/comments.js +++ b/test/server/services/comments.js @@ -200,31 +200,6 @@ describe('services.CommentsService', () => { expect(c.id).to.be.uuid; expect(c.status).to.be.equal('ACCEPTED'); }); - - it('creates many new comments', async () => { - const [c1, c2, c3] = await CommentsService.publicCreate([ - { - body: 'This is a comment!', - status: 'ACCEPTED', - }, - { - body: 'This is another comment!', - }, - { - body: 'This is a rejected comment!', - status: 'REJECTED', - }, - ]); - - expect(c1).to.not.be.null; - expect(c1.status).to.be.equal('ACCEPTED'); - - expect(c2).to.not.be.null; - expect(c2.status).to.be.equal('NONE'); - - expect(c3).to.not.be.null; - expect(c3.status).to.be.equal('REJECTED'); - }); }); describe('#edit', () => {