mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Add tests for isMemberOf
This commit is contained in:
54
test/spec/groupCtrlSpec.js
Normal file
54
test/spec/groupCtrlSpec.js
Normal file
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
describe('Groups Controller', function() {
|
||||
var scope, ctrl, groups, user, guild, $rootScope;
|
||||
|
||||
beforeEach(function() {
|
||||
module(function($provide) {
|
||||
$provide.value('User', {});
|
||||
});
|
||||
|
||||
inject(function($rootScope, $controller, Groups){
|
||||
user = specHelper.newUser();
|
||||
user._id = "unique-user-id";
|
||||
|
||||
scope = $rootScope.$new();
|
||||
|
||||
// Load RootCtrl to ensure shared behaviors are loaded
|
||||
$controller('RootCtrl', {$scope: scope, User: {user: user}});
|
||||
|
||||
ctrl = $controller('GroupsCtrl', {$scope: scope, User: {user: user}});
|
||||
|
||||
groups = Groups;
|
||||
});
|
||||
});
|
||||
|
||||
it('isMemberOfGroup returns true if guild is included in myGuilds call', function(){
|
||||
|
||||
guild = specHelper.newGroup("leaders-user-id");
|
||||
guild._id = "unique-guild-id";
|
||||
guild.type = 'guild';
|
||||
guild.members.push(user._id);
|
||||
|
||||
var myGuilds = sinon.stub(groups,"myGuilds", function() {
|
||||
return [guild];
|
||||
});
|
||||
|
||||
expect(scope.isMemberOfGroup(user._id, guild)).to.be.eql(true);
|
||||
expect(myGuilds).to.be.called
|
||||
});
|
||||
|
||||
it('isMemberOfGroup does not return true if guild is not included in myGuilds call', function(){
|
||||
|
||||
guild = specHelper.newGroup("leaders-user-id");
|
||||
guild._id = "unique-guild-id";
|
||||
guild.type = 'guild';
|
||||
|
||||
var myGuilds = sinon.stub(groups,"myGuilds", function() {
|
||||
return [];
|
||||
});
|
||||
|
||||
expect(scope.isMemberOfGroup(user._id, guild)).to.not.be.eql(true);
|
||||
expect(myGuilds).to.be.called
|
||||
});
|
||||
});
|
||||
@@ -29,5 +29,21 @@ specHelper = {
|
||||
achievements: {},
|
||||
};
|
||||
return user;
|
||||
},
|
||||
newGroup: function(leader) {
|
||||
var quest = { progress: { }, active: false };
|
||||
group = {
|
||||
"leader" : leader,
|
||||
"quest" : quest,
|
||||
"memberCount" : 1,
|
||||
"chat" : [],
|
||||
"privacy" : "public",
|
||||
"invites" : [],
|
||||
"members" : [
|
||||
leader
|
||||
]
|
||||
};
|
||||
return group;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -20,9 +20,7 @@ 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') {
|
||||
if (_.detect(Groups.myGuilds(), function(g) { return g._id === group._id })) {
|
||||
return true;
|
||||
}
|
||||
return _.detect(Groups.myGuilds(), function(g) { return g._id === group._id })
|
||||
}
|
||||
|
||||
if (!group.members) return false;
|
||||
|
||||
Reference in New Issue
Block a user