tests(api): Convert tests to use new api user methods

This commit is contained in:
Blade Barringer
2015-12-29 17:34:33 -06:00
parent b2336c7adf
commit 4cf9518a5a
28 changed files with 213 additions and 313 deletions

View File

@@ -3,23 +3,21 @@ import {
createAndPopulateGroup,
generateGroup,
generateUser,
requester,
translate as t,
} from '../../../helpers/api-integration.helper';
import { find } from 'lodash';
describe('DELETE /user', () => {
let api, user;
let user;
beforeEach(() => {
return generateUser().then((usr) => {
api = requester(usr);
user = usr;
});
});
it('deletes the user', () => {
return expect(api.del('/user').then((fetchedUser) => {
return expect(user.del('/user').then((fetchedUser) => {
return checkExistence('users', user._id);
})).to.eventually.eql(false);
});
@@ -41,7 +39,7 @@ describe('DELETE /user', () => {
});
it('deletes party when user is the only member', () => {
return expect(api.del('/user').then((result) => {
return expect(user.del('/user').then((result) => {
return checkExistence('groups', party._id);
})).to.eventually.eql(false);
});
@@ -60,14 +58,14 @@ describe('DELETE /user', () => {
});
it('deletes guild when user is the only member', () => {
return expect(api.del('/user').then((result) => {
return expect(user.del('/user').then((result) => {
return checkExistence('groups', guild._id);
})).to.eventually.eql(false);
});
});
context('groups user is leader of', () => {
let api, group, oldLeader, newLeader;
let group, oldLeader, newLeader;
beforeEach(() => {
return createAndPopulateGroup({
@@ -80,13 +78,12 @@ describe('DELETE /user', () => {
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}`);
return oldLeader.del('/user').then((res) => {
return newLeader.get(`/groups/${group._id}`);
}).then((guild) => {
expect(guild.leader).to.exist;
expect(guild.leader._id).to.not.eql(oldLeader._id);
@@ -95,14 +92,13 @@ describe('DELETE /user', () => {
});
context('groups user is a part of', () => {
let api, group1, group2, userToDelete, otherUser;
let group1, group2, userToDelete, otherUser;
beforeEach(() => {
return generateUser({
balance: 10,
}).then((user) => {
userToDelete = user;
api = requester(userToDelete);
return generateGroup(userToDelete, {
type: 'guild',
@@ -122,17 +118,17 @@ describe('DELETE /user', () => {
group2 = res.group;
otherUser = res.members[0];
return api.post(`/groups/${group2._id}/join`);
return userToDelete.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}`);
return userToDelete.del('/user').then((res) => {
return otherUser.get(`/groups/${group1._id}`);
}).then((fetchedGroup1) => {
expect(fetchedGroup1.members).to.be.empty;
return requester(otherUser).get(`/groups/${group2._id}`);
return otherUser.get(`/groups/${group2._id}`);
}).then((fetchedGroup2) => {
expect(fetchedGroup2.members).to.not.be.empty;
@@ -147,7 +143,7 @@ describe('DELETE /user', () => {
});
context('pending invitation to group', () => {
let api, group, userToDelete, otherUser;
let group, userToDelete, otherUser;
beforeEach(() => {
return createAndPopulateGroup({
@@ -165,8 +161,8 @@ describe('DELETE /user', () => {
});
it('removes invitations from groups', () => {
return requester(userToDelete).del('/user').then((res) => {
return requester(otherUser).get(`/groups/${group._id}`);
return userToDelete.del('/user').then((res) => {
return 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);