mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
70 lines
2.0 KiB
JavaScript
70 lines
2.0 KiB
JavaScript
import {
|
|
generateUser,
|
|
translate as t,
|
|
} from '../../../../helpers/api-integration.helper';
|
|
|
|
import { each } from 'lodash';
|
|
|
|
describe('POST /user/batch-update', () => {
|
|
let user;
|
|
|
|
beforeEach(async () => {
|
|
return generateUser().then((usr) => {
|
|
user = usr;
|
|
});
|
|
});
|
|
|
|
context('allowed operations', () => {
|
|
it('makes batch operations', async () => {
|
|
let task;
|
|
|
|
return user.get('/user/tasks').then((tasks) => {
|
|
task = tasks[0];
|
|
|
|
return user.post('/user/batch-update', [
|
|
{op: 'update', body: {'stats.hp': 30}},
|
|
{op: 'update', body: {'profile.name': 'Samwise'}},
|
|
{op: 'score', params: { direction: 'up', id: task.id }},
|
|
]);
|
|
}).then((updatedUser) => {
|
|
expect(updatedUser.stats.hp).to.eql(30);
|
|
expect(updatedUser.profile.name).to.eql('Samwise');
|
|
|
|
return user.get(`/user/tasks/${task.id}`);
|
|
}).then((task) => {
|
|
expect(task.value).to.be.greaterThan(0);
|
|
});
|
|
});
|
|
});
|
|
|
|
context('development only operations', () => { // These tests will fail if your NODE_ENV is set to 'development' instead of 'testing'
|
|
let protectedOperations = {
|
|
'Add Ten Gems': 'addTenGems',
|
|
'Add Hourglass': 'addHourglass',
|
|
};
|
|
|
|
each(protectedOperations, (operation, description) => {
|
|
|
|
it(`it sends back a 500 error for ${description} operation`, async () => {
|
|
return expect(user.post('/user/batch-update', [
|
|
{ op: operation },
|
|
])).to.eventually.be.rejected.and.eql({
|
|
code: 500,
|
|
text: t('messageUserOperationNotFound', { operation }),
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
context('unknown operations', () => {
|
|
it('sends back a 500 error', async () => {
|
|
return expect(user.post('/user/batch-update', [
|
|
{op: 'aNotRealOperation'},
|
|
])).to.eventually.be.rejected.and.eql({
|
|
code: 500,
|
|
text: t('messageUserOperationNotFound', { operation: 'aNotRealOperation' }),
|
|
});
|
|
});
|
|
});
|
|
});
|