Skip to content

Commit

Permalink
Merge 63de1e3 into c5215e8
Browse files Browse the repository at this point in the history
  • Loading branch information
TheHollidayInn committed May 23, 2016
2 parents c5215e8 + 63de1e3 commit a238918
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
9 changes: 6 additions & 3 deletions test/spec/controllers/partyCtrlSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ describe("Party Controller", function() {
inject(function(_$state_) {
var state = _$state_;
sandbox.stub(state, 'is').returns(true);

var syncParty = sinon.stub(groups.Group, 'syncParty')
syncParty.returns(Promise.resolve(groupResponse));

var froceSyncParty = sinon.stub(groups, 'party')
froceSyncParty.returns(Promise.resolve(groupResponse));

$controller('PartyCtrl', { $scope: scope, $state: state, User: User });
// @TODO: I have update the party ctrl to sync the user whenever it is called rather than only on the party page
// Since I have cached the promise, this should not be a performance issue, but let's keep this test here in case anything breaks.
// expect(state.is).to.be.calledOnce; // ensure initialization worked as desired
expect(state.is).to.be.calledOnce;
});
};

Expand Down
21 changes: 14 additions & 7 deletions website/client/js/controllers/partyCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ habitrpg.controller("PartyCtrl", ['$rootScope','$scope','Groups','Chat','User','
$scope.inviteOrStartParty = Groups.inviteOrStartParty;
$scope.loadWidgets = Social.loadWidgets;

Groups.Group.syncParty()
.then(function successCallback(group) {
$rootScope.party = $scope.group = group;
checkForNotifications();
}, function errorCallback(response) {
$rootScope.party = $scope.group = $scope.newGroup = { type: 'party' };
});
function handlePartyResponse (group) {
$rootScope.party = $scope.group = group;
checkForNotifications();
}

function handlePartyError (response) {
$rootScope.party = $scope.group = $scope.newGroup = { type: 'party' };
}

if ($state.is('options.social.party')) {
Groups.party(true).then(handlePartyResponse, handlePartyError);
} else {
Groups.Group.syncParty().then(handlePartyResponse, handlePartyError);
}

function checkForNotifications () {
// Checks if user's party has reached 2 players for the first time.
Expand Down
2 changes: 1 addition & 1 deletion website/client/js/controllers/tavernCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

habitrpg.controller("TavernCtrl", ['$scope', 'Groups', 'User', 'Challenges',
function($scope, Groups, User, Challenges) {
Groups.tavern()
Groups.tavern(true)
.then(function (tavern) {
$scope.group = tavern;
Challenges.getGroupChallenges($scope.group._id)
Expand Down

0 comments on commit a238918

Please sign in to comment.