mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Filter out blank emails
This commit is contained in:
@@ -51,8 +51,10 @@ describe('Invite to Group Controller', function() {
|
||||
|
||||
context('email', function() {
|
||||
it('invites user with emails', function() {
|
||||
scope.emails[0].name = 'Luigi';
|
||||
scope.emails[0].email = 'mario_bro@themushroomkingdom.com';
|
||||
scope.emails = [
|
||||
{name: 'Luigi', email: 'mario_bro@themushroomkingdom.com'},
|
||||
{name: 'Mario', email: 'mario@tmk.com'}
|
||||
];
|
||||
|
||||
scope.inviteNewUsers('email');
|
||||
expect(groups.Group.invite).to.be.calledOnce;
|
||||
@@ -60,7 +62,10 @@ describe('Invite to Group Controller', function() {
|
||||
gid: scope.group._id,
|
||||
}, {
|
||||
inviter: user.profile.name,
|
||||
emails: [{name: 'Luigi', email: 'mario_bro@themushroomkingdom.com'},{name: '', email: ''}]
|
||||
emails: [
|
||||
{name: 'Luigi', email: 'mario_bro@themushroomkingdom.com'},
|
||||
{name: 'Mario', email: 'mario@tmk.com'}
|
||||
]
|
||||
|
||||
});
|
||||
});
|
||||
@@ -74,6 +79,26 @@ describe('Invite to Group Controller', function() {
|
||||
|
||||
expect(scope.emails).to.eql([{name:'', email: ''},{name:'', email: ''}]);
|
||||
});
|
||||
|
||||
it('filters out blank email inputs', function() {
|
||||
scope.emails = [
|
||||
{name: 'Luigi', email: 'mario_bro@themushroomkingdom.com'},
|
||||
{name: 'Toad', email: ''},
|
||||
{name: 'Mario', email: 'mario@tmk.com'}
|
||||
];
|
||||
|
||||
scope.inviteNewUsers('email');
|
||||
expect(groups.Group.invite).to.be.calledOnce;
|
||||
expect(groups.Group.invite).to.be.calledWith({
|
||||
gid: scope.group._id,
|
||||
}, {
|
||||
inviter: user.profile.name,
|
||||
emails: [
|
||||
{name: 'Luigi', email: 'mario_bro@themushroomkingdom.com'},
|
||||
{name: 'Mario', email: 'mario@tmk.com'}
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('uuid', function() {
|
||||
|
||||
@@ -20,7 +20,9 @@ habitrpg.controller('InviteToGroupCtrl', ['$scope', 'User', 'Groups', 'injectedG
|
||||
|
||||
function _inviteByMethod(inviteMethod) {
|
||||
if (inviteMethod === 'email') {
|
||||
Groups.Group.invite({gid: $scope.group._id}, {inviter: $scope.inviter, emails: $scope.emails}, function(){
|
||||
var emails = _getEmails();
|
||||
|
||||
Groups.Group.invite({gid: $scope.group._id}, {inviter: $scope.inviter, emails: emails}, function(){
|
||||
Notification.text(window.env.t('invitationsSent'));
|
||||
_resetInvitees();
|
||||
}, function(){
|
||||
@@ -49,6 +51,14 @@ habitrpg.controller('InviteToGroupCtrl', ['$scope', 'User', 'Groups', 'injectedG
|
||||
return filteredUuids;
|
||||
}
|
||||
|
||||
function _getEmails() {
|
||||
var emails = _.filter($scope.emails, function(obj) {
|
||||
return obj.email != '';
|
||||
});
|
||||
console.log(emails);
|
||||
return emails;
|
||||
}
|
||||
|
||||
function _resetInvitees() {
|
||||
var emptyEmails = [{name:"",email:""},{name:"",email:""}];
|
||||
var emptyInvitees = [{uuid: ''}];
|
||||
|
||||
Reference in New Issue
Block a user