mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
tests(api): Convert tests to use new api user methods
This commit is contained in:
@@ -1,18 +1,16 @@
|
||||
import {
|
||||
generateUser,
|
||||
requester,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration.helper';
|
||||
|
||||
import { each } from 'lodash';
|
||||
|
||||
describe('POST /user/batch-update', () => {
|
||||
let api, user;
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
return generateUser().then((usr) => {
|
||||
user = usr;
|
||||
api = requester(user);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,24 +18,26 @@ describe('POST /user/batch-update', () => {
|
||||
it('makes batch operations', () => {
|
||||
let task;
|
||||
|
||||
return api.get('/user/tasks').then((tasks) => {
|
||||
return user.get('/user/tasks').then((tasks) => {
|
||||
task = tasks[0];
|
||||
return api.post('/user/batch-update', [
|
||||
|
||||
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((user) => {
|
||||
expect(user.stats.hp).to.eql(30);
|
||||
expect(user.profile.name).to.eql('Samwise');
|
||||
return api.get(`/user/tasks/${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', () => {
|
||||
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',
|
||||
@@ -46,11 +46,11 @@ describe('POST /user/batch-update', () => {
|
||||
each(protectedOperations, (operation, description) => {
|
||||
|
||||
it(`it sends back a 500 error for ${description} operation`, () => {
|
||||
return expect(api.post('/user/batch-update', [
|
||||
{op: operation},
|
||||
return expect(user.post('/user/batch-update', [
|
||||
{ op: operation },
|
||||
])).to.eventually.be.rejected.and.eql({
|
||||
code: 500,
|
||||
text: t('messageUserOperationNotFound', { operation: operation}),
|
||||
text: t('messageUserOperationNotFound', { operation }),
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -58,7 +58,7 @@ describe('POST /user/batch-update', () => {
|
||||
|
||||
context('unknown operations', () => {
|
||||
it('sends back a 500 error', () => {
|
||||
return expect(api.post('/user/batch-update', [
|
||||
return expect(user.post('/user/batch-update', [
|
||||
{op: 'aNotRealOperation'},
|
||||
])).to.eventually.be.rejected.and.eql({
|
||||
code: 500,
|
||||
|
||||
Reference in New Issue
Block a user