Moved markPMSRead to common.ops. Added tests

This commit is contained in:
Keith Holliday
2016-05-09 09:02:55 -05:00
parent c88cae4ddb
commit a92359e119
8 changed files with 47 additions and 11 deletions

View File

@@ -171,5 +171,6 @@
"pushDeviceAlreadyAdded": "The user already has the push device",
"resetComplete": "Reset completed",
"lvl10ChangeClass": "To change class you must be at least level 10.",
"equipmentAlreadyOwned": "You already own that piece of equipment"
"equipmentAlreadyOwned": "You already own that piece of equipment",
"pmsMarkedRead": "Your private messages have been marked as read"
}

View File

@@ -147,6 +147,7 @@ import deletePM from './ops/deletePM';
import reroll from './ops/reroll';
import addPushDevice from './ops/addPushDevice';
import reset from './ops/reset';
import markPmsRead from './ops/markPmsRead';
api.ops = {
scoreTask,
@@ -187,6 +188,7 @@ api.ops = {
reroll,
addPushDevice,
reset,
markPmsRead,
};
/*
@@ -288,6 +290,7 @@ api.wrap = function wrapUser (user, main = true) {
readCard: _.partial(importedOps.readCard, user),
openMysteryItem: _.partial(importedOps.openMysteryItem, user),
score: _.partial(importedOps.scoreTask, user),
markPmsRead: _.partial(importedOps.markPmsRead, user),
};
}

View File

@@ -46,6 +46,8 @@ import allocate from './allocate';
import readCard from './readCard';
import openMysteryItem from './openMysteryItem';
import scoreTask from './scoreTask';
import markPmsRead from './markPmsRead';
module.exports = {
update,
@@ -96,4 +98,5 @@ module.exports = {
readCard,
openMysteryItem,
scoreTask,
markPmsRead,
};

View File

@@ -0,0 +1,14 @@
import i18n from '../i18n';
module.exports = function markPmsRead (user, req = {}) {
user.inbox.newMessages = 0;
if (req.v2 === true) {
return user;
} else {
return [
user.inbox.newMessages,
i18n.t('pmsMarkedRead'),
];
}
};

View File

@@ -0,0 +1,22 @@
import {
generateUser,
} from '../../../../helpers/api-integration/v3';
describe('POST /user/mark-pms-read', () => {
let user;
beforeEach(async () => {
user = await generateUser();
});
// More tests in common code unit tests
it('marks user\'s private messages as read', async () => {
await user.update({
'inbox.newMessages': 1,
});
let res = await user.post('/user/mark-pms-read');
await user.sync();
expect(user.inbox.newMessages).to.equal(0);
});
});

View File

@@ -92,7 +92,6 @@ function($scope, $rootScope, User, $http, Notification, ApiUrl, Social) {
$scope.addHourglass = function(){
User.addHourglass();
//User.log({});
};
$scope.addGold = function(){

View File

@@ -199,13 +199,7 @@ angular.module('habitrpg')
},
clearNewMessages: function () {
$http({
method: "POST",
url: 'api/v3/user/mark-pms-read',
})
.then(function (response) {
sync();
})
callOpsFunctionAndRequest('markPmsRead', 'mark-pms-read', "POST");
},
clearPMs: function () {

View File

@@ -1189,9 +1189,9 @@ api.markPmsRead = {
url: '/user/mark-pms-read',
async handler (req, res) {
let user = res.locals.user;
user.inbox.newMessages = 0;
let markPmsResponse = common.ops.markPmsRead(user, req);
await user.save();
res.respond(200, user.inbox.newMessages);
res.respond(200, markPmsResponse);
},
};