mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
committed by
Blade Barringer
parent
17b0329c43
commit
9b10f348cc
@@ -57,11 +57,28 @@ describe('Post /groups/:groupId/invite', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns empty when uuids is empty', async () => {
|
it('returns an error when uuids and emails are empty', async () => {
|
||||||
await expect(inviter.post(`/groups/${group._id}/invite`, {
|
await expect(inviter.post(`/groups/${group._id}/invite`, {
|
||||||
|
emails: [],
|
||||||
uuids: [],
|
uuids: [],
|
||||||
}))
|
}))
|
||||||
.to.eventually.be.empty;
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: t('inviteMustNotBeEmpty'),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an error when uuids is empty and emails is undefined', async () => {
|
||||||
|
await expect(inviter.post(`/groups/${group._id}/invite`, {
|
||||||
|
emails: undefined,
|
||||||
|
uuids: [],
|
||||||
|
}))
|
||||||
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: t('inviteMissingUuid'),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns an error when there are more than INVITES_LIMIT uuids', async () => {
|
it('returns an error when there are more than INVITES_LIMIT uuids', async () => {
|
||||||
@@ -159,11 +176,16 @@ describe('Post /groups/:groupId/invite', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns empty when emails is an empty array', async () => {
|
it('returns an error when emails is empty and uuids is undefined', async () => {
|
||||||
await expect(inviter.post(`/groups/${group._id}/invite`, {
|
await expect(inviter.post(`/groups/${group._id}/invite`, {
|
||||||
emails: [],
|
emails: [],
|
||||||
|
uuids: undefined,
|
||||||
}))
|
}))
|
||||||
.to.eventually.be.empty;
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
error: 'BadRequest',
|
||||||
|
message: t('inviteMissingEmail'),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns an error when there are more than INVITES_LIMIT emails', async () => {
|
it('returns an error when there are more than INVITES_LIMIT emails', async () => {
|
||||||
|
|||||||
@@ -186,6 +186,8 @@
|
|||||||
"keepOrRemove": "req.query.keep must be either \"keep\" or \"remove\"",
|
"keepOrRemove": "req.query.keep must be either \"keep\" or \"remove\"",
|
||||||
"canOnlyInviteEmailUuid": "Can only invite using uuids or emails.",
|
"canOnlyInviteEmailUuid": "Can only invite using uuids or emails.",
|
||||||
"inviteMissingEmail": "Missing email address in invite.",
|
"inviteMissingEmail": "Missing email address in invite.",
|
||||||
|
"inviteMissingUuid": "Missing user id in invite",
|
||||||
|
"inviteMustNotBeEmpty": "Invite must not be empty.",
|
||||||
"partyMustbePrivate": "Parties must be private",
|
"partyMustbePrivate": "Parties must be private",
|
||||||
"userAlreadyInGroup": "User already in that group.",
|
"userAlreadyInGroup": "User already in that group.",
|
||||||
"cannotInviteSelfToGroup": "You cannot invite yourself to a group.",
|
"cannotInviteSelfToGroup": "You cannot invite yourself to a group.",
|
||||||
|
|||||||
@@ -675,28 +675,33 @@ api.inviteToGroup = {
|
|||||||
|
|
||||||
let uuidsIsArray = Array.isArray(uuids);
|
let uuidsIsArray = Array.isArray(uuids);
|
||||||
let emailsIsArray = Array.isArray(emails);
|
let emailsIsArray = Array.isArray(emails);
|
||||||
|
let emptyEmails = emailsIsArray && emails.length < 1;
|
||||||
|
let emptyUuids = uuidsIsArray && uuids.length < 1;
|
||||||
|
|
||||||
|
|
||||||
if (!uuids && !emails) {
|
if (!uuids && !emails) {
|
||||||
throw new BadRequest(res.t('canOnlyInviteEmailUuid'));
|
throw new BadRequest(res.t('canOnlyInviteEmailUuid'));
|
||||||
|
} else if (uuids && !uuidsIsArray) {
|
||||||
|
throw new BadRequest(res.t('uuidsMustBeAnArray'));
|
||||||
|
} else if (emails && !emailsIsArray) {
|
||||||
|
throw new BadRequest(res.t('emailsMustBeAnArray'));
|
||||||
|
} else if (!emails && emptyUuids) {
|
||||||
|
throw new BadRequest(res.t('inviteMissingUuid'));
|
||||||
|
} else if (!uuids && emptyEmails) {
|
||||||
|
throw new BadRequest(res.t('inviteMissingEmail'));
|
||||||
|
} else if (emptyEmails && emptyUuids) {
|
||||||
|
throw new BadRequest(res.t('inviteMustNotBeEmpty'));
|
||||||
}
|
}
|
||||||
|
|
||||||
let results = [];
|
let results = [];
|
||||||
let totalInvites = 0;
|
let totalInvites = 0;
|
||||||
|
|
||||||
if (uuids) {
|
if (uuids) {
|
||||||
if (!uuidsIsArray) {
|
totalInvites += uuids.length;
|
||||||
throw new BadRequest(res.t('uuidsMustBeAnArray'));
|
|
||||||
} else {
|
|
||||||
totalInvites += uuids.length;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emails) {
|
if (emails) {
|
||||||
if (!emailsIsArray) {
|
totalInvites += emails.length;
|
||||||
throw new BadRequest(res.t('emailsMustBeAnArray'));
|
|
||||||
} else {
|
|
||||||
totalInvites += emails.length;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalInvites > INVITES_LIMIT) {
|
if (totalInvites > INVITES_LIMIT) {
|
||||||
|
|||||||
Reference in New Issue
Block a user