Merge pull request #7189 from TheHollidayInn/api-v3-fixes

Api v3 fixes
This commit is contained in:
Matteo Pagliazzi
2016-05-12 09:37:22 +02:00
12 changed files with 84 additions and 84 deletions
@@ -109,11 +109,12 @@ describe('cron middleware', () => {
it('should call next is user was not modified after cron', (done) => {
let hpBefore = user.stats.hp;
user.lastCron = moment(new Date()).subtract({days: 2});
generateDaily(user);
cronMiddleware(req, res, () => {
expect(user.stats.hp).to.be.equal(hpBefore);
done();
user.save().then(function () {
cronMiddleware(req, res, function () {
expect(hpBefore).to.equal(user.stats.hp);
done();
});
});
});
+2 -8
View File
@@ -93,12 +93,9 @@ describe('Groups Controller', function() {
members: [user._id]
});
var myGuilds = sandbox.stub(groups, "myGuilds", function() {
return [guild];
});
user.guilds = [guild._id];
expect(scope.isMemberOfGroup(user._id, guild)).to.be.ok;
expect(myGuilds).to.be.called;
});
it('does not return true if guild is not included in myGuilds call', function(){
@@ -109,12 +106,9 @@ describe('Groups Controller', function() {
members: ['not-user-id']
});
var myGuilds = sandbox.stub(groups,"myGuilds", function() {
return [];
});
user.guilds = [];
expect(scope.isMemberOfGroup(user._id, guild)).to.not.be.ok;
expect(myGuilds).to.be.calledOnce;
});
});
+7 -7
View File
@@ -78,11 +78,11 @@ describe("Party Controller", function() {
initializeControllerWithStubbedState();
setTimeout(function() {
expect(User.set).to.be.calledTwice;
expect(User.set).to.be.calledOnce;
expect(User.set).to.be.calledWith(
{ 'achievements.partyUp': true }
);
expect(rootScope.openModal).to.be.calledTwice;
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith('achievements/partyUp');
done();
}, 1000);
@@ -103,11 +103,11 @@ describe("Party Controller", function() {
initializeControllerWithStubbedState();
setTimeout(function(){
expect(User.set).to.be.calledTwice;
expect(User.set).to.be.calledOnce;
expect(User.set).to.be.calledWith(
{ 'achievements.partyOn': true }
);
expect(rootScope.openModal).to.be.calledTwice;
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith('achievements/partyOn');
done();
}, 1000);
@@ -152,9 +152,9 @@ describe("Party Controller", function() {
var partyStub;
beforeEach(function () {
partyStub = sandbox.stub(groups.Group, "create", function() {
return party;
});
partyStub = sinon.stub(groups.Group, "create");
partyStub.returns(Promise.resolve(party));
sinon.stub(rootScope, 'hardRedirect');
});
it("creates a new party", function() {
+6 -2
View File
@@ -150,8 +150,8 @@ window.habitrpg = angular.module('habitrpg',
url: '/:gid',
templateUrl: 'partials/options.social.guilds.detail.html',
title: env.t('titleGuilds'),
controller: ['$scope', 'Groups', 'Chat', '$stateParams', 'Members',
function($scope, Groups, Chat, $stateParams, Members){
controller: ['$scope', 'Groups', 'Chat', '$stateParams', 'Members', 'Challenges',
function($scope, Groups, Chat, $stateParams, Members, Challenges){
Groups.Group.get($stateParams.gid)
.then(function (response) {
$scope.group = response.data.data;
@@ -164,6 +164,10 @@ window.habitrpg = angular.module('habitrpg',
.then(function (response) {
$scope.group.invites = response.data.data;
});
Challenges.getGroupChallenges($scope.group._id)
.then(function (response) {
$scope.group.challenges = response.data.data;
});
});
}]
})
+2 -3
View File
@@ -18,13 +18,12 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
// If the group is a guild, just check for an intersection with the
// current user's guilds, rather than checking the members of the group.
if(group.type === 'guild') {
var guilds = Groups.myGuilds();
return _.detect(guilds, function(g) { return g._id === group._id });
return _.detect(User.user.guilds, function(guildId) { return guildId === group._id });
}
// Similarly, if we're dealing with the user's current party, return true.
if(group.type === 'party') {
var currentParty = Groups.party();
var currentParty = group;
if(currentParty._id && currentParty._id === group._id) return true;
}
+5 -4
View File
@@ -3,8 +3,8 @@
habitrpg.controller("GuildsCtrl", ['$scope', 'Groups', 'User', 'Challenges', '$rootScope', '$state', '$location', '$compile', 'Analytics',
function($scope, Groups, User, Challenges, $rootScope, $state, $location, $compile, Analytics) {
$scope.groups = {
guilds: Groups.myGuilds(),
public: Groups.publicGuilds(),
guilds: [],
public: [],
};
Groups.myGuilds()
@@ -88,8 +88,9 @@ habitrpg.controller("GuildsCtrl", ['$scope', 'Groups', 'User', 'Challenges', '$r
var html, title;
Challenges.Challenge.query(function(challenges) {
challenges = _.pluck(_.filter(challenges, function(c) {
Challenges.getGroupChallenges(group._id)
.then(function(response) {
var challenges = _.pluck(_.filter(response.data.data, function(c) {
return c.group._id == group._id;
}), '_id');
+12 -8
View File
@@ -8,15 +8,19 @@ habitrpg.controller("HeaderCtrl", ['$scope', 'Groups', 'User',
$scope.inviteOrStartParty = Groups.inviteOrStartParty;
$scope.party = Groups.party(function(){
var triggerResort = function() {
$scope.partyMinusSelf = resortParty();
};
function handlePartyResponse (party) {
$scope.party = party;
triggerResort();
$scope.$watch('user.party.order', triggerResort);
$scope.$watch('user.party.orderAscending', triggerResort);
});
var triggerResort = function() {
$scope.partyMinusSelf = resortParty();
};
triggerResort();
$scope.$watch('user.party.order', triggerResort);
$scope.$watch('user.party.orderAscending', triggerResort);
}
Groups.party().then(handlePartyResponse, handlePartyResponse);
function resortParty() {
var result = _.sortBy(
+31 -38
View File
@@ -8,15 +8,6 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
$scope.type = 'party';
$scope.text = window.env.t('party');
//@TODO: cache
Groups.Group.syncParty()
.then(function successCallback(response) {
$scope.group = response.data.data;
checkForNotifications();
}, function errorCallback(response) {
$scope.newGroup = $scope.group = { type: 'party' };
});
$scope.inviteOrStartParty = Groups.inviteOrStartParty;
$scope.loadWidgets = Social.loadWidgets;
@@ -52,11 +43,12 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
$scope.create = function(group) {
if (!group.name) group.name = env.t('possessiveParty', {name: User.user.profile.name});
Groups.Group.create(group, function() {
Analytics.track({'hitType':'event', 'eventCategory':'behavior', 'eventAction':'join group', 'owner':true, 'groupType':'party', 'privacy':'private'});
Analytics.updateUser({'party.id': group.id, 'partySize': 1});
$rootScope.hardRedirect('/#/options/groups/party');
});
Groups.Group.create(group)
.then(function(response) {
Analytics.track({'hitType':'event', 'eventCategory':'behavior', 'eventAction':'join group', 'owner':true, 'groupType':'party', 'privacy':'private'});
Analytics.updateUser({'party.id': group.id, 'partySize': 1});
$rootScope.hardRedirect('/#/options/groups/party');
});
};
$scope.join = function (party) {
@@ -92,31 +84,32 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
title = window.env.t('leavePartyCha');
//TODO: Move this to challenge service
//@TODO: Implement this when we convert front-end challenge service
// Challenges.Challenge.query(function(challenges) {
// challenges = _.pluck(_.filter(challenges, function(c) {
// return c.group._id == group._id;
// }), '_id');
// if (_.intersection(challenges, User.user.challenges).length > 0) {
// html = $compile(
// '<a ng-controller="GroupsCtrl" ng-click="leave(\'remove-all\')">' + window.env.t('removeTasks') + '</a><br/>\n<a ng-click="leave(\'keep-all\')">' + window.env.t('keepTasks') + '</a><br/>\n<a ng-click="leave(\'cancel\')">' + window.env.t('cancel') + '</a><br/>'
// )($scope);
// title = window.env.t('leavePartyCha');
// } else {
// html = $compile(
// '<a ng-controller="GroupsCtrl" ng-click="leave(\'keep-all\')">' + window.env.t('confirm') + '</a><br/>\n<a ng-click="leave(\'cancel\')">' + window.env.t('cancel') + '</a><br/>'
// )($scope);
// title = window.env.t('leaveParty');
// }
Challenges.getGroupChallenges(group._id)
.then(function(response) {
var challenges = _.pluck(_.filter(response.data.data, function(c) {
return c.group._id == group._id;
}), '_id');
$scope.popoverEl.popover('destroy').popover({
html: true,
placement: 'top',
trigger: 'manual',
title: title,
content: html
}).popover('show');
// });
if (_.intersection(challenges, User.user.challenges).length > 0) {
html = $compile(
'<a ng-controller="GroupsCtrl" ng-click="leave(\'remove-all\')">' + window.env.t('removeTasks') + '</a><br/>\n<a ng-click="leave(\'keep-all\')">' + window.env.t('keepTasks') + '</a><br/>\n<a ng-click="leave(\'cancel\')">' + window.env.t('cancel') + '</a><br/>'
)($scope);
title = window.env.t('leavePartyCha');
} else {
html = $compile(
'<a ng-controller="GroupsCtrl" ng-click="leave(\'keep-all\')">' + window.env.t('confirm') + '</a><br/>\n<a ng-click="leave(\'cancel\')">' + window.env.t('cancel') + '</a><br/>'
)($scope);
title = window.env.t('leaveParty');
}
$scope.popoverEl.popover('destroy').popover({
html: true,
placement: 'top',
trigger: 'manual',
title: title,
content: html
}).popover('show');
});
};
$scope.clickStartQuest = function () {
+5 -3
View File
@@ -277,9 +277,11 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$
if (spell.target == 'self') {
$scope.castEnd(null, 'self');
} else if (spell.target == 'party') {
var party = Groups.party();
party = (_.isArray(party) ? party : []).concat(User.user);
$scope.castEnd(party, 'party');
Groups.party()
.then(function (party) {
party = (_.isArray(party) ? party : []).concat(User.user);
$scope.castEnd(party, 'party');
});
}
}
+1 -1
View File
@@ -63,7 +63,7 @@ angular.module('habitrpg')
}
function markChatSeen (groupId) {
if (User.user.newMessages) delete User.user.newMessages[gid];
if (User.user.newMessages) delete User.user.newMessages[groupId];
return $http({
method: 'POST',
url: apiV3Prefix + '/groups/' + groupId + '/chat/seen',
+2 -1
View File
@@ -110,7 +110,8 @@ angular.module('habitrpg')
data.party = response.data.data;
deferred.resolve(data.party);
}, function (response) {
deferred.reject(response);
data.party = { type: 'party' };
deferred.reject(data.party);
});
} else {
deferred.resolve(data.party);
+6 -5
View File
@@ -46,7 +46,7 @@ angular.module('habitrpg')
user._wrapped = false;
function sync() {
$http({
return $http({
method: "GET",
url: '/api/v3/user/',
})
@@ -349,10 +349,11 @@ angular.module('habitrpg')
settings.auth.apiToken = token;
settings.online = true;
save();
sync();
if (cb) {
cb();
}
sync().then(function () {
if (cb) {
cb();
}
});
//@TODO: Do we need the timezone set?
// userServices.log({}, function(){
// // If they don't have timezone, set it