Ensure correct join/leave button for parties

This commit is contained in:
Kevin Gisi
2015-04-24 11:54:00 -04:00
parent 523582f870
commit 65e42345f2
2 changed files with 20 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
'use strict';
describe('Groups Controller', function() {
var scope, ctrl, groups, user, guild, $rootScope;
var scope, ctrl, groups, user, guild, party, $rootScope;
beforeEach(function() {
module(function($provide) {
@@ -23,6 +23,19 @@ describe('Groups Controller', function() {
});
});
it("isMemberOfGroup returns true if group is the user's party", function() {
party = specHelper.newGroup("test-party");
party._id = "unique-party-id";
party.type = 'party';
party.members = []; // Ensure we wouldn't pass automatically.
var partyStub = sinon.stub(groups,"party", function() {
return party;
});
expect(scope.isMemberOfGroup(user._id, party)).to.be.ok;
});
it('isMemberOfGroup returns true if guild is included in myGuilds call', function(){
guild = specHelper.newGroup("leaders-user-id");

View File

@@ -23,6 +23,12 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
return _.detect(Groups.myGuilds(), function(g) { return g._id === group._id });
}
// Similarly, if we're dealing with the user's current party, return true.
if(group.type === 'party') {
var currentParty = Groups.party();
if(currentParty._id && currentParty._id === group._id) return true;
}
if (!group.members) return false;
var memberIds = _.map(group.members, function(x){return x._id});
return ~(memberIds.indexOf(userid));