mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
WIP(hourglass): Error catches
This commit is contained in:
@@ -67,5 +67,10 @@
|
|||||||
"subUpdateTitle": "Update",
|
"subUpdateTitle": "Update",
|
||||||
"subUpdateDescription": "Update the card to be charged.",
|
"subUpdateDescription": "Update the card to be charged.",
|
||||||
"notEnoughHourglasses": "You don't have enough Mystic Hourglasses.",
|
"notEnoughHourglasses": "You don't have enough Mystic Hourglasses.",
|
||||||
"hourglassBuyEquipSetConfirm": "Buy this full set of items for 1 Mystic Hourglass?"
|
"hourglassBuyEquipSetConfirm": "Buy this full set of items for 1 Mystic Hourglass?",
|
||||||
|
"petsAlreadyOwned": "Pet already owned.",
|
||||||
|
"mountsAlreadyOwned": "Mount already owned.",
|
||||||
|
"typeNotAllowedHourglass": "Item type not supported for purchase with Mystic Hourglass. Allowed types: ",
|
||||||
|
"petsNotAllowedHourglass": "Pet not available for purchase with Mystic Hourglass.",
|
||||||
|
"mountsNotAllowedHourglass": "Mount not available for purchase with Mystic Hourglass."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -533,18 +533,12 @@ _.each gearTypes, (type) ->
|
|||||||
Time Traveler Store, mystery sets need their items mapped in
|
Time Traveler Store, mystery sets need their items mapped in
|
||||||
###
|
###
|
||||||
_.each api.mystery, (v,k)-> v.items = _.where api.gear.flat, {mystery:k}
|
_.each api.mystery, (v,k)-> v.items = _.where api.gear.flat, {mystery:k}
|
||||||
api.timeTravelerStore = (owned, category) ->
|
api.timeTravelerStore = (owned) ->
|
||||||
ownedKeys = _.keys owned.toObject?() or owned # mongoose workaround
|
ownedKeys = _.keys owned.toObject?() or owned # mongoose workaround
|
||||||
if not category or category is "mystery"
|
_.reduce api.mystery, (m,v,k)->
|
||||||
_.reduce api.mystery, (m,v,k)->
|
return m if k=='wondercon' or ~ownedKeys.indexOf(v.items[0].key) # skip wondercon and already-owned sets
|
||||||
return m if k=='wondercon' or ~ownedKeys.indexOf(v.items[0].key) # skip wondercon and already-owned sets
|
m[k] = v;m
|
||||||
m[k] = v;m
|
, {}
|
||||||
, {}
|
|
||||||
else
|
|
||||||
_.reduce api.timeTravelStable[category], (m,v,i)->
|
|
||||||
returm m if ~ownedKeys.indexOf(v)
|
|
||||||
m[i] = v;m
|
|
||||||
, []
|
|
||||||
|
|
||||||
###
|
###
|
||||||
---------------------------------------------------------------
|
---------------------------------------------------------------
|
||||||
|
|||||||
@@ -1019,8 +1019,11 @@ api.wrap = (user, main=true) ->
|
|||||||
cb? null, _.pick(user,$w 'items purchased.plan.consecutive')
|
cb? null, _.pick(user,$w 'items purchased.plan.consecutive')
|
||||||
|
|
||||||
hourglassPurchase: (req, cb, analytics)->
|
hourglassPurchase: (req, cb, analytics)->
|
||||||
return cb?({code:401, message:i18n.t('notEnoughHourglasses', req.language)}) unless user.purchased.plan.consecutive.trinkets > 0
|
{type, key} = req.params
|
||||||
|
return cb?({code:400, message:i18n.t('typeNotAllowedHourglass', req.language) + JSON.stringify(_.keys(content.timeTravelStable))}) unless content.timeTravelStable[type]
|
||||||
|
return cb?({code:400, message:i18n.t(type+'NotAllowedHourglass', req.language)}) if not _.includes(content.timeTravelStable[type], key)
|
||||||
|
return cb?({code:400, message:i18n.t(type+'AlreadyOwned', req.language)}) if user.items[type][key]
|
||||||
|
return cb?({code:400, message:i18n.t('notEnoughHourglasses', req.language)}) unless user.purchased.plan.consecutive.trinkets > 0
|
||||||
|
|
||||||
sell: (req, cb) ->
|
sell: (req, cb) ->
|
||||||
{key, type} = req.params
|
{key, type} = req.params
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
user = {
|
user = {
|
||||||
items: {
|
items: {
|
||||||
pets: {},
|
pets: {},
|
||||||
mounts: {}
|
mounts: {},
|
||||||
|
hatchingPotions: {}
|
||||||
},
|
},
|
||||||
purchased: {
|
purchased: {
|
||||||
plan: {
|
plan: {
|
||||||
@@ -33,8 +34,16 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
|
|
||||||
context('failure conditions', function() {
|
context('failure conditions', function() {
|
||||||
|
|
||||||
|
it('does not allow purchase of unsupported item types', function(done) {
|
||||||
|
user.ops.hourglassPurchase({params:{type: 'hatchingPotions', key: 'Base'}}, function(response) {
|
||||||
|
expect(response.message).to.eql("Item type not supported for purchase with Mystic Hourglass. Allowed types: [pets, mounts]");
|
||||||
|
expect(user.items.hatchingPotions).to.eql({});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('does not grant pets without Mystic Hourglasses', function(done) {
|
it('does not grant pets without Mystic Hourglasses', function(done) {
|
||||||
user.ops.hourglassPurchase({params:{category: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params:{type: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
|
||||||
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
|
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
|
||||||
expect(user.items.pets).to.eql({});
|
expect(user.items.pets).to.eql({});
|
||||||
done();
|
done();
|
||||||
@@ -42,7 +51,7 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not grant mounts without Mystic Hourglasses', function(done) {
|
it('does not grant mounts without Mystic Hourglasses', function(done) {
|
||||||
user.ops.hourglassPurchase({params:{category: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params:{type: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
|
||||||
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
|
expect(response.message).to.eql("You don't have enough Mystic Hourglasses.");
|
||||||
expect(user.items.mounts).to.eql({});
|
expect(user.items.mounts).to.eql({});
|
||||||
done();
|
done();
|
||||||
@@ -55,7 +64,7 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
'MantisShrimp-Base': true
|
'MantisShrimp-Base': true
|
||||||
};
|
};
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params:{category: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params:{type: 'pets', key: 'MantisShrimp-Base'}}, function(response) {
|
||||||
expect(response.message).to.eql("Pet already owned.");
|
expect(response.message).to.eql("Pet already owned.");
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
@@ -68,7 +77,7 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
'MantisShrimp-Base': true
|
'MantisShrimp-Base': true
|
||||||
};
|
};
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params:{category: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params:{type: 'mounts', key: 'MantisShrimp-Base'}}, function(response) {
|
||||||
expect(response.message).to.eql("Mount already owned.");
|
expect(response.message).to.eql("Mount already owned.");
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
@@ -78,7 +87,7 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
it('does not grant pet that is not part of the Time Travel Stable', function(done) {
|
it('does not grant pet that is not part of the Time Travel Stable', function(done) {
|
||||||
user.purchased.plan.consecutive.trinkets = 1;
|
user.purchased.plan.consecutive.trinkets = 1;
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params: {category: 'pets', key: 'Wolf-Veteran'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'pets', key: 'Wolf-Veteran'}}, function(response) {
|
||||||
expect(response.message).to.eql('Pet not available for purchase with Mystic Hourglass.');
|
expect(response.message).to.eql('Pet not available for purchase with Mystic Hourglass.');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
@@ -88,7 +97,7 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
it('does not grant mount that is not part of the Time Travel Stable', function(done) {
|
it('does not grant mount that is not part of the Time Travel Stable', function(done) {
|
||||||
user.purchased.plan.consecutive.trinkets = 1;
|
user.purchased.plan.consecutive.trinkets = 1;
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params: {category: 'mounts', key: 'Orca-Base'}}, function(response) {
|
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'Orca-Base'}}, function(response) {
|
||||||
expect(response.message).to.eql('Mount not available for purchase with Mystic Hourglass.');
|
expect(response.message).to.eql('Mount not available for purchase with Mystic Hourglass.');
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
done();
|
done();
|
||||||
@@ -101,7 +110,7 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
it('buys a pet', function(done) {
|
it('buys a pet', function(done) {
|
||||||
user.purchased.plan.consecutive.trinkets = 2;
|
user.purchased.plan.consecutive.trinkets = 2;
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params: {category: 'pets', key: 'MantisShrimp-Base'}}, function() {
|
user.ops.hourglassPurchase({params: {type: 'pets', key: 'MantisShrimp-Base'}}, function() {
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
expect(user.items.pets).to.eql({'MantisShrimp-Base':true});
|
expect(user.items.pets).to.eql({'MantisShrimp-Base':true});
|
||||||
done();
|
done();
|
||||||
@@ -111,7 +120,7 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
it('buys a mount', function(done) {
|
it('buys a mount', function(done) {
|
||||||
user.purchased.plan.consecutive.trinkets = 2;
|
user.purchased.plan.consecutive.trinkets = 2;
|
||||||
|
|
||||||
user.ops.hourglassPurchase({params: {category: 'mounts', key: 'MantisShrimp-Base'}}, function() {
|
user.ops.hourglassPurchase({params: {type: 'mounts', key: 'MantisShrimp-Base'}}, function() {
|
||||||
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
|
||||||
expect(user.items.mounts).to.eql({'MantisShrimp-Base':true});
|
expect(user.items.mounts).to.eql({'MantisShrimp-Base':true});
|
||||||
done();
|
done();
|
||||||
@@ -120,4 +129,3 @@ describe('user.ops.hourglassPurchase', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -180,13 +180,22 @@ module.exports = (swagger, v2) ->
|
|||||||
"/user/inventory/purchase/{type}/{key}":
|
"/user/inventory/purchase/{type}/{key}":
|
||||||
spec:
|
spec:
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
description: "Purchase a gem-purchaseable item from Alexander"
|
description: "Purchase a Gem-purchasable item from Alexander"
|
||||||
parameters:[
|
parameters:[
|
||||||
path('type',"The type of object you're purchasing.",'string',['eggs','hatchingPotions','food','quests','special'])
|
path('type',"The type of object you're purchasing.",'string',['eggs','hatchingPotions','food','quests','special'])
|
||||||
path('key',"The object key you're purchasing (call /content route for available keys)",'string')
|
path('key',"The object key you're purchasing (call /content route for available keys)",'string')
|
||||||
]
|
]
|
||||||
action: user.purchase
|
action: user.purchase
|
||||||
|
|
||||||
|
"/user/inventory/hourglass/{type}/{key}"
|
||||||
|
spec:
|
||||||
|
method: 'POST'
|
||||||
|
description: "Purchase a pet or mount using a Mystic Hourglass"
|
||||||
|
parameters:[
|
||||||
|
path('type',"The type of object you're purchasing.",'string',['pets','mounts'])
|
||||||
|
path('key',"The object key you're purchasing (call /content route for available keys)",'string')
|
||||||
|
]
|
||||||
|
action: user.hourglassPurchase
|
||||||
|
|
||||||
"/user/inventory/feed/{pet}/{food}":
|
"/user/inventory/feed/{pet}/{food}":
|
||||||
spec:
|
spec:
|
||||||
|
|||||||
Reference in New Issue
Block a user