mirror of
https://github.com/wassname/talk.git
synced 2026-08-18 12:30:39 +08:00
Const, service, and model updates
- Updated enum values to be uppercase - Updated services to expose service models - Updated models to only export the mongoose model - Moved all mongoose static methods over to new services - Updated tests to refelct new setup BREAKING - Status that were uppercased (caps) have caused issues with the admin pages
This commit is contained in:
@@ -1,245 +0,0 @@
|
||||
const Comment = require('../../models/comment');
|
||||
const User = require('../../models/user');
|
||||
const Action = require('../../models/action');
|
||||
const Setting = require('../../models/setting');
|
||||
|
||||
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
|
||||
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('models.Comment', () => {
|
||||
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 = [{
|
||||
email: 'stampi@gmail.com',
|
||||
displayName: 'Stampi',
|
||||
password: '1Coral!!'
|
||||
}, {
|
||||
email: 'sockmonster@gmail.com',
|
||||
displayName: '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'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Setting.init(settings).then(() => {
|
||||
return Promise.all([
|
||||
Comment.create(comments),
|
||||
User.createLocalUsers(users),
|
||||
Action.create(actions)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#publicCreate()', () => {
|
||||
|
||||
it('creates a new comment', () => {
|
||||
return Comment.publicCreate({
|
||||
body: 'This is a comment!',
|
||||
status: 'accepted'
|
||||
}).then((c) => {
|
||||
expect(c).to.not.be.null;
|
||||
expect(c.id).to.not.be.null;
|
||||
expect(c.id).to.be.uuid;
|
||||
expect(c.status).to.be.equal('accepted');
|
||||
});
|
||||
});
|
||||
|
||||
it('creates many new comments', () => {
|
||||
return Comment.publicCreate([{
|
||||
body: 'This is a comment!',
|
||||
status: 'accepted'
|
||||
}, {
|
||||
body: 'This is another comment!'
|
||||
}, {
|
||||
body: 'This is a rejected comment!',
|
||||
status: 'rejected'
|
||||
}]).then(([c1, c2, c3]) => {
|
||||
expect(c1).to.not.be.null;
|
||||
expect(c1.id).to.be.uuid;
|
||||
expect(c1.status).to.be.equal('accepted');
|
||||
|
||||
expect(c2).to.not.be.null;
|
||||
expect(c2.id).to.be.uuid;
|
||||
expect(c2.status).to.be.null;
|
||||
|
||||
expect(c3).to.not.be.null;
|
||||
expect(c3.id).to.be.uuid;
|
||||
expect(c3.status).to.be.equal('rejected');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#findById()', () => {
|
||||
|
||||
it('should find a comment by id', () => {
|
||||
return Comment.findById('1').then((result) => {
|
||||
expect(result).to.not.be.null;
|
||||
expect(result).to.have.property('body', 'comment 10');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#findByAssetId()', () => {
|
||||
|
||||
it('should find an array of all comments by asset id', () => {
|
||||
return Comment.findByAssetId('123').then((result) => {
|
||||
expect(result).to.have.length(3);
|
||||
result.sort((a, b) => {
|
||||
if (a.body < b.body) {return -1;}
|
||||
else {return 1;}
|
||||
});
|
||||
expect(result[0]).to.have.property('body', 'comment 10');
|
||||
expect(result[1]).to.have.property('body', 'comment 20');
|
||||
expect(result[2]).to.have.property('body', 'comment 40');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#moderationQueue()', () => {
|
||||
|
||||
it('should find an array of new comments to moderate when pre-moderation', () => {
|
||||
return Comment.moderationQueue('premod').then((result) => {
|
||||
expect(result).to.not.be.null;
|
||||
expect(result).to.have.lengthOf(2);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#removeAction', () => {
|
||||
|
||||
it('should remove an action', () => {
|
||||
return Comment.removeAction('3', '123', 'flag')
|
||||
.then(() => {
|
||||
return Action.findByItemIdArray(['123']);
|
||||
})
|
||||
.then((actions) => {
|
||||
expect(actions.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#findByUserId', () => {
|
||||
it('should return all comments if admin', () => {
|
||||
return Comment.findByUserId('456', true)
|
||||
.then(comments => {
|
||||
expect(comments).to.have.length(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not return premod and rejected comments if not admin', () => {
|
||||
return Comment.findByUserId('456')
|
||||
.then(comments => {
|
||||
expect(comments).to.have.length(1);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#changeStatus', () => {
|
||||
|
||||
it('should change the status of a comment from no status', () => {
|
||||
let comment_id = comments[0].id;
|
||||
|
||||
return Comment.findById(comment_id)
|
||||
.then((c) => {
|
||||
expect(c.status).to.be.null;
|
||||
|
||||
return Comment.pushStatus(comment_id, 'rejected', '123');
|
||||
})
|
||||
.then(() => Comment.findById(comment_id))
|
||||
.then((c) => {
|
||||
expect(c).to.have.property('status');
|
||||
expect(c.status).to.equal('rejected');
|
||||
expect(c.status_history).to.have.length(1);
|
||||
expect(c.status_history[0]).to.have.property('type', 'rejected');
|
||||
expect(c.status_history[0]).to.have.property('assigned_by', '123');
|
||||
});
|
||||
});
|
||||
|
||||
it('should change the status of a comment from accepted', () => {
|
||||
return Comment.pushStatus(comments[1].id, 'rejected', '123')
|
||||
.then(() => Comment.findById(comments[1].id))
|
||||
.then((c) => {
|
||||
expect(c).to.have.property('status_history');
|
||||
expect(c).to.have.property('status');
|
||||
expect(c.status).to.equal('rejected');
|
||||
expect(c.status_history).to.have.length(2);
|
||||
expect(c.status_history[0]).to.have.property('type', 'accepted');
|
||||
expect(c.status_history[0]).to.have.property('assigned_by', null);
|
||||
|
||||
expect(c.status_history[1]).to.have.property('type', 'rejected');
|
||||
expect(c.status_history[1]).to.have.property('assigned_by', '123');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
@@ -8,12 +8,13 @@ const expect = chai.expect;
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const Asset = require('../../../../models/asset');
|
||||
const AssetModel = require('../../../../models/asset');
|
||||
const AssetsService = require('../../../../services/assets');
|
||||
|
||||
describe('/api/v1/assets', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
return Asset.create([
|
||||
return AssetModel.create([
|
||||
{
|
||||
url: 'https://coralproject.net/news/asset1',
|
||||
title: 'Asset 1',
|
||||
@@ -121,7 +122,7 @@ describe('/api/v1/assets', () => {
|
||||
|
||||
const today = Date.now();
|
||||
|
||||
return Asset.findOrCreateByUrl('http://test.com')
|
||||
return AssetsService.findOrCreateByUrl('http://test.com')
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('isClosed', null);
|
||||
expect(asset).to.have.property('closedAt', null);
|
||||
@@ -135,7 +136,7 @@ describe('/api/v1/assets', () => {
|
||||
|
||||
expect(res).to.have.status(204);
|
||||
|
||||
return Asset.findByUrl('http://test.com');
|
||||
return AssetsService.findByUrl('http://test.com');
|
||||
})
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('isClosed', true);
|
||||
|
||||
@@ -4,7 +4,7 @@ const expect = chai.expect;
|
||||
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const User = require('../../../../models/user');
|
||||
const UsersService = require('../../../../services/users');
|
||||
|
||||
describe('/api/v1/auth', () => {
|
||||
describe('#get', () => {
|
||||
@@ -19,15 +19,15 @@ describe('/api/v1/auth', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const Setting = require('../../../../models/setting');
|
||||
const SettingsService = require('../../../../services/settings');
|
||||
|
||||
describe('/api/v1/auth/local', () => {
|
||||
|
||||
let mockUser;
|
||||
beforeEach(() => {
|
||||
const settings = {requireEmailConfirmation: false, wordlist: {banned: ['bad'], suspect: ['naughty']}};
|
||||
return Setting.init(settings).then(() => {
|
||||
return User.createLocalUser('maria@gmail.com', 'password!', 'Maria')
|
||||
return SettingsService.init(settings).then(() => {
|
||||
return UsersService.createLocalUser('maria@gmail.com', 'password!', 'Maria')
|
||||
.then((user) => {
|
||||
mockUser = user;
|
||||
});
|
||||
@@ -66,7 +66,7 @@ describe('/api/v1/auth/local', () => {
|
||||
|
||||
describe('email confirmation enabled', () => {
|
||||
|
||||
beforeEach(() => Setting.init({requireEmailConfirmation: true}));
|
||||
beforeEach(() => SettingsService.init({requireEmailConfirmation: true}));
|
||||
|
||||
describe('#post', () => {
|
||||
it('should not allow a login from a user that is not confirmed', () => {
|
||||
@@ -76,9 +76,9 @@ describe('/api/v1/auth/local', () => {
|
||||
.catch((err) => {
|
||||
err.response.should.have.status(401);
|
||||
|
||||
return User.createEmailConfirmToken(mockUser.id, mockUser.profiles[0].id);
|
||||
return UsersService.createEmailConfirmToken(mockUser.id, mockUser.profiles[0].id);
|
||||
})
|
||||
.then(User.verifyEmailConfirmation)
|
||||
.then(UsersService.verifyEmailConfirmation)
|
||||
.then(() => {
|
||||
return chai.request(app)
|
||||
.post('/api/v1/auth/local')
|
||||
|
||||
@@ -8,18 +8,19 @@ const expect = chai.expect;
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const Comment = require('../../../../models/comment');
|
||||
const Asset = require('../../../../models/asset');
|
||||
const Action = require('../../../../models/action');
|
||||
const User = require('../../../../models/user');
|
||||
const CommentModel = require('../../../../models/comment');
|
||||
const ActionModel = require('../../../../models/action');
|
||||
|
||||
const CommentsService = require('../../../../services/comments');
|
||||
const UsersService = require('../../../../services/users');
|
||||
const SettingsService = require('../../../../services/settings');
|
||||
|
||||
const Setting = require('../../../../models/setting');
|
||||
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
|
||||
|
||||
describe('/api/v1/comments', () => {
|
||||
|
||||
// Ensure that the settings are always available.
|
||||
beforeEach(() => Setting.init(settings));
|
||||
beforeEach(() => SettingsService.init(settings));
|
||||
|
||||
describe('#get', () => {
|
||||
const comments = [{
|
||||
@@ -34,16 +35,16 @@ describe('/api/v1/comments', () => {
|
||||
body: 'comment 20',
|
||||
asset_id: 'asset',
|
||||
author_id: '456',
|
||||
status: 'rejected',
|
||||
status: 'REJECTED',
|
||||
status_history: [{
|
||||
type: 'rejected'
|
||||
type: 'REJECTED'
|
||||
}]
|
||||
}, {
|
||||
body: 'comment 30',
|
||||
asset_id: '456',
|
||||
status: 'accepted',
|
||||
status: 'ACCEPTED',
|
||||
status_history: [{
|
||||
type: 'accepted'
|
||||
type: 'ACCEPTED'
|
||||
}]
|
||||
}];
|
||||
|
||||
@@ -58,18 +59,18 @@ describe('/api/v1/comments', () => {
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
action_type: 'FLAG',
|
||||
item_id: 'abc',
|
||||
item_type: 'comments'
|
||||
item_type: 'COMMENTS'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
action_type: 'LIKE',
|
||||
item_id: 'hij',
|
||||
item_type: 'comments'
|
||||
item_type: 'COMMENTS'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Promise.all([
|
||||
Comment.create(comments).then((newComments) => {
|
||||
CommentModel.create(comments).then((newComments) => {
|
||||
newComments.forEach((comment, i) => {
|
||||
comments[i].id = comment.id;
|
||||
});
|
||||
@@ -77,9 +78,9 @@ describe('/api/v1/comments', () => {
|
||||
actions[0].item_id = comments[0].id;
|
||||
actions[1].item_id = comments[1].id;
|
||||
|
||||
return Action.create(actions);
|
||||
return ActionModel.create(actions);
|
||||
}),
|
||||
User.createLocalUsers(users)
|
||||
UsersService.createLocalUsers(users)
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -119,7 +120,7 @@ describe('/api/v1/comments', () => {
|
||||
|
||||
it('should return all the rejected comments', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/comments?status=rejected')
|
||||
.get('/api/v1/comments?status=REJECTED')
|
||||
.set(passport.inject({roles: ['admin']}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
@@ -131,7 +132,7 @@ describe('/api/v1/comments', () => {
|
||||
|
||||
it('should return all the approved comments', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/comments?status=accepted')
|
||||
.get('/api/v1/comments?status=ACCEPTED')
|
||||
.set(passport.inject({roles: ['admin']}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
@@ -142,7 +143,7 @@ describe('/api/v1/comments', () => {
|
||||
|
||||
it('should return all the new comments', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/comments?status=new')
|
||||
.get('/api/v1/comments?status=NEW')
|
||||
.set(passport.inject({roles: ['admin']}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
@@ -152,7 +153,7 @@ describe('/api/v1/comments', () => {
|
||||
|
||||
it('should return all the flagged comments', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/comments?action_type=flag')
|
||||
.get('/api/v1/comments?action_type=FLAG')
|
||||
.set(passport.inject({roles: ['admin']}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
@@ -162,174 +163,6 @@ describe('/api/v1/comments', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#post', () => {
|
||||
|
||||
let asset_id;
|
||||
let postmod_asset_id;
|
||||
|
||||
beforeEach(() => Promise.all([
|
||||
Asset.findOrCreateByUrl('https://coralproject.net/section/article-is-the-best').then((asset) => {
|
||||
|
||||
// Update the asset id.
|
||||
asset_id = asset.id;
|
||||
}),
|
||||
Asset.findOrCreateByUrl('https://coralproject.net/section/postmod-article-is-the-best').then((asset) => {
|
||||
|
||||
// Update the asset id.
|
||||
postmod_asset_id = asset.id;
|
||||
|
||||
return Asset.overrideSettings(postmod_asset_id, {moderation: 'post'});
|
||||
}),
|
||||
]));
|
||||
|
||||
it('should create a comment', () => {
|
||||
return chai.request(app)
|
||||
.post('/api/v1/comments')
|
||||
.set(passport.inject({roles: []}))
|
||||
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': asset_id, 'parent_id': ''})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
expect(res.body).to.have.property('id');
|
||||
expect(res.body).to.have.property('status', 'premod');
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a comment with a rejected status if it contains a bad word', () => {
|
||||
return chai.request(app).post('/api/v1/comments')
|
||||
.set(passport.inject({roles: []}))
|
||||
.send({'body': 'bad words are the baddest', 'author_id': '123', 'asset_id': asset_id, 'parent_id': ''})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
expect(res.body).to.have.property('id');
|
||||
expect(res.body).to.have.property('status', 'rejected');
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a comment with no status and a flag if it contains a suspected word', () => {
|
||||
return chai.request(app).post('/api/v1/comments')
|
||||
.set(passport.inject({roles: []}))
|
||||
.send({'body': 'suspect words are the most suspicious', 'author_id': '123', 'asset_id': postmod_asset_id, 'parent_id': ''})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
expect(res.body).to.have.property('id');
|
||||
expect(res.body).to.have.property('status', null);
|
||||
|
||||
return Promise.all([
|
||||
res.body,
|
||||
Action.findByType('flag', 'comments')
|
||||
]);
|
||||
})
|
||||
.then(([comment, actions]) => {
|
||||
expect(actions).to.have.length(1);
|
||||
|
||||
let action = actions[0];
|
||||
|
||||
expect(action).to.have.property('item_id', comment.id);
|
||||
expect(action).to.have.property('metadata');
|
||||
expect(action.metadata).to.have.property('field', 'body');
|
||||
expect(action.metadata).to.have.property('details', 'Matched suspect word filters.');
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a comment with a premod status if it\'s asset is has pre-moderation enabled', () => {
|
||||
return Asset
|
||||
.findOrCreateByUrl('https://coralproject.net/article1')
|
||||
.then((asset) => {
|
||||
return Asset
|
||||
.overrideSettings(asset.id, {moderation: 'pre'})
|
||||
.then(() => asset);
|
||||
})
|
||||
.then((asset) => {
|
||||
return chai.request(app).post('/api/v1/comments')
|
||||
.set(passport.inject({roles: []}))
|
||||
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': asset.id, 'parent_id': ''});
|
||||
})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
expect(res.body).to.have.property('id');
|
||||
expect(res.body).to.have.property('asset_id');
|
||||
expect(res.body).to.have.property('status', 'premod');
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a comment with null status if it\'s asset is has post-moderation enabled', () => {
|
||||
return Asset
|
||||
.findOrCreateByUrl('https://coralproject.net/article1')
|
||||
.then((asset) => {
|
||||
return Asset
|
||||
.overrideSettings(asset.id, {moderation: 'post'})
|
||||
.then(() => asset);
|
||||
})
|
||||
.then((asset) => {
|
||||
return chai.request(app).post('/api/v1/comments')
|
||||
.set(passport.inject({roles: []}))
|
||||
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': asset.id, 'parent_id': ''});
|
||||
})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
expect(res.body).to.have.property('id');
|
||||
expect(res.body).to.have.property('asset_id');
|
||||
expect(res.body).to.have.property('status', null);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a rejected comment if the body is above the character count', () => {
|
||||
return Asset
|
||||
.findOrCreateByUrl('https://coralproject.net/article1')
|
||||
.then((asset) => {
|
||||
return Asset
|
||||
.overrideSettings(asset.id, {charCountEnable: true, charCount: 10})
|
||||
.then(() => asset);
|
||||
})
|
||||
.then((asset) => {
|
||||
return chai.request(app).post('/api/v1/comments')
|
||||
.set(passport.inject({roles: []}))
|
||||
.send({'body': 'This is way way way way way too long.', 'author_id': '123', 'asset_id': asset.id, 'parent_id': ''});
|
||||
})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
expect(res.body).to.have.property('id');
|
||||
expect(res.body).to.have.property('asset_id');
|
||||
expect(res.body).to.have.property('status', 'rejected');
|
||||
});
|
||||
});
|
||||
|
||||
it('shouldn\'t create a comment when the asset has expired commenting', () => {
|
||||
return Asset.create({
|
||||
closedAt: new Date().setDate(0),
|
||||
closedMessage: 'tests said expired!'
|
||||
})
|
||||
.then((asset) => {
|
||||
return chai.request(app).post('/api/v1/comments')
|
||||
.set(passport.inject({roles: []}))
|
||||
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': asset.id, 'parent_id': ''});
|
||||
})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(500);
|
||||
})
|
||||
.catch((err) => {
|
||||
expect(err.response.body).to.not.be.null;
|
||||
expect(err.response.body).to.have.property('message');
|
||||
expect(err.response.body.error.metadata.closedMessage).to.be.equal('tests said expired!');
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a comment when the asset has not expired yet', () => {
|
||||
return Asset.create({
|
||||
closedAt: new Date().setDate(32),
|
||||
closedMessage: 'tests said expired!'
|
||||
})
|
||||
.then((asset) => {
|
||||
return chai.request(app).post('/api/v1/comments')
|
||||
.set(passport.inject({roles: []}))
|
||||
.send({'body': 'Something body.', 'author_id': '123', 'asset_id': asset.id, 'parent_id': ''});
|
||||
})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(201);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('/api/v1/comments/:comment_id', () => {
|
||||
@@ -360,21 +193,21 @@ describe('/api/v1/comments/:comment_id', () => {
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
action_type: 'FLAG',
|
||||
item_id: 'abc',
|
||||
item_type: 'comment'
|
||||
item_type: 'COMMENTS'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
action_type: 'LIKE',
|
||||
item_id: 'hij',
|
||||
item_type: 'comment'
|
||||
item_type: 'COMMENTS'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Setting.init(settings).then(() => {
|
||||
return SettingsService.init(settings).then(() => {
|
||||
return Promise.all([
|
||||
Comment.create(comments),
|
||||
User.createLocalUsers(users),
|
||||
Action.create(actions)
|
||||
CommentModel.create(comments),
|
||||
UsersService.createLocalUsers(users),
|
||||
ActionModel.create(actions)
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -400,7 +233,7 @@ describe('/api/v1/comments/:comment_id', () => {
|
||||
.set(passport.inject({roles: ['admin']}))
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(204);
|
||||
return Comment.findById('abc');
|
||||
return CommentsService.findById('abc');
|
||||
})
|
||||
.then((comment) => {
|
||||
expect(comment).to.be.null;
|
||||
@@ -448,15 +281,17 @@ describe('/api/v1/comments/:comment_id/actions', () => {
|
||||
body: 'comment 20',
|
||||
asset_id: 'asset',
|
||||
author_id: '456',
|
||||
status: 'REJECTED',
|
||||
status_history: [{
|
||||
type: 'rejected'
|
||||
type: 'REJECTED'
|
||||
}]
|
||||
}, {
|
||||
id: 'hij',
|
||||
body: 'comment 30',
|
||||
asset_id: '456',
|
||||
status: 'ACCEPTED',
|
||||
status_history: [{
|
||||
type: 'accepted'
|
||||
type: 'ACCEPTED'
|
||||
}]
|
||||
}];
|
||||
|
||||
@@ -471,19 +306,21 @@ describe('/api/v1/comments/:comment_id/actions', () => {
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
action_type: 'FLAG',
|
||||
item_type: 'COMMENTS',
|
||||
item_id: 'abc'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
action_type: 'LIKE',
|
||||
item_type: 'COMMENTS',
|
||||
item_id: 'hij'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Setting.init(settings).then(() => {
|
||||
return SettingsService.init(settings).then(() => {
|
||||
return Promise.all([
|
||||
Comment.create(comments),
|
||||
User.createLocalUsers(users),
|
||||
Action.create(actions)
|
||||
CommentModel.create(comments),
|
||||
UsersService.createLocalUsers(users),
|
||||
ActionModel.create(actions)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,9 +10,9 @@ chai.use(require('chai-http'));
|
||||
|
||||
const Comment = require('../../../../models/comment');
|
||||
const Action = require('../../../../models/action');
|
||||
const User = require('../../../../models/user');
|
||||
const UsersService = require('../../../../services/users');
|
||||
|
||||
const Setting = require('../../../../models/setting');
|
||||
const SettingsService = require('../../../../services/settings');
|
||||
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['banned'], suspect: ['suspect']}};
|
||||
|
||||
describe('/api/v1/queue', () => {
|
||||
@@ -21,26 +21,26 @@ describe('/api/v1/queue', () => {
|
||||
body: 'comment 10',
|
||||
asset_id: 'asset',
|
||||
author_id: '123',
|
||||
status: 'rejected',
|
||||
status: 'REJECTED',
|
||||
status_history: [{
|
||||
type: 'rejected'
|
||||
type: 'REJECTED'
|
||||
}]
|
||||
}, {
|
||||
id: 'def',
|
||||
body: 'comment 20',
|
||||
asset_id: 'asset',
|
||||
author_id: '456',
|
||||
status: 'premod',
|
||||
status: 'PREMOD',
|
||||
status_history: [{
|
||||
type: 'premod'
|
||||
type: 'PREMOD'
|
||||
}]
|
||||
}, {
|
||||
id: 'hij',
|
||||
body: 'comment 30',
|
||||
asset_id: '456',
|
||||
status: 'accepted',
|
||||
status: 'ACCEPTED',
|
||||
status_history: [{
|
||||
type: 'accepted'
|
||||
type: 'ACCEPTED'
|
||||
}]
|
||||
}];
|
||||
|
||||
@@ -55,18 +55,18 @@ describe('/api/v1/queue', () => {
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
action_type: 'FLAG',
|
||||
item_id: 'abc',
|
||||
item_type: 'comment'
|
||||
item_type: 'COMMENTS'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
action_type: 'LIKE',
|
||||
item_id: 'hij',
|
||||
item_type: 'comment'
|
||||
item_type: 'COMMENTS'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Setting.init(settings).then(() => {
|
||||
return User.createLocalUsers(users)
|
||||
return SettingsService.init(settings).then(() => {
|
||||
return UsersService.createLocalUsers(users)
|
||||
.then((u) => {
|
||||
comments[0].author_id = u[0].id;
|
||||
comments[1].author_id = u[1].id;
|
||||
@@ -80,7 +80,7 @@ describe('/api/v1/queue', () => {
|
||||
|
||||
return Promise.all([
|
||||
Action.create(actions),
|
||||
Setting.init(settings)
|
||||
SettingsService.init(settings)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,12 +7,12 @@ const expect = chai.expect;
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const Setting = require('../../../../models/setting');
|
||||
const SettingsService = require('../../../../services/settings');
|
||||
const defaults = {id: '1', moderation: 'pre'};
|
||||
|
||||
describe('/api/v1/settings', () => {
|
||||
|
||||
beforeEach(() => Setting.init(defaults));
|
||||
beforeEach(() => SettingsService.init(defaults));
|
||||
|
||||
describe('#get', () => {
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('/api/v1/settings', () => {
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(204);
|
||||
|
||||
return Setting.retrieve();
|
||||
return SettingsService.retrieve();
|
||||
})
|
||||
.then((settings) => {
|
||||
expect(settings).to.have.property('moderation', 'post');
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
const app = require('../../../../app');
|
||||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
|
||||
// Setup chai.
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const Action = require('../../../../models/action');
|
||||
const User = require('../../../../models/user');
|
||||
const Comment = require('../../../../models/comment');
|
||||
const Asset = require('../../../../models/asset');
|
||||
|
||||
const Setting = require('../../../../models/setting');
|
||||
|
||||
describe('/api/v1/stream', () => {
|
||||
describe('#get', () => {
|
||||
const settings = {
|
||||
id: '1',
|
||||
moderation: 'post',
|
||||
wordlist: {
|
||||
banned: ['banned'],
|
||||
suspect: ['suspect']
|
||||
}
|
||||
};
|
||||
|
||||
const assets = [
|
||||
{
|
||||
url: 'https://example.com/article/1'
|
||||
},
|
||||
{
|
||||
url: 'https://example.com/article/2',
|
||||
settings: {
|
||||
moderation: 'pre'
|
||||
}
|
||||
},
|
||||
{
|
||||
url: 'https://example.com/article/3'
|
||||
}
|
||||
];
|
||||
|
||||
const comments = [{
|
||||
id: 'abc',
|
||||
body: 'comment 10',
|
||||
author_id: '',
|
||||
parent_id: '',
|
||||
status: 'accepted',
|
||||
status_history: [{
|
||||
type: 'accepted'
|
||||
}]
|
||||
}, {
|
||||
id: 'def',
|
||||
body: 'comment 20',
|
||||
author_id: '',
|
||||
parent_id: '',
|
||||
status: null,
|
||||
status_history: []
|
||||
}, {
|
||||
id: 'uio',
|
||||
body: 'comment 30',
|
||||
asset_id: 'asset',
|
||||
author_id: '456',
|
||||
parent_id: '',
|
||||
status: 'accepted',
|
||||
status_history: [{
|
||||
type: 'accepted'
|
||||
}]
|
||||
}, {
|
||||
id: 'hij',
|
||||
body: 'comment 40',
|
||||
asset_id: '456',
|
||||
status: 'rejected',
|
||||
status_history: [{
|
||||
type: 'rejected'
|
||||
}]
|
||||
}, {
|
||||
body: 'comment 50',
|
||||
status: 'premod',
|
||||
status_history: [{
|
||||
type: 'premod'
|
||||
}]
|
||||
}, {
|
||||
body: 'comment 60',
|
||||
status: 'accepted',
|
||||
status_history: [{
|
||||
type: 'accepted'
|
||||
}]
|
||||
}, {
|
||||
body: 'comment 70',
|
||||
status: 'rejected',
|
||||
status_history: [{
|
||||
type: 'rejected'
|
||||
}]
|
||||
}, {
|
||||
body: 'comment 70',
|
||||
status: null,
|
||||
status_history: []
|
||||
}];
|
||||
|
||||
const users = [{
|
||||
displayName: 'Ana',
|
||||
email: 'ana@gmail.com',
|
||||
password: '123456789'
|
||||
}, {
|
||||
displayName: 'Maria',
|
||||
email: 'maria@gmail.com',
|
||||
password: '123456789'
|
||||
}];
|
||||
|
||||
const actions = [{
|
||||
action_type: 'flag',
|
||||
item_id: 'abc'
|
||||
}, {
|
||||
action_type: 'like',
|
||||
item_id: 'hij'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Setting.init(settings)
|
||||
.then(() => Promise.all([
|
||||
User.createLocalUsers(users),
|
||||
Promise.all(assets.map((asset) => Asset.create(asset)))
|
||||
]))
|
||||
.then(([mockUsers, mockAssets]) => {
|
||||
|
||||
// Map the id's over.
|
||||
mockAssets.forEach((asset, i) => {
|
||||
assets[i].id = asset.id;
|
||||
});
|
||||
|
||||
mockUsers.forEach((user, i) => {
|
||||
users[i].id = user.id;
|
||||
});
|
||||
|
||||
comments.forEach((comment, i) => {
|
||||
comments[i].author_id = users[(i % 2) === 0 ? 0 : 1].id;
|
||||
});
|
||||
|
||||
comments[0].asset_id = assets[0].id;
|
||||
comments[1].asset_id = assets[0].id;
|
||||
comments[2].asset_id = assets[1].id;
|
||||
comments[3].asset_id = assets[1].id;
|
||||
comments[4].asset_id = assets[2].id;
|
||||
comments[5].asset_id = assets[2].id;
|
||||
comments[6].asset_id = assets[2].id;
|
||||
comments[7].asset_id = assets[2].id;
|
||||
|
||||
return Promise.all([
|
||||
Comment.create(comments),
|
||||
Action.create(actions)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a stream with comments, users and actions for an existing asset', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/stream')
|
||||
.query({asset_url: assets[0].url})
|
||||
.then(res => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body.assets.length).to.equal(1);
|
||||
expect(res.body.comments.length).to.equal(2);
|
||||
expect(res.body.users.length).to.equal(2);
|
||||
expect(res.body.actions.length).to.equal(1);
|
||||
expect(res.body.settings).to.have.property('moderation', 'post');
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject requests without a scheme in the asset_url', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/stream')
|
||||
.query({asset_url: 'test.com'})
|
||||
.catch((err) => {
|
||||
expect(err).to.have.status(400);
|
||||
expect(err.response.body.message).to.contain('asset_url is invalid');
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge the settings when the asset contains settings to override it with', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/stream')
|
||||
.query({asset_url: assets[1].url})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body.assets).to.have.length(1);
|
||||
expect(res.body.comments).to.have.length(1);
|
||||
expect(res.body.users).to.have.length(1);
|
||||
expect(res.body.settings).to.have.property('moderation', 'pre');
|
||||
expect(res.body.settings).to.not.have.property('wordlist');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not change the previously displayed comments based on moderation state changes', () => {
|
||||
|
||||
let preComments, postComments;
|
||||
|
||||
return chai.request(app)
|
||||
.get('/api/v1/stream')
|
||||
.query({asset_url: assets[2].url})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body.comments.length).to.equal(2);
|
||||
expect(res.body.settings).to.have.property('moderation', 'post');
|
||||
|
||||
preComments = res.body.comments;
|
||||
|
||||
return Asset.overrideSettings(assets[2].id, {moderation: 'pre'});
|
||||
})
|
||||
.then(() => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/stream')
|
||||
.query({asset_url: assets[2].url});
|
||||
})
|
||||
.then((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res.body.comments.length).to.equal(2);
|
||||
expect(res.body.settings).to.have.property('moderation', 'pre');
|
||||
|
||||
postComments = res.body.comments;
|
||||
|
||||
expect(preComments).to.deep.equal(postComments);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -5,21 +5,21 @@ const mailer = require('../../../../services/mailer');
|
||||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
|
||||
const Setting = require('../../../../models/setting');
|
||||
const SettingsService = require('../../../../services/settings');
|
||||
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
|
||||
|
||||
// Setup chai.
|
||||
chai.should();
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const User = require('../../../../models/user');
|
||||
const UsersService = require('../../../../services/users');
|
||||
|
||||
describe('/api/v1/users/:user_id/email/confirm', () => {
|
||||
|
||||
let mockUser;
|
||||
|
||||
beforeEach(() => Setting.init(settings).then(() => {
|
||||
return User.createLocalUser('ana@gmail.com', '123321123', 'Ana');
|
||||
beforeEach(() => SettingsService.init(settings).then(() => {
|
||||
return UsersService.createLocalUser('ana@gmail.com', '123321123', 'Ana');
|
||||
})
|
||||
.then((user) => {
|
||||
mockUser = user;
|
||||
@@ -63,8 +63,8 @@ describe('/api/v1/users/:user_id/actions', () => {
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return Setting.init(settings).then(() => {
|
||||
return User.createLocalUsers(users);
|
||||
return SettingsService.init(settings).then(() => {
|
||||
return UsersService.createLocalUsers(users);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
const Action = require('../../models/action');
|
||||
const ActionModel = require('../../models/action');
|
||||
const ActionsService = require('../../services/actions');
|
||||
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('models.Action', () => {
|
||||
describe('services.ActionsService', () => {
|
||||
let mockActions = [];
|
||||
|
||||
beforeEach(() => Action.create([
|
||||
beforeEach(() => ActionModel.create([
|
||||
{
|
||||
action_type: 'flag',
|
||||
action_type: 'FLAG',
|
||||
item_id: '123',
|
||||
item_type: 'comment',
|
||||
item_type: 'COMMENTS',
|
||||
user_id: 'flagginguserid'
|
||||
},
|
||||
{
|
||||
action_type: 'flag',
|
||||
action_type: 'FLAG',
|
||||
item_id: '456',
|
||||
item_type: 'comment'
|
||||
item_type: 'COMMENTS'
|
||||
},
|
||||
{
|
||||
action_type: 'flag',
|
||||
action_type: 'FLAG',
|
||||
item_id: '123',
|
||||
item_type: 'comment'
|
||||
item_type: 'COMMENTS'
|
||||
},
|
||||
{
|
||||
action_type: 'like',
|
||||
action_type: 'LIKE',
|
||||
item_id: '123',
|
||||
item_type: 'comment'
|
||||
item_type: 'COMMENTS'
|
||||
}
|
||||
]).then((actions) => {
|
||||
mockActions = actions;
|
||||
@@ -32,16 +34,16 @@ describe('models.Action', () => {
|
||||
|
||||
describe('#findById()', () => {
|
||||
it('should find an action by id', () => {
|
||||
return Action.findById(mockActions[0].id).then((result) => {
|
||||
return ActionsService.findById(mockActions[0].id).then((result) => {
|
||||
expect(result).to.not.be.null;
|
||||
expect(result).to.have.property('action_type', 'flag');
|
||||
expect(result).to.have.property('action_type', 'FLAG');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#findByItemIdArray()', () => {
|
||||
it('should find an array of actions from an array of item_ids', () => {
|
||||
return Action.findByItemIdArray(['123', '456']).then((result) => {
|
||||
return ActionsService.findByItemIdArray(['123', '456']).then((result) => {
|
||||
expect(result).to.have.length(4);
|
||||
});
|
||||
});
|
||||
@@ -49,46 +51,48 @@ describe('models.Action', () => {
|
||||
|
||||
describe('#getActionSummaries()', () => {
|
||||
it('should return properly formatted summaries from an array of item_ids', () => {
|
||||
return Action.getActionSummaries(['123', '789']).then((summaries) => {
|
||||
expect(summaries).to.have.length(2);
|
||||
return ActionsService
|
||||
.getActionSummaries(['123', '789'])
|
||||
.then((summaries) => {
|
||||
expect(summaries).to.have.length(2);
|
||||
|
||||
expect(summaries).to.deep.include({
|
||||
action_type: 'like',
|
||||
count: 1,
|
||||
item_id: '123',
|
||||
item_type: 'comment',
|
||||
current_user: null
|
||||
});
|
||||
expect(summaries).to.deep.include({
|
||||
action_type: 'LIKE',
|
||||
count: 1,
|
||||
item_id: '123',
|
||||
item_type: 'COMMENTS',
|
||||
current_user: null
|
||||
});
|
||||
|
||||
expect(summaries).to.deep.include({
|
||||
action_type: 'flag',
|
||||
count: 2,
|
||||
item_id: '123',
|
||||
item_type: 'comment',
|
||||
current_user: null
|
||||
expect(summaries).to.deep.include({
|
||||
action_type: 'FLAG',
|
||||
count: 2,
|
||||
item_id: '123',
|
||||
item_type: 'COMMENTS',
|
||||
current_user: null
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should include a current user when one is passed', () => {
|
||||
return Action
|
||||
return ActionsService
|
||||
.getActionSummaries(['123'], 'flagginguserid')
|
||||
.then((summaries) => {
|
||||
expect(summaries).to.have.length(2);
|
||||
|
||||
let summary = summaries.find((s) => s.item_id === '123' && s.action_type === 'flag');
|
||||
let summary = summaries.find((s) => s.item_id === '123' && s.action_type === 'FLAG');
|
||||
|
||||
expect(summary).to.not.be.undefined;
|
||||
expect(summary.current_user).to.not.be.null;
|
||||
expect(summary.current_user).to.have.property('item_id', '123');
|
||||
expect(summary.current_user).to.have.property('item_type', 'comment');
|
||||
expect(summary.current_user).to.have.property('item_type', 'COMMENTS');
|
||||
expect(summary.current_user).to.have.property('user_id', 'flagginguserid');
|
||||
expect(summary.current_user).to.have.property('action_type', 'flag');
|
||||
expect(summary.current_user).to.have.property('action_type', 'FLAG');
|
||||
});
|
||||
});
|
||||
|
||||
it('should not include a current user when one is passed for a user that doesn\'t have an action', () => {
|
||||
return Action
|
||||
return ActionsService
|
||||
.getActionSummaries(['123'], 'flagginguserid2')
|
||||
.then((summaries) => {
|
||||
expect(summaries).to.have.length(2);
|
||||
@@ -1,4 +1,5 @@
|
||||
const Asset = require('../../models/asset');
|
||||
const AssetModel = require('../../models/asset');
|
||||
const AssetsService = require('../../services/assets');
|
||||
|
||||
const chai = require('chai');
|
||||
const expect = chai.expect;
|
||||
@@ -6,16 +7,16 @@ const expect = chai.expect;
|
||||
// Use the chai should.
|
||||
chai.should();
|
||||
|
||||
describe('models.Asset', () => {
|
||||
describe('services.AssetsService', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
const defaults = {url:'http://test.com'};
|
||||
return Asset.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true});
|
||||
return AssetModel.update({id: '1'}, {$setOnInsert: defaults}, {upsert: true});
|
||||
});
|
||||
|
||||
describe('#findById', ()=> {
|
||||
it('should find an asset by the id', () => {
|
||||
return Asset.findById(1)
|
||||
return AssetsService.findById(1)
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('url')
|
||||
.and.to.equal('http://test.com');
|
||||
@@ -24,17 +25,19 @@ describe('models.Asset', () => {
|
||||
});
|
||||
|
||||
describe('#findByUrl', ()=> {
|
||||
beforeEach(() => Asset.findOrCreateByUrl('http://test.com'));
|
||||
beforeEach(() => AssetsService.findOrCreateByUrl('http://test.com'));
|
||||
|
||||
it('should find an asset by a url', () => {
|
||||
return Asset.findByUrl('http://test.com')
|
||||
return AssetsService
|
||||
.findByUrl('http://test.com')
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('url', 'http://test.com');
|
||||
});
|
||||
});
|
||||
|
||||
it('should return null when a url does not exist', () => {
|
||||
return Asset.findByUrl('http://new.test.com')
|
||||
return AssetsService
|
||||
.findByUrl('http://new.test.com')
|
||||
.then((asset) => {
|
||||
expect(asset).to.be.null;
|
||||
});
|
||||
@@ -43,7 +46,8 @@ describe('models.Asset', () => {
|
||||
|
||||
describe('#findOrCreateByUrl', ()=> {
|
||||
it('should find an asset by a url', () => {
|
||||
return Asset.findOrCreateByUrl('http://test.com')
|
||||
return AssetsService
|
||||
.findOrCreateByUrl('http://test.com')
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('url')
|
||||
.and.to.equal('http://test.com');
|
||||
@@ -51,7 +55,8 @@ describe('models.Asset', () => {
|
||||
});
|
||||
|
||||
it('should return a new asset when the url does not exist', () => {
|
||||
return Asset.findOrCreateByUrl('http://new.test.com')
|
||||
return AssetsService
|
||||
.findOrCreateByUrl('http://new.test.com')
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('id')
|
||||
.and.to.not.equal(1);
|
||||
@@ -61,16 +66,16 @@ describe('models.Asset', () => {
|
||||
|
||||
describe('#overrideSettings', () => {
|
||||
it('should update the settings', () => {
|
||||
return Asset
|
||||
return AssetsService
|
||||
.findOrCreateByUrl('https://override.test.com/asset')
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('settings');
|
||||
expect(asset.settings).to.be.null;
|
||||
|
||||
return Asset.overrideSettings(asset.id, {moderation: 'pre'});
|
||||
return AssetsService.overrideSettings(asset.id, {moderation: 'pre'});
|
||||
})
|
||||
.then(() => {
|
||||
return Asset.findOrCreateByUrl('https://override.test.com/asset');
|
||||
return AssetsService.findOrCreateByUrl('https://override.test.com/asset');
|
||||
})
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('settings');
|
||||
@@ -82,7 +87,8 @@ describe('models.Asset', () => {
|
||||
|
||||
describe('#findOrCreateByUrl', ()=> {
|
||||
it('should find an asset by a url', () => {
|
||||
return Asset.findOrCreateByUrl('http://test.com')
|
||||
return AssetsService
|
||||
.findOrCreateByUrl('http://test.com')
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('url')
|
||||
.and.to.equal('http://test.com');
|
||||
@@ -90,7 +96,8 @@ describe('models.Asset', () => {
|
||||
});
|
||||
|
||||
it('should return a new asset when the url does not exist', () => {
|
||||
return Asset.findOrCreateByUrl('http://new.test.com')
|
||||
return AssetsService
|
||||
.findOrCreateByUrl('http://new.test.com')
|
||||
.then((asset) => {
|
||||
expect(asset).to.have.property('id')
|
||||
.and.to.not.equal(1);
|
||||
@@ -0,0 +1,259 @@
|
||||
const CommentModel = require('../../models/comment');
|
||||
const ActionModel = require('../../models/action');
|
||||
|
||||
const ActionsService = require('../../services/actions');
|
||||
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 expect = require('chai').expect;
|
||||
|
||||
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 users = [{
|
||||
email: 'stampi@gmail.com',
|
||||
displayName: 'Stampi',
|
||||
password: '1Coral!!'
|
||||
}, {
|
||||
email: 'sockmonster@gmail.com',
|
||||
displayName: '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'
|
||||
}];
|
||||
|
||||
beforeEach(() => {
|
||||
return SettingsService.init(settings).then(() => {
|
||||
return Promise.all([
|
||||
CommentModel.create(comments),
|
||||
UsersService.createLocalUsers(users),
|
||||
ActionModel.create(actions)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#publicCreate()', () => {
|
||||
|
||||
it('creates a new comment', () => {
|
||||
return CommentsService
|
||||
.publicCreate({
|
||||
body: 'This is a comment!',
|
||||
status: 'ACCEPTED'
|
||||
}).then((c) => {
|
||||
expect(c).to.not.be.null;
|
||||
expect(c.id).to.not.be.null;
|
||||
expect(c.id).to.be.uuid;
|
||||
expect(c.status).to.be.equal('ACCEPTED');
|
||||
});
|
||||
});
|
||||
|
||||
it('creates many new comments', () => {
|
||||
return CommentsService
|
||||
.publicCreate([{
|
||||
body: 'This is a comment!',
|
||||
status: 'ACCEPTED'
|
||||
}, {
|
||||
body: 'This is another comment!'
|
||||
}, {
|
||||
body: 'This is a rejected comment!',
|
||||
status: 'REJECTED'
|
||||
}]).then(([c1, c2, c3]) => {
|
||||
expect(c1).to.not.be.null;
|
||||
expect(c1.id).to.be.uuid;
|
||||
expect(c1.status).to.be.equal('ACCEPTED');
|
||||
|
||||
expect(c2).to.not.be.null;
|
||||
expect(c2.id).to.be.uuid;
|
||||
expect(c2.status).to.be.null;
|
||||
|
||||
expect(c3).to.not.be.null;
|
||||
expect(c3.id).to.be.uuid;
|
||||
expect(c3.status).to.be.equal('REJECTED');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#findById()', () => {
|
||||
|
||||
it('should find a comment by id', () => {
|
||||
return CommentsService
|
||||
.findById('1')
|
||||
.then((result) => {
|
||||
expect(result).to.not.be.null;
|
||||
expect(result).to.have.property('body', 'comment 10');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#findByAssetId()', () => {
|
||||
|
||||
it('should find an array of all comments by asset id', () => {
|
||||
return CommentsService
|
||||
.findByAssetId('123')
|
||||
.then((result) => {
|
||||
expect(result).to.have.length(3);
|
||||
result.sort((a, b) => {
|
||||
if (a.body < b.body) {return -1;}
|
||||
else {return 1;}
|
||||
});
|
||||
expect(result[0]).to.have.property('body', 'comment 10');
|
||||
expect(result[1]).to.have.property('body', 'comment 20');
|
||||
expect(result[2]).to.have.property('body', 'comment 40');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#moderationQueue()', () => {
|
||||
|
||||
it('should find an array of new comments to moderate when pre-moderation', () => {
|
||||
return CommentsService
|
||||
.moderationQueue('PREMOD')
|
||||
.then((result) => {
|
||||
expect(result).to.not.be.null;
|
||||
expect(result).to.have.lengthOf(2);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#removeAction', () => {
|
||||
|
||||
it('should remove an action', () => {
|
||||
return CommentsService
|
||||
.removeAction('3', '123', 'flag')
|
||||
.then(() => {
|
||||
return ActionsService.findByItemIdArray(['123']);
|
||||
})
|
||||
.then((actions) => {
|
||||
expect(actions.length).to.equal(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#findByUserId', () => {
|
||||
it('should return all comments if admin', () => {
|
||||
return CommentsService
|
||||
.findByUserId('456', true)
|
||||
.then(comments => {
|
||||
expect(comments).to.have.length(4);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not return premod and rejected comments if not admin', () => {
|
||||
return CommentsService
|
||||
.findByUserId('456')
|
||||
.then(comments => {
|
||||
expect(comments).to.have.length(1);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#changeStatus', () => {
|
||||
|
||||
it('should change the status of a comment from no status', () => {
|
||||
let comment_id = comments[0].id;
|
||||
|
||||
return CommentsService.findById(comment_id)
|
||||
.then((c) => {
|
||||
expect(c.status).to.be.null;
|
||||
|
||||
return CommentsService.pushStatus(comment_id, 'REJECTED', '123');
|
||||
})
|
||||
.then(() => CommentsService.findById(comment_id))
|
||||
.then((c) => {
|
||||
expect(c).to.have.property('status');
|
||||
expect(c.status).to.equal('REJECTED');
|
||||
expect(c.status_history).to.have.length(1);
|
||||
expect(c.status_history[0]).to.have.property('type', 'REJECTED');
|
||||
expect(c.status_history[0]).to.have.property('assigned_by', '123');
|
||||
});
|
||||
});
|
||||
|
||||
it('should change the status of a comment from accepted', () => {
|
||||
return CommentsService.pushStatus(comments[1].id, 'REJECTED', '123')
|
||||
.then(() => CommentsService.findById(comments[1].id))
|
||||
.then((c) => {
|
||||
expect(c).to.have.property('status_history');
|
||||
expect(c).to.have.property('status');
|
||||
expect(c.status).to.equal('REJECTED');
|
||||
expect(c.status_history).to.have.length(2);
|
||||
expect(c.status_history[0]).to.have.property('type', 'ACCEPTED');
|
||||
expect(c.status_history[0]).to.have.property('assigned_by', null);
|
||||
|
||||
expect(c.status_history[1]).to.have.property('type', 'REJECTED');
|
||||
expect(c.status_history[1]).to.have.property('assigned_by', '123');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
describe('scraper: services', () => {
|
||||
describe('services.scraper', () => {
|
||||
describe('#create', () => {
|
||||
it('should create a new kue job');
|
||||
});
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
const Setting = require('../../models/setting');
|
||||
const SettingsService = require('../../services/settings');
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('models.Setting', () => {
|
||||
describe('services.SettingsService', () => {
|
||||
|
||||
beforeEach(() => Setting.init({moderation: 'pre', wordlist: ['donut']}));
|
||||
beforeEach(() => SettingsService.init({moderation: 'pre', wordlist: ['donut']}));
|
||||
|
||||
describe('#retrieve()', () => {
|
||||
it('should have a moderation field defined', () => {
|
||||
return Setting.retrieve().then(settings => {
|
||||
return SettingsService.retrieve().then(settings => {
|
||||
expect(settings).to.have.property('moderation').and.to.equal('pre');
|
||||
});
|
||||
});
|
||||
|
||||
it('should have two infoBox fields defined', () => {
|
||||
return Setting.retrieve().then(settings => {
|
||||
return SettingsService.retrieve().then(settings => {
|
||||
expect(settings).to.have.property('infoBoxEnable').and.to.equal(false);
|
||||
expect(settings).to.have.property('infoBoxContent').and.to.equal('');
|
||||
});
|
||||
@@ -23,7 +23,7 @@ describe('models.Setting', () => {
|
||||
describe('#update()', () => {
|
||||
it('should update the settings with a passed object', () => {
|
||||
const mockSettings = {moderation: 'post', infoBoxEnable: true, infoBoxContent: 'yeah'};
|
||||
return Setting.update(mockSettings).then(updatedSettings => {
|
||||
return SettingsService.update(mockSettings).then(updatedSettings => {
|
||||
expect(updatedSettings).to.be.an('object');
|
||||
expect(updatedSettings).to.have.property('moderation').and.to.equal('post');
|
||||
expect(updatedSettings).to.have.property('infoBoxEnable', true);
|
||||
@@ -34,7 +34,7 @@ describe('models.Setting', () => {
|
||||
|
||||
describe('#get', () => {
|
||||
it('should return the moderation settings', () => {
|
||||
return Setting.retrieve().then(({moderation}) => {
|
||||
return SettingsService.retrieve().then(({moderation}) => {
|
||||
expect(moderation).not.to.be.null;
|
||||
});
|
||||
});
|
||||
@@ -42,7 +42,7 @@ describe('models.Setting', () => {
|
||||
|
||||
describe('#merge', () => {
|
||||
it('should merge a settings object and its overrides', () => {
|
||||
return Setting
|
||||
return SettingsService
|
||||
.retrieve()
|
||||
.then((settings) => {
|
||||
let ovrSett = {moderation: 'post'};
|
||||
@@ -1,16 +1,16 @@
|
||||
const User = require('../../models/user');
|
||||
const Comment = require('../../models/comment');
|
||||
const Setting = require('../../models/setting');
|
||||
const UsersService = require('../../services/users');
|
||||
const SettingsService = require('../../services/settings');
|
||||
|
||||
const expect = require('chai').expect;
|
||||
|
||||
describe('models.User', () => {
|
||||
describe('services.UsersService', () => {
|
||||
|
||||
let mockUsers;
|
||||
beforeEach(() => {
|
||||
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
|
||||
|
||||
return Setting.init(settings).then(() => {
|
||||
return User.createLocalUsers([{
|
||||
return SettingsService.init(settings).then(() => {
|
||||
return UsersService.createLocalUsers([{
|
||||
email: 'stampi@gmail.com',
|
||||
displayName: 'Stampi',
|
||||
password: '1Coral!-'
|
||||
@@ -30,11 +30,10 @@ describe('models.User', () => {
|
||||
|
||||
describe('#findById()', () => {
|
||||
it('should find a user by id', () => {
|
||||
return User
|
||||
return UsersService
|
||||
.findById(mockUsers[0].id)
|
||||
.then((user) => {
|
||||
expect(user).to.have.property('displayName')
|
||||
.and.to.equal('stampi');
|
||||
expect(user).to.have.property('displayName', 'stampi');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -42,7 +41,7 @@ describe('models.User', () => {
|
||||
describe('#findByIdArray()', () => {
|
||||
it('should find an array of users from an array of ids', () => {
|
||||
const ids = mockUsers.map((user) => user.id);
|
||||
return User.findByIdArray(ids).then((result) => {
|
||||
return UsersService.findByIdArray(ids).then((result) => {
|
||||
expect(result).to.have.length(3);
|
||||
});
|
||||
});
|
||||
@@ -51,15 +50,14 @@ describe('models.User', () => {
|
||||
describe('#findPublicByIdArray()', () => {
|
||||
it('should find an array of users from an array of ids', () => {
|
||||
const ids = mockUsers.map((user) => user.id);
|
||||
return User.findPublicByIdArray(ids).then((result) => {
|
||||
return UsersService.findPublicByIdArray(ids).then((result) => {
|
||||
expect(result).to.have.length(3);
|
||||
const sorted = result.sort((a, b) => {
|
||||
if(a.displayName < b.displayName) {return -1;}
|
||||
if(a.displayName > b.displayName) {return 1;}
|
||||
return 0;
|
||||
});
|
||||
expect(sorted[0]).to.have.property('displayName')
|
||||
.and.to.equal('marvel');
|
||||
expect(sorted[0]).to.have.property('displayName', 'marvel');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -67,7 +65,7 @@ describe('models.User', () => {
|
||||
describe('#findLocalUser', () => {
|
||||
|
||||
it('should find a user when we give the right credentials', () => {
|
||||
return User
|
||||
return UsersService
|
||||
.findLocalUser(mockUsers[0].profiles[0].id, '1Coral!-')
|
||||
.then((user) => {
|
||||
expect(user).to.have.property('displayName')
|
||||
@@ -76,7 +74,7 @@ describe('models.User', () => {
|
||||
});
|
||||
|
||||
it('should not find the user when we give the wrong credentials', () => {
|
||||
return User
|
||||
return UsersService
|
||||
.findLocalUser(mockUsers[0].profiles[0].id, '1Coral!-<nope>')
|
||||
.then((user) => {
|
||||
expect(user).to.equal(false);
|
||||
@@ -87,9 +85,9 @@ describe('models.User', () => {
|
||||
|
||||
describe('#createLocalUser', () => {
|
||||
it('should not create a user with duplicate display name', () => {
|
||||
return User.createLocalUsers([{
|
||||
return UsersService.createLocalUsers([{
|
||||
email: 'otrostampi@gmail.com',
|
||||
displayName: 'Stampi',
|
||||
displayName: 'StampiTheSecond',
|
||||
password: '1Coralito!'
|
||||
}])
|
||||
.then((user) => {
|
||||
@@ -104,7 +102,7 @@ describe('models.User', () => {
|
||||
describe('#createEmailConfirmToken', () => {
|
||||
|
||||
it('should create a token for a valid user', () => {
|
||||
return User
|
||||
return UsersService
|
||||
.createEmailConfirmToken(mockUsers[0].id, mockUsers[0].profiles[0].id)
|
||||
.then((token) => {
|
||||
expect(token).to.not.be.null;
|
||||
@@ -112,15 +110,15 @@ describe('models.User', () => {
|
||||
});
|
||||
|
||||
it('should not create a token for a user already verified', () => {
|
||||
return User
|
||||
return UsersService
|
||||
.createEmailConfirmToken(mockUsers[0].id, mockUsers[0].profiles[0].id)
|
||||
.then((token) => {
|
||||
expect(token).to.not.be.null;
|
||||
|
||||
return User.verifyEmailConfirmation(token);
|
||||
return UsersService.verifyEmailConfirmation(token);
|
||||
})
|
||||
.then(() => {
|
||||
return User.createEmailConfirmToken(mockUsers[0].id, mockUsers[0].profiles[0].id);
|
||||
return UsersService.createEmailConfirmToken(mockUsers[0].id, mockUsers[0].profiles[0].id);
|
||||
})
|
||||
.catch((err) => {
|
||||
expect(err).to.have.property('message', 'email address already confirmed');
|
||||
@@ -132,17 +130,17 @@ describe('models.User', () => {
|
||||
describe('#verifyEmailConfirmation', () => {
|
||||
|
||||
it('should correctly validate a valid token', () => {
|
||||
return User
|
||||
return UsersService
|
||||
.createEmailConfirmToken(mockUsers[0].id, mockUsers[0].profiles[0].id)
|
||||
.then((token) => {
|
||||
expect(token).to.not.be.null;
|
||||
|
||||
return User.verifyEmailConfirmation(token);
|
||||
return UsersService.verifyEmailConfirmation(token);
|
||||
});
|
||||
});
|
||||
|
||||
it('should correctly reject an invalid token', () => {
|
||||
return User
|
||||
return UsersService
|
||||
.verifyEmailConfirmation('cats')
|
||||
.catch((err) => {
|
||||
expect(err).to.not.be.null;
|
||||
@@ -150,15 +148,15 @@ describe('models.User', () => {
|
||||
});
|
||||
|
||||
it('should update the user model when verification is complete', () => {
|
||||
return User
|
||||
return UsersService
|
||||
.createEmailConfirmToken(mockUsers[0].id, mockUsers[0].profiles[0].id)
|
||||
.then((token) => {
|
||||
expect(token).to.not.be.null;
|
||||
|
||||
return User.verifyEmailConfirmation(token);
|
||||
return UsersService.verifyEmailConfirmation(token);
|
||||
})
|
||||
.then(() => {
|
||||
return User.findById(mockUsers[0].id);
|
||||
return UsersService.findById(mockUsers[0].id);
|
||||
})
|
||||
.then((user) => {
|
||||
expect(user.profiles[0]).to.have.property('metadata');
|
||||
@@ -171,85 +169,42 @@ describe('models.User', () => {
|
||||
|
||||
describe('#setStatus', () => {
|
||||
it('should set the status to active', () => {
|
||||
return User
|
||||
.setStatus(mockUsers[0].id, 'active')
|
||||
.then(() => {
|
||||
User.findById(mockUsers[0].id)
|
||||
.then((user) => {
|
||||
expect(user).to.have.property('status')
|
||||
.and.to.equal('active');
|
||||
});
|
||||
return UsersService
|
||||
.setStatus(mockUsers[0].id, 'ACTIVE')
|
||||
.then(() => UsersService.findById(mockUsers[0].id))
|
||||
.then((user) => {
|
||||
expect(user).to.have.property('status', 'ACTIVE');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#ban', () => {
|
||||
|
||||
let mockComment;
|
||||
|
||||
beforeEach(() => {
|
||||
return Comment.create([
|
||||
{
|
||||
body: 'testing the comment for that user if it is rejected.',
|
||||
id: mockUsers[0].id
|
||||
}
|
||||
])
|
||||
.then(([comment]) => {
|
||||
mockComment = comment;
|
||||
});
|
||||
});
|
||||
|
||||
it('should set the status to banned', () => {
|
||||
return User
|
||||
.setStatus(mockUsers[0].id, 'banned', mockComment.id)
|
||||
.then(() => {
|
||||
return User.findById(mockUsers[0].id);
|
||||
})
|
||||
return UsersService
|
||||
.setStatus(mockUsers[0].id, 'BANNED')
|
||||
.then(() => UsersService.findById(mockUsers[0].id))
|
||||
.then((user) => {
|
||||
expect(user).to.have.property('status')
|
||||
.and.to.equal('banned');
|
||||
});
|
||||
});
|
||||
|
||||
it('should set the comment to rejected', () => {
|
||||
return User
|
||||
.setStatus(mockUsers[0].id, 'banned', mockComment.id)
|
||||
.then(() => {
|
||||
return Comment.findById(mockComment.id);
|
||||
})
|
||||
.then((comment) => {
|
||||
expect(comment).to.have.property('status')
|
||||
.and.to.equal('rejected');
|
||||
expect(user).to.have.property('status', 'BANNED');
|
||||
});
|
||||
});
|
||||
|
||||
it('should still disable and ban the user if there is no comment', () => {
|
||||
return User
|
||||
.setStatus(mockUsers[0].id, 'banned', '')
|
||||
.then(() => User.findById(mockUsers[0].id))
|
||||
return UsersService
|
||||
.setStatus(mockUsers[0].id, 'BANNED')
|
||||
.then(() => UsersService.findById(mockUsers[0].id))
|
||||
.then((user) => {
|
||||
expect(user).to.have.property('status', 'banned');
|
||||
expect(user).to.have.property('status', 'BANNED');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#unban', () => {
|
||||
let mockComment;
|
||||
beforeEach(() => {
|
||||
return Promise.all([
|
||||
Comment.create([{body: 'testing the comment for that user if it is rejected.', id: mockUsers[0].id}])
|
||||
])
|
||||
.then((comment) => {
|
||||
mockComment = comment;
|
||||
});
|
||||
});
|
||||
|
||||
it('should set the status to active', () => {
|
||||
return User
|
||||
.setStatus(mockUsers[0].id, 'active', mockComment.id)
|
||||
.then(() => User.findById(mockUsers[0].id))
|
||||
return UsersService
|
||||
.setStatus(mockUsers[0].id, 'ACTIVE')
|
||||
.then(() => UsersService.findById(mockUsers[0].id))
|
||||
.then((user) => {
|
||||
expect(user).to.have.property('status', 'active');
|
||||
expect(user).to.have.property('status', 'ACTIVE');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,9 @@
|
||||
const expect = require('chai').expect;
|
||||
const Errors = require('../../errors');
|
||||
const Wordlist = require('../../services/wordlist');
|
||||
const Setting = require('../../models/setting');
|
||||
const SettingsService = require('../../services/settings');
|
||||
|
||||
describe('wordlist: services', () => {
|
||||
describe('services.Wordlist', () => {
|
||||
|
||||
const wordlists = {
|
||||
banned: [
|
||||
@@ -19,7 +19,7 @@ describe('wordlist: services', () => {
|
||||
let wordlist = new Wordlist();
|
||||
const settings = {id: '1', moderation: 'pre', wordlist: {banned: ['bad words'], suspect: ['suspect words']}};
|
||||
|
||||
beforeEach(() => Setting.init(settings));
|
||||
beforeEach(() => SettingsService.init(settings));
|
||||
|
||||
describe('#init', () => {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user