mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Add API calls for shop inventories (#7810)
* Add API call for market inventory * changes to shop api calls * optimize shop categories * add API call for quests * add api call for time travelers shop * fic buying items in shops * fix linting errors * shop adjustments for iOS app * add tests to shops * fix syntax issues * Code formatting * correct indentation * add tests for api routes * fix time travelers and seasonal * Increase test coverage for shop routes * refactor: Pull out trinket count in time traveler route * refactor: Clarify instructions for seasonal shop script * lint: Remove extra new line * Adjust shops common test
This commit is contained in:
committed by
Sabe Jones
parent
aa00893f6c
commit
24d25026cf
28
test/api/v3/integration/shops/GET-shops_market.test.js
Normal file
28
test/api/v3/integration/shops/GET-shops_market.test.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('GET /shops/market', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('returns a valid shop object', async () => {
|
||||
let shop = await user.get('/shops/market');
|
||||
|
||||
expect(shop.identifier).to.equal('market');
|
||||
expect(shop.text).to.eql(t('market'));
|
||||
expect(shop.notes).to.eql(t('welcomeMarketMobile'));
|
||||
expect(shop.imageName).to.be.a('string');
|
||||
expect(shop.categories).to.be.an('array');
|
||||
|
||||
let categories = shop.categories.map(cat => cat.identifier);
|
||||
|
||||
expect(categories).to.include('eggs');
|
||||
expect(categories).to.include('hatchingPotions');
|
||||
expect(categories).to.include('food');
|
||||
});
|
||||
});
|
||||
28
test/api/v3/integration/shops/GET-shops_quests.test.js
Normal file
28
test/api/v3/integration/shops/GET-shops_quests.test.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('GET /shops/quests', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('returns a valid shop object', async () => {
|
||||
let shop = await user.get('/shops/quests');
|
||||
|
||||
expect(shop.identifier).to.equal('questShop');
|
||||
expect(shop.text).to.eql(t('quests'));
|
||||
expect(shop.notes).to.eql(t('ianTextMobile'));
|
||||
expect(shop.imageName).to.be.a('string');
|
||||
expect(shop.categories).to.be.an('array');
|
||||
|
||||
let categories = shop.categories.map(cat => cat.identifier);
|
||||
|
||||
expect(categories).to.include('unlockable');
|
||||
expect(categories).to.include('gold');
|
||||
expect(categories).to.include('pet');
|
||||
});
|
||||
});
|
||||
22
test/api/v3/integration/shops/GET-shops_seasonal.test.js
Normal file
22
test/api/v3/integration/shops/GET-shops_seasonal.test.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('GET /shops/seasonal', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('returns a valid shop object', async () => {
|
||||
let shop = await user.get('/shops/seasonal');
|
||||
|
||||
expect(shop.identifier).to.equal('seasonalShop');
|
||||
expect(shop.text).to.eql(t('seasonalShop'));
|
||||
expect(shop.notes).to.eql(t('seasonalShopSummerText'));
|
||||
expect(shop.imageName).to.be.a('string');
|
||||
expect(shop.categories).to.be.an('array');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
|
||||
describe('GET /shops/time-travelers', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
it('returns a valid shop object', async () => {
|
||||
let shop = await user.get('/shops/time-travelers');
|
||||
|
||||
expect(shop.identifier).to.equal('timeTravelersShop');
|
||||
expect(shop.text).to.eql(t('timeTravelers'));
|
||||
expect(shop.notes).to.be.a('string');
|
||||
expect(shop.imageName).to.be.a('string');
|
||||
expect(shop.categories).to.be.an('array');
|
||||
|
||||
let categories = shop.categories.map(cat => cat.identifier);
|
||||
|
||||
expect(categories).to.include('pets');
|
||||
expect(categories).to.include('mounts');
|
||||
expect(categories).to.include('201606');
|
||||
|
||||
let mammothPet = shop.categories
|
||||
.find(cat => cat.identifier === 'pets')
|
||||
.items
|
||||
.find(pet => pet.key === 'Mammoth-Base');
|
||||
let mantisShrimp = shop.categories
|
||||
.find(cat => cat.identifier === 'mounts')
|
||||
.items
|
||||
.find(pet => pet.key === 'MantisShrimp-Base');
|
||||
|
||||
expect(mammothPet).to.exist;
|
||||
expect(mantisShrimp).to.exist;
|
||||
});
|
||||
|
||||
it('returns active shop notes and imageName if user has trinkets', async () => {
|
||||
await user.update({
|
||||
'purchased.plan.consecutive.trinkets': 1,
|
||||
});
|
||||
|
||||
let shop = await user.get('/shops/time-travelers');
|
||||
|
||||
expect(shop.notes).to.eql(t('timeTravelersPopover'));
|
||||
expect(shop.imageName).to.eql('npc_timetravelers_active');
|
||||
});
|
||||
|
||||
it('returns inactive shop notes and imageName if user has trinkets', async () => {
|
||||
let shop = await user.get('/shops/time-travelers');
|
||||
|
||||
expect(shop.notes).to.eql(t('timeTravelersPopoverNoSubMobile'));
|
||||
expect(shop.imageName).to.eql('npc_timetravelers');
|
||||
});
|
||||
|
||||
it('does not return mystery sets that are already owned', async () => {
|
||||
await user.update({
|
||||
'items.gear.owned': {
|
||||
head_mystery_201606: true, // eslint-disable-line camelcase
|
||||
armor_mystery_201606: true, // eslint-disable-line camelcase
|
||||
},
|
||||
});
|
||||
|
||||
let shop = await user.get('/shops/time-travelers');
|
||||
|
||||
let categories = shop.categories.map(cat => cat.identifier);
|
||||
|
||||
expect(categories).to.not.include('201606');
|
||||
});
|
||||
|
||||
it('does not return pets and mounts that user already owns', async () => {
|
||||
await user.update({
|
||||
'items.mounts': {
|
||||
'MantisShrimp-Base': true,
|
||||
},
|
||||
'items.pets': {
|
||||
'Mammoth-Base': 5,
|
||||
},
|
||||
});
|
||||
|
||||
let shop = await user.get('/shops/time-travelers');
|
||||
|
||||
let mammothPet = shop.categories
|
||||
.find(cat => cat.identifier === 'pets')
|
||||
.items
|
||||
.find(pet => pet.key === 'Mammoth-Base');
|
||||
let mantisShrimp = shop.categories
|
||||
.find(cat => cat.identifier === 'mounts')
|
||||
.items
|
||||
.find(pet => pet.key === 'MantisShrimp-Base');
|
||||
|
||||
expect(mammothPet).to.not.exist;
|
||||
expect(mantisShrimp).to.not.exist;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user