From d918bc9f56f625ca3decd5a8c8d8d886cea3b137 Mon Sep 17 00:00:00 2001 From: Grayson Gilmore Date: Tue, 18 Jul 2017 15:21:34 -0500 Subject: [PATCH] Add tests to increase coverage on /website/server/controllers/api-v3/auth.js (#8809) * Add tests covering branches in _handleGroupInvitation * Remove .only from latest test --- .../user/auth/POST-register_local.test.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/api/v3/integration/user/auth/POST-register_local.test.js b/test/api/v3/integration/user/auth/POST-register_local.test.js index baf7bf3fa4..39683ce5b4 100644 --- a/test/api/v3/integration/user/auth/POST-register_local.test.js +++ b/test/api/v3/integration/user/auth/POST-register_local.test.js @@ -515,6 +515,52 @@ describe('POST /user/auth/local/register', () => { inviter: groupLeader._id, }); }); + + it('user not added to a party on expired invite', async () => { + let { group, groupLeader } = await createAndPopulateGroup({ + groupDetails: { type: 'party', privacy: 'private' }, + }); + + let invite = encrypt(JSON.stringify({ + id: group._id, + inviter: groupLeader._id, + sentAt: Date.now() - 6.912e8, // 8 days old + })); + + let user = await api.post(`/user/auth/local/register?groupInvite=${invite}`, { + username, + email, + password, + confirmPassword: password, + }); + + expect(user.invitations.party).to.eql({}); + }); + + it('adds a user to a guild on an invite of type other than party', async () => { + let { group, groupLeader } = await createAndPopulateGroup({ + groupDetails: { type: 'guild', privacy: 'private' }, + }); + + let invite = encrypt(JSON.stringify({ + id: group._id, + inviter: groupLeader._id, + sentAt: Date.now(), + })); + + let user = await api.post(`/user/auth/local/register?groupInvite=${invite}`, { + username, + email, + password, + confirmPassword: password, + }); + + expect(user.invitations.guilds[0]).to.eql({ + id: group._id, + name: group.name, + inviter: groupLeader._id, + }); + }); }); context('successful login via api', () => {