Addressing null item_id in user flagging.

This commit is contained in:
David Jay
2016-12-09 15:27:11 -05:00
parent bf01543a88
commit 922fc630a4
3 changed files with 46 additions and 10 deletions
+1 -9
View File
@@ -37,15 +37,7 @@ ActionSchema.statics.findById = function(id) {
* @param {String} action the new action to the comment
* @return {Promise}
*/
ActionSchema.statics.insertUserAction = ({item_id, item_type, user_id, action_type, field, detail}) => {
const action = {
item_id,
item_type,
user_id,
action_type,
field,
detail
};
ActionSchema.statics.insertUserAction = (action) => {
// Create/Update the action.
return Action.findOneAndUpdate(action, action, {
+1 -1
View File
@@ -158,7 +158,7 @@ router.post('/:user_id/actions', authorization.needed(), (req, res, next) => {
} = req.body;
User
.addAction(req.params.comment_id, req.user.id, action_type, field, detail)
.addAction(req.params.user_id, req.user.id, action_type, field, detail)
.then((action) => {
res.status(201).json(action);
})
+44
View File
@@ -0,0 +1,44 @@
const passport = require('../../../passport');
const app = require('../../../../app');
const chai = require('chai');
const expect = chai.expect;
// Setup chai.
chai.should();
chai.use(require('chai-http'));
const User = require('../../../../models/user');
describe('/api/v1/user/:user_id/actions', () => {
const users = [{
displayName: 'Ana',
email: 'ana@gmail.com',
password: '123'
}, {
displayName: 'Maria',
email: 'maria@gmail.com',
password: '123'
}];
beforeEach(() => {
return User.createLocalUsers(users);
});
describe('#post', () => {
it('it should update actions', () => {
return chai.request(app)
.post('/api/v1/user/abc/actions')
.set(passport.inject({id: '456', roles: ['admin']}))
.send({'action_type': 'flag', 'detail': 'Bio is too awesome.'})
.then((res) => {
expect(res).to.have.status(201);
expect(res).to.have.body;
expect(res.body).to.have.property('action_type', 'flag');
expect(res.body).to.have.property('detail', 'Bio is too awesome.');
expect(res.body).to.have.property('item_id', 'abc');
});
});
});
});