v3: port hatch, equip and feed ops

This commit is contained in:
Matteo Pagliazzi
2016-03-24 16:08:58 +01:00
parent 23f92e2d28
commit 0a65e6a6f1
15 changed files with 783 additions and 336 deletions
-102
View File
@@ -1,102 +0,0 @@
/* eslint-disable camelcase */
import sinon from 'sinon'; // eslint-disable-line no-shadow
import {assert} from 'sinon';
import i18n from '../../common/script/i18n';
import shared from '../../common/script/index.js';
import content from '../../common/script/content/index';
describe('user.ops.equip', () => {
let user;
let spy;
beforeEach(() => {
user = {
items: {
gear: {
owned: {
weapon_warrior_0: true,
weapon_warrior_1: true,
weapon_warrior_2: true,
weapon_wizard_1: true,
weapon_wizard_2: true,
shield_base_0: true,
shield_warrior_1: true,
},
equipped: {
weapon: 'weapon_warrior_0',
shield: 'shield_base_0',
},
},
},
preferences: {},
stats: {gp: 200},
achievements: {},
flags: {},
};
shared.wrap(user);
spy = sinon.spy();
});
context('Gear', () => {
it('should not send a message if a weapon is equipped while only having zero or one weapons equipped', () => {
// user.ops.equip always calls the callback, even if it isn't sending a message
// so we need to check to see if a single null message was sent.
user.ops.equip({params: {key: 'weapon_warrior_1'}});
// one-handed to one-handed
user.ops.equip({params: {key: 'weapon_warrior_2'}}, spy);
assert.calledOnce(spy);
assert.calledWith(spy, null);
spy.reset();
// one-handed to two-handed
user.ops.equip({params: {key: 'weapon_wizard_1'}}, spy);
assert.calledOnce(spy);
assert.calledWith(spy, null);
spy.reset();
// two-handed to two-handed
user.ops.equip({params: {key: 'weapon_wizard_2'}}, spy);
assert.calledOnce(spy);
assert.calledWith(spy, null);
spy.reset();
// two-handed to one-handed
user.ops.equip({params: {key: 'weapon_warrior_2'}}, spy);
assert.calledOnce(spy);
assert.calledWith(spy, null);
spy.reset();
});
it('should send messages if equipping a two-hander causes the off-hander to be unequipped', () => {
user.ops.equip({params: {key: 'weapon_warrior_1'}});
user.ops.equip({params: {key: 'shield_warrior_1'}});
// equipping two-hander
user.ops.equip({params: {key: 'weapon_wizard_1'}}, spy);
let weapon = content.gear.flat.weapon_wizard_1;
let item = content.gear.flat.shield_warrior_1;
let message = i18n.t('messageTwoHandedEquip', {twoHandedText: weapon.text(null), offHandedText: item.text(null)});
assert.calledOnce(spy);
assert.calledWith(spy, {code: 200, message});
});
it('should send messages if equipping an off-hand item causes a two-handed weapon to be unequipped', () => {
// equipping two-hander
user.ops.equip({params: {key: 'weapon_wizard_1'}});
let weapon = content.gear.flat.weapon_wizard_1;
let shield = content.gear.flat.shield_warrior_1;
user.ops.equip({params: {key: 'shield_warrior_1'}}, spy);
let message = i18n.t('messageTwoHandedUnequip', {twoHandedText: weapon.text(null), offHandedText: shield.text(null)});
assert.calledOnce(spy);
assert.calledWith(spy, {code: 200, message});
});
});
});
-129
View File
@@ -1,129 +0,0 @@
let shared = require('../../common/script/index.js');
describe('user.ops.hatch', () => {
let user;
beforeEach(() => {
user = {
items: {
eggs: {},
hatchingPotions: {},
pets: {},
},
};
shared.wrap(user);
});
context('Pet Hatching', () => {
context('failure conditions', () => {
it('does not allow hatching without specifying egg and potion', (done) => {
user.ops.hatch({params: {}}, (response) => {
expect(response.message).to.eql('Please specify query.egg & query.hatchingPotion');
expect(user.items.pets).to.be.empty;
done();
});
});
it('does not allow hatching if user lacks specified egg', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.ops.hatch({params: {egg: 'Dragon', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageMissingEggPotion'));
expect(user.items.pets).to.be.empty;
expect(user.items.eggs).to.eql({Wolf: 1});
expect(user.items.hatchingPotions).to.eql({Base: 1});
done();
});
});
it('does not allow hatching if user lacks specified hatching potion', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Golden'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageMissingEggPotion'));
expect(user.items.pets).to.be.empty;
expect(user.items.eggs).to.eql({Wolf: 1});
expect(user.items.hatchingPotions).to.eql({Base: 1});
done();
});
});
it('does not allow hatching if user already owns target pet', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.items.pets = {'Wolf-Base': 10};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageAlreadyPet'));
expect(user.items.pets).to.eql({'Wolf-Base': 10});
expect(user.items.eggs).to.eql({Wolf: 1});
expect(user.items.hatchingPotions).to.eql({Base: 1});
done();
});
});
it('does not allow hatching quest pet egg using premium potion', (done) => {
user.items.eggs = {Cheetah: 1};
user.items.hatchingPotions = {Spooky: 1};
user.ops.hatch({params: {egg: 'Cheetah', hatchingPotion: 'Spooky'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageInvalidEggPotionCombo'));
expect(user.items.pets).to.be.empty;
expect(user.items.eggs).to.eql({Cheetah: 1});
expect(user.items.hatchingPotions).to.eql({Spooky: 1});
done();
});
});
});
context('successful hatching', () => {
it('hatches a basic pet', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
expect(user.items.pets).to.eql({'Wolf-Base': 5});
expect(user.items.eggs).to.eql({Wolf: 0});
expect(user.items.hatchingPotions).to.eql({Base: 0});
done();
});
});
it('hatches a quest pet', (done) => {
user.items.eggs = {Cheetah: 1};
user.items.hatchingPotions = {Base: 1};
user.ops.hatch({params: {egg: 'Cheetah', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
expect(user.items.pets).to.eql({'Cheetah-Base': 5});
expect(user.items.eggs).to.eql({Cheetah: 0});
expect(user.items.hatchingPotions).to.eql({Base: 0});
done();
});
});
it('hatches a premium pet', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Spooky: 1};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Spooky'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
expect(user.items.pets).to.eql({'Wolf-Spooky': 5});
expect(user.items.eggs).to.eql({Wolf: 0});
expect(user.items.hatchingPotions).to.eql({Spooky: 0});
done();
});
});
it('hatches a pet previously raised to a mount', (done) => {
user.items.eggs = {Wolf: 1};
user.items.hatchingPotions = {Base: 1};
user.items.pets = {'Wolf-Base': -1};
user.ops.hatch({params: {egg: 'Wolf', hatchingPotion: 'Base'}}, (response) => {
expect(response.message).to.eql(shared.i18n.t('messageHatched'));
expect(user.items.pets).to.eql({'Wolf-Base': 5});
expect(user.items.eggs).to.eql({Wolf: 0});
expect(user.items.hatchingPotions).to.eql({Base: 0});
done();
});
});
});
});
});