mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Reinstate error code in resolve promise for api tests.
This commit is contained in:
@@ -146,7 +146,10 @@ describe('GET /groups/:id', () => {
|
|||||||
it('does not return the group object for a non-member', () => {
|
it('does not return the group object for a non-member', () => {
|
||||||
let api = requester(nonMember);
|
let api = requester(nonMember);
|
||||||
return expect(api.get(`/groups/${createdGroup._id}`))
|
return expect(api.get(`/groups/${createdGroup._id}`))
|
||||||
.to.be.rejectedWith('Group not found or you don\'t have access.');
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
text: 'Group not found or you don\'t have access.',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -173,7 +176,10 @@ describe('GET /groups/:id', () => {
|
|||||||
it('does not return the group object for a non-member', () => {
|
it('does not return the group object for a non-member', () => {
|
||||||
let api = requester(nonMember);
|
let api = requester(nonMember);
|
||||||
return expect(api.get(`/groups/${createdGroup._id}`))
|
return expect(api.get(`/groups/${createdGroup._id}`))
|
||||||
.to.be.rejectedWith('Group not found or you don\'t have access.');
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
text: 'Group not found or you don\'t have access.',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -219,7 +225,10 @@ describe('GET /groups/:id', () => {
|
|||||||
it('returns error if group does not exist', () => {
|
it('returns error if group does not exist', () => {
|
||||||
let api = requester(user);
|
let api = requester(user);
|
||||||
return expect(api.get('/groups/group-that-does-not-exist'))
|
return expect(api.get('/groups/group-that-does-not-exist'))
|
||||||
.to.be.rejectedWith('Group not found or you don\'t have access.');
|
.to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
text: 'Group not found or you don\'t have access.',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -80,14 +80,20 @@ describe('POST /groups', () => {
|
|||||||
return api.post('/groups', {
|
return api.post('/groups', {
|
||||||
type: 'party',
|
type: 'party',
|
||||||
});
|
});
|
||||||
})).to.be.rejectedWith('Already in a party, try refreshing.');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
text: 'Already in a party, try refreshing.',
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
xit('prevents creating a public party. TODO: it is possible to create a public party. Should we send back an error? Automatically switch the privacy to private?', () => {
|
xit('prevents creating a public party. TODO: it is possible to create a public party. Should we send back an error? Automatically switch the privacy to private?', () => {
|
||||||
return expect(api.post('/groups', {
|
return expect(api.post('/groups', {
|
||||||
type: 'party',
|
type: 'party',
|
||||||
privacy: 'public',
|
privacy: 'public',
|
||||||
})).to.be.rejectedWith('Parties must be private');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 400,
|
||||||
|
text: 'Parties must be private',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -111,7 +117,10 @@ describe('POST /groups', () => {
|
|||||||
return api.post('/groups', {
|
return api.post('/groups', {
|
||||||
type: 'guild',
|
type: 'guild',
|
||||||
});
|
});
|
||||||
})).to.be.rejectedWith('Not enough gems!');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
text: 'Not enough gems!',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,10 @@ describe('POST /groups/:id', () => {
|
|||||||
it('does not allow user to update group', () => {
|
it('does not allow user to update group', () => {
|
||||||
return expect(api.post(`/groups/${groupUserDoesNotOwn._id}`, {
|
return expect(api.post(`/groups/${groupUserDoesNotOwn._id}`, {
|
||||||
name: 'Change'
|
name: 'Change'
|
||||||
})).to.be.rejectedWith('Only the group leader can update the group!');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
text: 'Only the group leader can update the group!',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,10 @@ describe('POST /groups/:id/leave', () => {
|
|||||||
it('group is not accessible after leaving', () => {
|
it('group is not accessible after leaving', () => {
|
||||||
return expect(api.post(`/groups/${group._id}/leave`).then((result) => {
|
return expect(api.post(`/groups/${group._id}/leave`).then((result) => {
|
||||||
return api.get(`/groups/${group._id}`);
|
return api.get(`/groups/${group._id}`);
|
||||||
})).to.be.rejectedWith('Group not found or you don\'t have access.');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 404,
|
||||||
|
text: 'Group not found or you don\'t have access.',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ describe('POST /groups/:id/removeMember', () => {
|
|||||||
it('does not allow leader to remove themselves', () => {
|
it('does not allow leader to remove themselves', () => {
|
||||||
return expect(api.post(`/groups/${group._id}/removeMember`, null, {
|
return expect(api.post(`/groups/${group._id}/removeMember`, null, {
|
||||||
uuid: leader._id,
|
uuid: leader._id,
|
||||||
})).to.be.rejectedWith('You cannot remove yourself!');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
text: 'You cannot remove yourself!',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can remove other members of guild', () => {
|
it('can remove other members of guild', () => {
|
||||||
|
|||||||
@@ -37,7 +37,10 @@ describe('POST /register', () => {
|
|||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
confirmPassword: confirmPassword,
|
confirmPassword: confirmPassword,
|
||||||
})).to.be.rejectedWith(':password and :confirmPassword don\'t match');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
text: ':password and :confirmPassword don\'t match',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -63,7 +66,10 @@ describe('POST /register', () => {
|
|||||||
email: uniqueEmail,
|
email: uniqueEmail,
|
||||||
password: password,
|
password: password,
|
||||||
confirmPassword: password,
|
confirmPassword: password,
|
||||||
})).to.be.rejectedWith('Username already taken');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
text: 'Username already taken',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects if email is already taken', () => {
|
it('rejects if email is already taken', () => {
|
||||||
@@ -76,7 +82,10 @@ describe('POST /register', () => {
|
|||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
confirmPassword: password,
|
confirmPassword: password,
|
||||||
})).to.be.rejectedWith('Email already taken');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
text: 'Email already taken',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ describe('DELETE /user', () => {
|
|||||||
it('deletes the user', () => {
|
it('deletes the user', () => {
|
||||||
return expect(api.del('/user').then((fetchedUser) => {
|
return expect(api.del('/user').then((fetchedUser) => {
|
||||||
return api.get('/user');
|
return api.get('/user');
|
||||||
})).to.be.rejectedWith('No user found.');
|
})).to.eventually.be.rejected.and.eql({
|
||||||
|
code: 401,
|
||||||
|
text: 'No user found.',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('user in solo group', () => {
|
context('user in solo group', () => {
|
||||||
|
|||||||
@@ -188,7 +188,10 @@ function _requestMaker(user, method) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
if (!err.response) return reject(err);
|
if (!err.response) return reject(err);
|
||||||
let errorString = JSON.parse(err.response.text).err;
|
let errorString = JSON.parse(err.response.text).err;
|
||||||
return reject(errorString);
|
return reject({
|
||||||
|
code: err.response.statusCode,
|
||||||
|
text: errorString,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
resolve(response.body);
|
resolve(response.body);
|
||||||
|
|||||||
Reference in New Issue
Block a user