Ported release both, added unit tests, add release both route with integration tests
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('POST /user/release-both', () => {
|
||||
let user;
|
||||
let animal = 'Wolf-Base';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser({
|
||||
'items.currentMount': animal,
|
||||
'items.currentPet': animal,
|
||||
'items.pets': {animal: 5},
|
||||
'items.mounts': {animal: true},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error when user balance is too low and user does not have triadBingo', async () => {
|
||||
await expect(user.post('/user/release-both'))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
code: 401,
|
||||
error: 'NotAuthorized',
|
||||
message: t('notEnoughGems'),
|
||||
});
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('grants triad bingo with gems', async () => {
|
||||
await user.update({
|
||||
balance: 1.5,
|
||||
});
|
||||
|
||||
let response = await user.post('/user/release-both');
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('mountsAndPetsReleased'));
|
||||
expect(user.balance).to.equal(0);
|
||||
expect(user.items.currentMount).to.be.empty;
|
||||
expect(user.items.currentPet).to.be.empty;
|
||||
expect(user.items.pets[animal]).to.be.empty;
|
||||
expect(user.items.mounts[animal]).to.equal(null);
|
||||
expect(user.achievements.beastMasterCount).to.equal(1);
|
||||
expect(user.achievements.mountMasterCount).to.equal(1);
|
||||
expect(user.achievements.triadBingoCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
import releaseBoth from '../../../common/script/ops/releaseBoth';
|
||||
import i18n from '../../../common/script/i18n';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
import {
|
||||
NotAuthorized,
|
||||
} from '../../../common/script/libs/errors';
|
||||
|
||||
describe('shared.ops.releaseBoth', () => {
|
||||
let user;
|
||||
let animal = 'Wolf-Base';
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser();
|
||||
user.items.currentMount = animal;
|
||||
user.items.currentPet = animal;
|
||||
user.items.pets[animal] = 5;
|
||||
user.items.mounts[animal] = true;
|
||||
user.balance = 1.5;
|
||||
});
|
||||
|
||||
it('returns an error when user balance is too low and user does not have triadBingo', (done) => {
|
||||
user.balance = 0;
|
||||
|
||||
try {
|
||||
releaseBoth(user);
|
||||
} catch (err) {
|
||||
expect(err).to.be.an.instanceof(NotAuthorized);
|
||||
expect(err.message).to.equal(i18n.t('notEnoughGems'));
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
it('grants triad bingo with gems', () => {
|
||||
let response = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.achievements.triadBingoCount).to.equal(1);
|
||||
});
|
||||
|
||||
it('grants triad bingo without gems', () => {
|
||||
user.balance = 0;
|
||||
user.achievements.triadBingo = 1;
|
||||
user.achievements.triadBingoCount = 1;
|
||||
|
||||
let response = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.achievements.triadBingoCount).to.equal(2);
|
||||
});
|
||||
|
||||
it('releases pets', () => {
|
||||
let response = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.items.pets[animal]).to.be.empty;
|
||||
expect(user.items.mounts[animal]).to.equal(null);
|
||||
});
|
||||
|
||||
it('releases mounts', () => {
|
||||
let response = releaseBoth(user);
|
||||
|
||||
expect(response.message).to.equal(i18n.t('mountsAndPetsReleased'));
|
||||
expect(user.items.mounts[animal]).to.equal(null);
|
||||
});
|
||||
|
||||
it('removes currentPet', () => {
|
||||
releaseBoth(user);
|
||||
|
||||
expect(user.items.currentMount).to.be.empty;
|
||||
expect(user.items.currentPet).to.be.empty;
|
||||
});
|
||||
|
||||
it('removes currentMount', () => {
|
||||
releaseBoth(user);
|
||||
|
||||
expect(user.items.currentMount).to.be.empty;
|
||||
});
|
||||
|
||||
it('decreases user\'s balance', () => {
|
||||
releaseBoth(user);
|
||||
|
||||
expect(user.balance).to.equal(0);
|
||||
});
|
||||
|
||||
it('incremenets beastMasterCount', () => {
|
||||
releaseBoth(user);
|
||||
|
||||
expect(user.achievements.beastMasterCount).to.equal(1);
|
||||
});
|
||||
|
||||
it('incremenets mountMasterCount', () => {
|
||||
releaseBoth(user);
|
||||
|
||||
expect(user.achievements.mountMasterCount).to.equal(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user