mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-10-28 11:42:29 +01:00
* (server) Add parties array to store invites * (server) Lint files * Update joinGroup, rejectGroupInvite, _inviteByUUID, and remove clearPartyInvitation.js * Update user schema: detailed 'invitations.parties' attributes * Code improvement and do not let invite twice * Check if the user is already invited earlier in the code * Added message to invitation page, and show all invitations * Added join party confirmation alert * Small fixes * Created test: allow inviting a user to 2 different parties * Updated tests * Update invitations.parties on more places * Small adjustments * Updates on invitations.party references * Show all invitations when user is already in a party * Fixed notifications counter * Update both 'party' and 'parties' at _handleGroupInvitation * Updated a test * Fixed small mistake at _handleGroupInvitation * More test update * Update invitation.party when removing single invite and small adjust at view
114 lines
3.2 KiB
JavaScript
114 lines
3.2 KiB
JavaScript
import {
|
|
generateUser,
|
|
createAndPopulateGroup,
|
|
translate as t,
|
|
} from '../../../../helpers/api-v3-integration.helper';
|
|
|
|
describe('POST /group/:groupId/reject-invite', () => {
|
|
context('Rejecting a public guild invite', () => {
|
|
let publicGuild, invitedUser;
|
|
|
|
beforeEach(async () => {
|
|
let {group, invitees} = await createAndPopulateGroup({
|
|
groupDetails: {
|
|
name: 'Test Guild',
|
|
type: 'guild',
|
|
privacy: 'public',
|
|
},
|
|
invites: 1,
|
|
});
|
|
|
|
publicGuild = group;
|
|
invitedUser = invitees[0];
|
|
});
|
|
|
|
it('returns error when user is not invited', async () => {
|
|
let userWithoutInvite = await generateUser();
|
|
|
|
await expect(userWithoutInvite.post(`/groups/${publicGuild._id}/reject-invite`)).to.eventually.be.rejected.and.eql({
|
|
code: 401,
|
|
error: 'NotAuthorized',
|
|
message: t('messageGroupRequiresInvite'),
|
|
});
|
|
});
|
|
|
|
it('clears invitation from user', async () => {
|
|
await invitedUser.post(`/groups/${publicGuild._id}/reject-invite`);
|
|
|
|
await expect(invitedUser.get('/user'))
|
|
.to.eventually.have.deep.property('invitations.guilds')
|
|
.to.not.include({id: publicGuild._id});
|
|
});
|
|
});
|
|
|
|
context('Rejecting a private guild invite', () => {
|
|
let invitedUser, guild;
|
|
|
|
beforeEach(async () => {
|
|
let { group, invitees } = await createAndPopulateGroup({
|
|
groupDetails: {
|
|
name: 'Test Guild',
|
|
type: 'guild',
|
|
privacy: 'private',
|
|
},
|
|
invites: 1,
|
|
});
|
|
|
|
guild = group;
|
|
invitedUser = invitees[0];
|
|
});
|
|
|
|
it('returns error when user is not invited', async () => {
|
|
let userWithoutInvite = await generateUser();
|
|
|
|
await expect(userWithoutInvite.post(`/groups/${guild._id}/reject-invite`)).to.eventually.be.rejected.and.eql({
|
|
code: 401,
|
|
error: 'NotAuthorized',
|
|
message: t('messageGroupRequiresInvite'),
|
|
});
|
|
});
|
|
|
|
it('clears invitation from user', async () => {
|
|
await invitedUser.post(`/groups/${guild._id}/reject-invite`);
|
|
|
|
await expect(invitedUser.get('/user'))
|
|
.to.eventually.have.deep.property('invitations.guilds')
|
|
.to.not.include({id: guild._id});
|
|
});
|
|
});
|
|
|
|
context('Rejecting a party invite', () => {
|
|
let invitedUser, party;
|
|
|
|
beforeEach(async () => {
|
|
let { group, invitees } = await createAndPopulateGroup({
|
|
groupDetails: {
|
|
name: 'Test Party',
|
|
type: 'party',
|
|
},
|
|
members: 2,
|
|
invites: 1,
|
|
});
|
|
|
|
party = group;
|
|
invitedUser = invitees[0];
|
|
});
|
|
|
|
it('returns error when user is not invited', async () => {
|
|
let userWithoutInvite = await generateUser();
|
|
|
|
await expect(userWithoutInvite.post(`/groups/${party._id}/reject-invite`)).to.eventually.be.rejected.and.eql({
|
|
code: 401,
|
|
error: 'NotAuthorized',
|
|
message: t('messageGroupRequiresInvite'),
|
|
});
|
|
});
|
|
|
|
it('clears invitation from user', async () => {
|
|
await invitedUser.post(`/groups/${party._id}/reject-invite`);
|
|
|
|
await expect(invitedUser.get('/user')).to.eventually.not.have.deep.property('invitations.parties[0].id');
|
|
});
|
|
});
|
|
});
|