mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Move all delete user tests to new structure
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import {
|
||||
checkExistence,
|
||||
createAndPopulateGroup,
|
||||
generateGroup,
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../helpers/api-integration.helper';
|
||||
import { find } from 'lodash';
|
||||
|
||||
describe('DELETE /user', () => {
|
||||
let api, user;
|
||||
@@ -64,13 +66,111 @@ describe('DELETE /user', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('groups with multiple members', () => {
|
||||
it('removes user from all groups user was a part of');
|
||||
context('groups user is leader of', () => {
|
||||
let api, group, oldLeader, newLeader;
|
||||
|
||||
beforeEach(() => {
|
||||
return createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
},
|
||||
members: 3,
|
||||
}).then((res) => {
|
||||
group = res.group;
|
||||
newLeader = res.members[0];
|
||||
oldLeader = res.leader;
|
||||
api = requester(oldLeader);
|
||||
});
|
||||
});
|
||||
|
||||
it('chooses new group leader for any group user was the leader of', () => {
|
||||
return api.del('/user').then((res) => {
|
||||
return requester(newLeader).get(`/groups/${group._id}`);
|
||||
}).then((guild) => {
|
||||
expect(guild.leader).to.exist;
|
||||
expect(guild.leader._id).to.not.eql(oldLeader._id);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('groups user is a part of', () => {
|
||||
let api, group1, group2, userToDelete, otherUser;
|
||||
|
||||
beforeEach(() => {
|
||||
return generateUser({
|
||||
balance: 10,
|
||||
}).then((user) => {
|
||||
userToDelete = user;
|
||||
api = requester(userToDelete);
|
||||
|
||||
return generateGroup(userToDelete, {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
});
|
||||
}).then((newGroup) => {
|
||||
group1 = newGroup;
|
||||
|
||||
return createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
},
|
||||
members: 3,
|
||||
});
|
||||
}).then((res) => {
|
||||
group2 = res.group;
|
||||
otherUser = res.members[0];
|
||||
|
||||
return api.post(`/groups/${group2._id}/join`);
|
||||
});
|
||||
});
|
||||
|
||||
it('removes user from all groups user was a part of', () => {
|
||||
return api.del('/user').then((res) => {
|
||||
return requester(otherUser).get(`/groups/${group1._id}`);
|
||||
}).then((fetchedGroup1) => {
|
||||
expect(fetchedGroup1.members).to.be.empty;
|
||||
|
||||
return requester(otherUser).get(`/groups/${group2._id}`);
|
||||
}).then((fetchedGroup2) => {
|
||||
expect(fetchedGroup2.members).to.not.be.empty;
|
||||
|
||||
let userInGroup = find(fetchedGroup2.members, (member) => {
|
||||
return member._id === userToDelete._id;
|
||||
});
|
||||
|
||||
expect(userInGroup).to.not.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
it('chooses new group leader for any group user was the leader of');
|
||||
});
|
||||
|
||||
context('pending invitation to group', () => {
|
||||
it('removes invitations from groups');
|
||||
let api, group, userToDelete, otherUser;
|
||||
|
||||
beforeEach(() => {
|
||||
return createAndPopulateGroup({
|
||||
groupDetails: {
|
||||
type: 'guild',
|
||||
privacy: 'public',
|
||||
},
|
||||
members: 3,
|
||||
invites: 2,
|
||||
}).then((res) => {
|
||||
group = res.group;
|
||||
otherUser = res.members[0];
|
||||
userToDelete = res.invitees[0];
|
||||
});
|
||||
});
|
||||
|
||||
it('removes invitations from groups', () => {
|
||||
return requester(userToDelete).del('/user').then((res) => {
|
||||
return requester(otherUser).get(`/groups/${group._id}`);
|
||||
}).then((fetchedGroup) => {
|
||||
expect(fetchedGroup.invites).to.have.a.lengthOf(1);
|
||||
expect(fetchedGroup.invites[0]._id).to.not.eql(userToDelete._id);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user