From 239f78674bafd56541b939a4eb3d483e9e565714 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Wed, 14 Nov 2018 01:44:09 +0000 Subject: [PATCH] fix(usernames): address failing tests --- test/api/unit/models/group.test.js | 30 +++++++++++++++--------------- website/server/models/group.js | 2 +- website/server/models/message.js | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/test/api/unit/models/group.test.js b/test/api/unit/models/group.test.js index e965ca29ff..a9df620f56 100644 --- a/test/api/unit/models/group.test.js +++ b/test/api/unit/models/group.test.js @@ -569,7 +569,7 @@ describe('Group Model', () => { }); it('throws an error if no uuids or emails are passed in', async () => { - await expect(Group.validateInvitations(null, null, res)).to.eventually.be.rejected.and.eql({ + await expect(Group.validateInvitations({}, res)).to.eventually.be.rejected.and.eql({ httpCode: 400, message: 'Bad request.', name: 'BadRequest', @@ -579,7 +579,7 @@ describe('Group Model', () => { }); it('throws an error if only uuids are passed in, but they are not an array', async () => { - await expect(Group.validateInvitations({ uuid: 'user-id'}, null, res)).to.eventually.be.rejected.and.eql({ + await expect(Group.validateInvitations({ uuids: 'user-id'}, res)).to.eventually.be.rejected.and.eql({ httpCode: 400, message: 'Bad request.', name: 'BadRequest', @@ -589,7 +589,7 @@ describe('Group Model', () => { }); it('throws an error if only emails are passed in, but they are not an array', async () => { - await expect(Group.validateInvitations(null, { emails: 'user@example.com'}, res)).to.eventually.be.rejected.and.eql({ + await expect(Group.validateInvitations({emails: 'user@example.com'}, res)).to.eventually.be.rejected.and.eql({ httpCode: 400, message: 'Bad request.', name: 'BadRequest', @@ -599,27 +599,27 @@ describe('Group Model', () => { }); it('throws an error if emails are not passed in, and uuid array is empty', async () => { - await expect(Group.validateInvitations([], null, res)).to.eventually.be.rejected.and.eql({ + await expect(Group.validateInvitations({uuids: []}, res)).to.eventually.be.rejected.and.eql({ httpCode: 400, message: 'Bad request.', name: 'BadRequest', }); expect(res.t).to.be.calledOnce; - expect(res.t).to.be.calledWith('inviteMissingUuid'); + expect(res.t).to.be.calledWith('inviteMustNotBeEmpty'); }); it('throws an error if uuids are not passed in, and email array is empty', async () => { - await expect(Group.validateInvitations(null, [], res)).to.eventually.be.rejected.and.eql({ + await expect(Group.validateInvitations({emails: []}, res)).to.eventually.be.rejected.and.eql({ httpCode: 400, message: 'Bad request.', name: 'BadRequest', }); expect(res.t).to.be.calledOnce; - expect(res.t).to.be.calledWith('inviteMissingEmail'); + expect(res.t).to.be.calledWith('inviteMustNotBeEmpty'); }); it('throws an error if uuids and emails are passed in as empty arrays', async () => { - await expect(Group.validateInvitations([], [], res)).to.eventually.be.rejected.and.eql({ + await expect(Group.validateInvitations({emails: [], uuids: []}, res)).to.eventually.be.rejected.and.eql({ httpCode: 400, message: 'Bad request.', name: 'BadRequest', @@ -639,7 +639,7 @@ describe('Group Model', () => { uuids.push('one-more-uuid'); // to put it over the limit - await expect(Group.validateInvitations(uuids, emails, res)).to.eventually.be.rejected.and.eql({ + await expect(Group.validateInvitations({uuids, emails}, res)).to.eventually.be.rejected.and.eql({ httpCode: 400, message: 'Bad request.', name: 'BadRequest', @@ -657,33 +657,33 @@ describe('Group Model', () => { emails.push(`user-${i}@example.com`); } - await Group.validateInvitations(uuids, emails, res); + await Group.validateInvitations({uuids, emails}, res); expect(res.t).to.not.be.called; }); it('does not throw an error if only user ids are passed in', async () => { - await Group.validateInvitations(['user-id', 'user-id2'], null, res); + await Group.validateInvitations({uuids: ['user-id', 'user-id2']}, res); expect(res.t).to.not.be.called; }); it('does not throw an error if only emails are passed in', async () => { - await Group.validateInvitations(null, ['user1@example.com', 'user2@example.com'], res); + await Group.validateInvitations({emails: ['user1@example.com', 'user2@example.com']}, res); expect(res.t).to.not.be.called; }); it('does not throw an error if both uuids and emails are passed in', async () => { - await Group.validateInvitations(['user-id', 'user-id2'], ['user1@example.com', 'user2@example.com'], res); + await Group.validateInvitations({uuids: ['user-id', 'user-id2'], emails: ['user1@example.com', 'user2@example.com']}, res); expect(res.t).to.not.be.called; }); it('does not throw an error if uuids are passed in and emails are an empty array', async () => { - await Group.validateInvitations(['user-id', 'user-id2'], [], res); + await Group.validateInvitations({uuids: ['user-id', 'user-id2'], emails: []}, res); expect(res.t).to.not.be.called; }); it('does not throw an error if emails are passed in and uuids are an empty array', async () => { - await Group.validateInvitations([], ['user1@example.com', 'user2@example.com'], res); + await Group.validateInvitations({uuids: [], emails: ['user1@example.com', 'user2@example.com']}, res); expect(res.t).to.not.be.called; }); }); diff --git a/website/server/models/group.js b/website/server/models/group.js index 42eb35c9a4..8876e03db1 100644 --- a/website/server/models/group.js +++ b/website/server/models/group.js @@ -368,7 +368,7 @@ function getInviteError (uuids, emails, usernames) { errorString = 'emailsMustBeAnArray'; } else if (usernames && !usernamesIsArray) { errorString = 'usernamesMustBeAnArray'; - } else if (emptyEmails && emptyUuids && emptyUsernames) { + } else if ((!emails || emptyEmails) && (!uuids || emptyUuids) && (!usernames || emptyUsernames)) { errorString = 'inviteMustNotBeEmpty'; } diff --git a/website/server/models/message.js b/website/server/models/message.js index d02abfed29..2ba3235c39 100644 --- a/website/server/models/message.js +++ b/website/server/models/message.js @@ -118,7 +118,7 @@ export function messageDefaults (msg, user) { contributor: user.contributor && user.contributor.toObject(), backer: user.backer && user.backer.toObject(), user: user.profile.name, - username: user.flags.verifiedUsername && user.auth && user.auth.local && user.auth.local.username, + username: user.flags && user.flags.verifiedUsername && user.auth && user.auth.local && user.auth.local.username, }); } else { message.uuid = 'system';