Merge branch 'api-v3' into sabrecat/v3-payments

This commit is contained in:
Matteo Pagliazzi
2016-04-30 16:51:51 +02:00
3365 changed files with 7060 additions and 5409 deletions

View File

@@ -236,7 +236,7 @@ describe('POST /challenges', () => {
official: true,
});
expect(challenge.official).to.be.undefined;
expect(challenge.official).to.eql(false);
});
it('returns an error when challenge validation fails; doesn\'s save user or group', async () => {
@@ -284,7 +284,7 @@ describe('POST /challenges', () => {
expect(challenge.name).to.eql(name);
expect(challenge.shortName).to.eql(shortName);
expect(challenge.description).to.eql(description);
expect(challenge.official).to.be.undefined;
expect(challenge.official).to.eql(false);
expect(challenge.group).to.eql({
_id: group._id,
privacy: group.privacy,

View File

@@ -44,6 +44,15 @@ describe('POST /group/:groupId/join', () => {
expect(res.leader.profile.name).to.eql(user.profile.name);
});
it('returns an error is user was already a member', async () => {
await joiningUser.post(`/groups/${publicGuild._id}/join`);
await expect(joiningUser.post(`/groups/${publicGuild._id}/join`)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('userAlreadyInGroup'),
});
});
it('promotes joining member in a public empty guild to leader', async () => {
await user.post(`/groups/${publicGuild._id}/leave`);

View File

@@ -36,6 +36,6 @@ describe('POST /user/allocate', () => {
await user.sync();
expect(user.stats.con).to.equal(1);
expect(user.stats.points).to.equal(0);
expect(res.stats.con).to.equal(1);
expect(res.con).to.equal(1);
});
});

View File

@@ -18,11 +18,7 @@ describe('POST /user/allocate-now', () => {
let res = await user.post('/user/allocate-now');
await user.sync();
expect(res).to.eql({
data: {
stats: user.stats,
},
});
expect(res).to.eql(user.stats);
expect(user.stats.points).to.equal(0);
expect(user.stats.con).to.equal(9);
expect(user.stats.int).to.equal(8);

View File

@@ -36,9 +36,7 @@ describe('POST /user/buy/:key', () => {
await user.sync();
expect(user.stats.hp).to.equal(50);
expect(res.data).to.eql({
stats: user.stats,
});
expect(res.data).to.eql(user.stats);
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
});

View File

@@ -31,11 +31,7 @@ describe('POST /user/buy-mystery-set/:key', () => {
expect(res.data).to.eql({
items: JSON.parse(JSON.stringify(user.items)), // otherwise dates can't be compared
purchased: {
plan: {
consecutive: user.purchased.plan.consecutive,
},
},
purchasedPlanConsecutive: user.purchased.plan.consecutive,
});
expect(res.message).to.equal(t('hourglassPurchaseSet'));
});

View File

@@ -36,9 +36,7 @@ describe('POST /user/buy-potion', () => {
await user.sync();
expect(user.stats.hp).to.equal(50);
expect(res.data).to.eql({
stats: user.stats,
});
expect(res.data).to.eql(user.stats);
expect(res.message).to.equal(t('messageBought', {itemText: potion.text()}));
});
});

View File

@@ -18,13 +18,13 @@ describe('POST /user/change-class', () => {
let res = await user.post('/user/change-class?class=rogue');
await user.sync();
expect(res).to.eql({
data: JSON.parse(JSON.stringify({
expect(res).to.eql(JSON.parse(
JSON.stringify({
preferences: user.preferences,
stats: user.stats,
flags: user.flags,
items: user.items,
})),
});
})
));
});
});

View File

@@ -15,12 +15,12 @@ describe('POST /user/disable-classes', () => {
let res = await user.post('/user/disable-classes');
await user.sync();
expect(res).to.eql({
data: JSON.parse(JSON.stringify({
expect(res).to.eql(JSON.parse(
JSON.stringify({
preferences: user.preferences,
stats: user.stats,
flags: user.flags,
})),
});
})
));
});
});

View File

@@ -35,8 +35,6 @@ describe('POST /user/equip/:type/:key', () => {
let res = await user.post('/user/equip/equipped/weapon_warrior_2');
await user.sync();
expect(res).to.eql({
data: JSON.parse(JSON.stringify(user.items)),
});
expect(res).to.eql(JSON.parse(JSON.stringify(user.items)));
});
});

View File

@@ -13,16 +13,12 @@ describe('POST /user/sleep', () => {
it('toggles sleep status', async () => {
let res = await user.post('/user/sleep');
expect(res).to.eql({
preferences: {sleep: true},
});
expect(res).to.eql(true);
await user.sync();
expect(user.preferences.sleep).to.be.true;
let res2 = await user.post('/user/sleep');
expect(res2).to.eql({
preferences: {sleep: false},
});
expect(res2).to.eql(false);
await user.sync();
expect(user.preferences.sleep).to.be.false;
});

View File

@@ -16,7 +16,7 @@ describe('POST /user/reset-password', async () => {
let response = await user.post(endpoint, {
email: user.auth.local.email,
});
expect(response).to.eql({ message: t('passwordReset') });
expect(response).to.eql({ data: {}, message: t('passwordReset') });
await user.sync();
expect(user.auth.local.hashed_password).to.not.eql(previousPassword);
});
@@ -25,7 +25,7 @@ describe('POST /user/reset-password', async () => {
let response = await user.post(endpoint, {
email: 'nonExistent@email.com',
});
expect(response).to.eql({ message: t('passwordReset') });
expect(response).to.eql({ data: {}, message: t('passwordReset') });
});
it('errors if email is not provided', async () => {
@@ -36,4 +36,3 @@ describe('POST /user/reset-password', async () => {
});
});
});