diff --git a/models/action.js b/models/action.js index 13b1c5494..ed18e48c5 100644 --- a/models/action.js +++ b/models/action.js @@ -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, { diff --git a/routes/api/user/index.js b/routes/api/user/index.js index 1a4548164..f99433fcc 100644 --- a/routes/api/user/index.js +++ b/routes/api/user/index.js @@ -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); }) diff --git a/tests/routes/api/user/index.js b/tests/routes/api/user/index.js new file mode 100644 index 000000000..78030049b --- /dev/null +++ b/tests/routes/api/user/index.js @@ -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'); + }); + }); + }); +});