replaced eslint:recommended with prettier

This commit is contained in:
Wyatt Johnson
2018-01-11 20:00:34 -07:00
parent d56c19016a
commit 0abc2ca243
649 changed files with 16235 additions and 13008 deletions
+135 -103
View File
@@ -2,12 +2,16 @@ const CommentModel = require('../../../models/comment');
const ActionModel = require('../../../models/action');
const events = require('../../../services/events');
const {COMMENTS_EDIT} = require('../../../services/events/constants');
const { COMMENTS_EDIT } = require('../../../services/events/constants');
const UsersService = require('../../../services/users');
const SettingsService = require('../../../services/settings');
const CommentsService = require('../../../services/comments');
const settings = {id: '1', moderation: 'PRE', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
const settings = {
id: '1',
moderation: 'PRE',
wordlist: { banned: ['bad words'], suspect: ['suspect words'] },
};
const chai = require('chai');
chai.use(require('sinon-chai'));
@@ -16,84 +20,105 @@ const expect = chai.expect;
const sinon = require('sinon');
describe('services.CommentsService', () => {
const comments = [{
body: 'comment 10',
asset_id: '123',
status_history: [],
parent_id: '',
author_id: '123',
id: '1'
}, {
body: 'comment 20',
asset_id: '123',
status_history: [{
type: 'ACCEPTED'
}],
status: 'ACCEPTED',
parent_id: '',
author_id: '123',
id: '2'
}, {
body: 'comment 30',
asset_id: '456',
status_history: [],
parent_id: '',
author_id: '456',
id: '3'
}, {
body: 'comment 40',
asset_id: '123',
status_history: [{
type: 'REJECTED'
}],
status: 'REJECTED',
parent_id: '',
author_id: '456',
id: '4'
}, {
body: 'comment 50',
asset_id: '1234',
status_history: [{
type: 'PREMOD'
}],
status: 'PREMOD',
parent_id: '',
author_id: '456',
id: '5'
}, {
body: 'comment 60',
asset_id: '1234',
status_history: [{
type: 'PREMOD'
}],
status: 'PREMOD',
parent_id: '',
author_id: '456',
id: '6'
}];
const comments = [
{
body: 'comment 10',
asset_id: '123',
status_history: [],
parent_id: '',
author_id: '123',
id: '1',
},
{
body: 'comment 20',
asset_id: '123',
status_history: [
{
type: 'ACCEPTED',
},
],
status: 'ACCEPTED',
parent_id: '',
author_id: '123',
id: '2',
},
{
body: 'comment 30',
asset_id: '456',
status_history: [],
parent_id: '',
author_id: '456',
id: '3',
},
{
body: 'comment 40',
asset_id: '123',
status_history: [
{
type: 'REJECTED',
},
],
status: 'REJECTED',
parent_id: '',
author_id: '456',
id: '4',
},
{
body: 'comment 50',
asset_id: '1234',
status_history: [
{
type: 'PREMOD',
},
],
status: 'PREMOD',
parent_id: '',
author_id: '456',
id: '5',
},
{
body: 'comment 60',
asset_id: '1234',
status_history: [
{
type: 'PREMOD',
},
],
status: 'PREMOD',
parent_id: '',
author_id: '456',
id: '6',
},
];
const users = [{
id: 'u1',
email: 'stampi@gmail.com',
username: 'Stampi',
password: '1Coral!!'
}, {
email: 'sockmonster@gmail.com',
username: 'Sockmonster',
password: '2Coral!!'
}];
const users = [
{
id: 'u1',
email: 'stampi@gmail.com',
username: 'Stampi',
password: '1Coral!!',
},
{
email: 'sockmonster@gmail.com',
username: 'Sockmonster',
password: '2Coral!!',
},
];
const actions = [{
action_type: 'FLAG',
item_id: '3',
item_type: 'COMMENTS',
user_id: '123'
}, {
action_type: 'LIKE',
item_id: '1',
item_type: 'COMMENTS',
user_id: '456'
}];
const actions = [
{
action_type: 'FLAG',
item_id: '3',
item_type: 'COMMENTS',
user_id: '123',
},
{
action_type: 'LIKE',
item_id: '1',
item_type: 'COMMENTS',
user_id: '456',
},
];
beforeEach(async () => {
await SettingsService.init(settings);
@@ -101,16 +126,15 @@ describe('services.CommentsService', () => {
await Promise.all([
CommentModel.create(comments),
UsersService.createLocalUsers(users),
ActionModel.create(actions)
ActionModel.create(actions),
]);
});
describe('#publicCreate()', () => {
it('creates a new comment', async () => {
const c = await CommentsService.publicCreate({
body: 'This is a comment!',
status: 'ACCEPTED'
status: 'ACCEPTED',
});
expect(c).to.not.be.null;
@@ -120,19 +144,19 @@ describe('services.CommentsService', () => {
});
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'
}]);
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');
@@ -161,7 +185,10 @@ describe('services.CommentsService', () => {
expect(retrivedComment).to.have.property('status', 'ACCEPTED');
expect(retrivedComment.status_history).to.have.length(2);
expect(retrivedComment.status_history[1]).to.have.property('type', 'ACCEPTED');
expect(retrivedComment.status_history[1]).to.have.property(
'type',
'ACCEPTED'
);
const editedComment = await CommentsService.edit({
id: originalComment.id,
@@ -172,34 +199,40 @@ describe('services.CommentsService', () => {
expect(editedComment).to.have.property('status', 'PREMOD');
expect(editedComment.status_history).to.have.length(4);
expect(editedComment.status_history[3]).to.have.property('type', 'PREMOD');
expect(editedComment.status_history[3]).to.have.property(
'type',
'PREMOD'
);
retrivedComment = await CommentsService.findById(originalComment.id);
expect(retrivedComment).to.have.property('status', 'PREMOD');
expect(retrivedComment.status_history).to.have.length(4);
expect(retrivedComment.status_history[3]).to.have.property('type', 'PREMOD');
expect(retrivedComment.status_history[3]).to.have.property(
'type',
'PREMOD'
);
});
});
describe('#findById()', () => {
it('should find a comment by id', async () => {
const comment = await CommentsService.findById('1');
expect(comment).to.not.be.null;
expect(comment).to.have.property('body', 'comment 10');
});
});
describe('#findByAssetId()', () => {
it('should find an array of all comments by asset id', async () => {
const comments = await CommentsService.findByAssetId('123');
expect(comments).to.have.length(3);
comments.sort((a, b) => {
if (a.body < b.body) {return -1;}
else {return 1;}
if (a.body < b.body) {
return -1;
} else {
return 1;
}
});
expect(comments[0]).to.have.property('body', 'comment 10');
expect(comments[1]).to.have.property('body', 'comment 20');
@@ -208,7 +241,6 @@ describe('services.CommentsService', () => {
});
describe('#changeStatus', () => {
it('should change the status of a comment from no status', async () => {
let comment_id = comments[0].id;