mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Ensure correct join/leave button for parties
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user