mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
Ported sell function. Add unit tests. Create sell route. Add integration tests
This commit is contained in:
42
test/api/v3/integration/user/POST-user_sell.test.js
Normal file
42
test/api/v3/integration/user/POST-user_sell.test.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration/v3';
|
||||
import content from '../../../../../common/script/content';
|
||||
|
||||
describe('POST /user/sell/:type/:key', () => {
|
||||
let user;
|
||||
let type = 'eggs';
|
||||
let key = 'Wolf';
|
||||
|
||||
beforeEach(async () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
// More tests in common code unit tests
|
||||
|
||||
it('returns an error when user does not have item', async () => {
|
||||
await expect(user.post(`/user/sell/${type}/${key}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('userItemsKeyNotFound', {type}),
|
||||
});
|
||||
});
|
||||
|
||||
it('sells an item', async () => {
|
||||
await user.update({
|
||||
items: {
|
||||
eggs: {
|
||||
Wolf: 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
let response = await user.post(`/user/sell/${type}/${key}`);
|
||||
await user.sync();
|
||||
|
||||
expect(response.message).to.equal(t('sold', {type, key}));
|
||||
expect(user.stats.gp).to.equal(content[type][key].value);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user