Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/HabitRPG/habitica into n…
Browse files Browse the repository at this point in the history
…egue/market-fixes-2

# Conflicts:
#	website/client/components/shops/buyModal.vue
  • Loading branch information
negue committed Nov 28, 2017
2 parents 6f3fd9d + 4ab89fd commit f883786
Show file tree
Hide file tree
Showing 67 changed files with 446 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var migrationName = '20140831_increase_gems_for_previous_contributions';
* https://github.com/HabitRPG/habitrpg/issues/3933
* Increase Number of Gems for Contributors
* author: Alys (d904bd62-da08-416b-a816-ba797c9ee265)
*
*
* Increase everyone's gems per their contribution level.
* Originally they were given 2 gems per tier.
* Now they are given 3 gems per tier for tiers 1,2,3
Expand Down Expand Up @@ -70,7 +70,7 @@ dbUsers.findEach(query, fields, function(err, user) {
var extraGems = tier; // tiers 1,2,3
if (tier > 3) { extraGems = 3 + (tier - 3) * 2; }
if (tier == 8) { extraGems = 11; }
extraBalance = extraGems / 4;
var extraBalance = extraGems / 4;
set['balance'] = user.balance + extraBalance;

// Capture current state of user:
Expand Down
4 changes: 2 additions & 2 deletions migrations/20151021_usernames_emails_lowercase.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function findUsers(gt){
console.log('User: ', countUsers, user._id);

var update = {
$set: {};
$set: {}
};

if(user.auth && user.auth.local) {
Expand All @@ -60,4 +60,4 @@ function findUsers(gt){
});
};

findUsers();
findUsers();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"vue-router": "^3.0.0",
"vue-style-loader": "^3.0.0",
"vue-template-compiler": "^2.5.2",
"vuedraggable": "^2.15.0",
"vuejs-datepicker": "git://github.com/habitrpg/vuejs-datepicker#825a866b6a9c52dd8c588a3e8b900880875ce914",
"webpack": "^2.2.1",
"webpack-merge": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
generateUser,
translate as t,
} from '../../../../helpers/api-v3-integration.helper';
import config from '../../../../../config.json';
import { v4 as generateUUID } from 'uuid';

describe('POST /groups/:id/chat/:id/clearflags', () => {
Expand Down Expand Up @@ -74,7 +75,7 @@ describe('POST /groups/:id/chat/:id/clearflags', () => {
expect(messages[0].flagCount).to.eql(0);
});

it('can unflag a system message', async () => {
it('can\'t flag a system message', async () => {
let { group, members } = await createAndPopulateGroup({
groupDetails: {
type: 'party',
Expand All @@ -95,13 +96,15 @@ describe('POST /groups/:id/chat/:id/clearflags', () => {
await member.post('/user/class/cast/mpheal');

let [skillMsg] = await member.get(`/groups/${group.id}/chat`);

await member.post(`/groups/${group._id}/chat/${skillMsg.id}/flag`);
await admin.post(`/groups/${group._id}/chat/${skillMsg.id}/clearflags`);

let messages = await members[0].get(`/groups/${group._id}/chat`);
expect(messages[0].id).to.eql(skillMsg.id);
expect(messages[0].flagCount).to.eql(0);
await expect(member.post(`/groups/${group._id}/chat/${skillMsg.id}/flag`))
.to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('messageCannotFlagSystemMessages', {communityManagerEmail: config.EMAILS.COMMUNITY_MANAGER_EMAIL}),
});
// let messages = await members[0].get(`/groups/${group._id}/chat`);
// expect(messages[0].id).to.eql(skillMsg.id);
// expect(messages[0].flagCount).to.eql(0);
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/api/v3/integration/coupons/GET-coupons.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
generateUser,
translate as t,
resetHabiticaDB,
} from '../../../../helpers/api-v3-integration.helper';
import apiMessages from '../../../../../website/server/libs/apiMessages';

describe('GET /coupons/', () => {
let user;
Expand All @@ -19,7 +19,7 @@ describe('GET /coupons/', () => {
await expect(user.get('/coupons')).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('noSudoAccess'),
message: apiMessages('noSudoAccess'),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
resetHabiticaDB,
} from '../../../../helpers/api-v3-integration.helper';
import couponCode from 'coupon-code';
import apiMessages from '../../../../../website/server/libs/apiMessages';

describe('POST /coupons/generate/:event', () => {
let user;
Expand All @@ -25,7 +26,7 @@ describe('POST /coupons/generate/:event', () => {
await expect(user.post('/coupons/generate/aaa')).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('noSudoAccess'),
message: apiMessages('noSudoAccess'),
});
});

Expand Down
57 changes: 45 additions & 12 deletions test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,31 @@ describe('POST /tasks/:id/score/:direction', () => {
});

it('uncompletes todo when direction is down', async () => {
await user.post(`/tasks/${todo._id}/score/up`);
await user.post(`/tasks/${todo._id}/score/down`);
let updatedTask = await user.get(`/tasks/${todo._id}`);

expect(updatedTask.completed).to.equal(false);
expect(updatedTask.dateCompleted).to.be.a('undefined');
});

it('scores up todo even if it is already completed'); // Yes?
it('doesn\'t let a todo be completed twice', async () => {
await user.post(`/tasks/${todo._id}/score/up`);
await expect(user.post(`/tasks/${todo._id}/score/up`))
.to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('sessionOutdated'),
});
});

it('scores down todo even if it is already uncompleted'); // Yes?
it('doesn\'t let a todo be uncompleted twice', async () => {
await expect(user.post(`/tasks/${todo._id}/score/down`)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('sessionOutdated'),
});
});

context('user stats when direction is up', () => {
let updatedUser;
Expand All @@ -163,23 +178,25 @@ describe('POST /tasks/:id/score/:direction', () => {
});

context('user stats when direction is down', () => {
let updatedUser;
let updatedUser, initialUser;

beforeEach(async () => {
await user.post(`/tasks/${todo._id}/score/up`);
initialUser = await user.get('/user');
await user.post(`/tasks/${todo._id}/score/down`);
updatedUser = await user.get('/user');
});

it('decreases user\'s mp', () => {
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
expect(updatedUser.stats.mp).to.be.lessThan(initialUser.stats.mp);
});

it('decreases user\'s exp', () => {
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
expect(updatedUser.stats.exp).to.be.lessThan(initialUser.stats.exp);
});

it('decreases user\'s gold', () => {
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
expect(updatedUser.stats.gp).to.be.lessThan(initialUser.stats.gp);
});
});
});
Expand All @@ -202,6 +219,7 @@ describe('POST /tasks/:id/score/:direction', () => {
});

it('uncompletes daily when direction is down', async () => {
await user.post(`/tasks/${daily._id}/score/up`);
await user.post(`/tasks/${daily._id}/score/down`);
let task = await user.get(`/tasks/${daily._id}`);

Expand All @@ -222,9 +240,22 @@ describe('POST /tasks/:id/score/:direction', () => {
expect(task.nextDue.length).to.eql(6);
});

it('scores up daily even if it is already completed'); // Yes?
it('doesn\'t let a daily be completed twice', async () => {
await user.post(`/tasks/${daily._id}/score/up`);
await expect(user.post(`/tasks/${daily._id}/score/up`)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('sessionOutdated'),
});
});

it('scores down daily even if it is already uncompleted'); // Yes?
it('doesn\'t let a daily be uncompleted twice', async () => {
await expect(user.post(`/tasks/${daily._id}/score/down`)).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('sessionOutdated'),
});
});

context('user stats when direction is up', () => {
let updatedUser;
Expand All @@ -248,23 +279,25 @@ describe('POST /tasks/:id/score/:direction', () => {
});

context('user stats when direction is down', () => {
let updatedUser;
let updatedUser, initialUser;

beforeEach(async () => {
await user.post(`/tasks/${daily._id}/score/up`);
initialUser = await user.get('/user');
await user.post(`/tasks/${daily._id}/score/down`);
updatedUser = await user.get('/user');
});

it('decreases user\'s mp', () => {
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
expect(updatedUser.stats.mp).to.be.lessThan(initialUser.stats.mp);
});

it('decreases user\'s exp', () => {
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
expect(updatedUser.stats.exp).to.be.lessThan(initialUser.stats.exp);
});

it('decreases user\'s gold', () => {
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
expect(updatedUser.stats.gp).to.be.lessThan(initialUser.stats.gp);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ describe('POST /tasks/:id/score/:direction', () => {
});

it('should update the history', async () => {
let newCron = new Date(2015, 11, 20);

await user.post('/debug/set-cron', {
lastCron: newCron,
});

await user.post('/cron');
await user.post(`/tasks/${usersChallengeTaskId}/score/up`);

let tasks = await user.get(`/tasks/challenge/${challenge._id}`);
Expand Down
2 changes: 1 addition & 1 deletion test/api/v3/integration/user/DELETE-user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe('DELETE /user', () => {
})).to.eventually.be.rejected.and.eql({
code: 401,
error: 'NotAuthorized',
message: t('incorrectDeletePhrase'),
message: t('incorrectDeletePhrase', {magicWord: 'DELETE'}),
});
});

Expand Down
3 changes: 2 additions & 1 deletion test/api/v3/unit/middlewares/ensureAccessRight.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import i18n from '../../../../../website/common/script/i18n';
import { ensureAdmin, ensureSudo } from '../../../../../website/server/middlewares/ensureAccessRight';
import { NotAuthorized } from '../../../../../website/server/libs/errors';
import apiMessages from '../../../../../website/server/libs/apiMessages';

describe('ensure access middlewares', () => {
let res, req, next;
Expand Down Expand Up @@ -42,7 +43,7 @@ describe('ensure access middlewares', () => {

ensureSudo(req, res, next);

expect(next).to.be.calledWith(new NotAuthorized(i18n.t('noSudoAccess')));
expect(next).to.be.calledWith(new NotAuthorized(apiMessages('noSudoAccess')));
});

it('passes when user is a sudo user', () => {
Expand Down
31 changes: 31 additions & 0 deletions test/client/unit/specs/components/groups/membersModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Vue from 'vue';
import MembersModalComponent from 'client/components/groups/membersModal.vue';

describe('Members Modal Component', () => {
describe('Party Sort', () => {
let CTor;
let vm;

beforeEach(() => {
CTor = Vue.extend(MembersModalComponent);
vm = new CTor().$mount();
});

afterEach(() => {
vm.$destroy();
});

it('should have an empty object as sort-option at start', () => {
const defaultData = vm.data();
expect(defaultData.sortOption).to.eq({});
});

it('should accept sort-option object', () => {
const sortOption = vm.data().sortOption[0];
vm.sort(sortOption);
Vue.nextTick(() => {
expect(vm.data().sortOption).to.eq(sortOption);
});
});
});
});
20 changes: 14 additions & 6 deletions webpack/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ const path = require('path');
const staticAssetsDirectory = './website/static/.'; // The folder where static files (not processed) live
const prodEnv = require('./prod.env');
const devEnv = require('./dev.env');
const nconf = require('nconf');
const setupNconf = require('../../website/server/libs/setupNconf');

let configFile = path.join(path.resolve(__dirname, '../../config.json'));

setupNconf(configFile);

const DEV_BASE_URL = nconf.get('BASE_URL');

module.exports = {
build: {
Expand Down Expand Up @@ -33,25 +41,25 @@ module.exports = {
assetsPublicPath: '/',
staticAssetsDirectory,
proxyTable: {
// proxy all requests starting with /api/v3 to localhost:3000
// proxy all requests starting with /api/v3 to IP:PORT as specified in the top-level config
'/api/v3': {
target: 'http://localhost:3000',
target: DEV_BASE_URL,
changeOrigin: true,
},
'/stripe': {
target: 'http://localhost:3000',
target: DEV_BASE_URL,
changeOrigin: true,
},
'/amazon': {
target: 'http://localhost:3000',
target: DEV_BASE_URL,
changeOrigin: true,
},
'/paypal': {
target: 'http://localhost:3000',
target: DEV_BASE_URL,
changeOrigin: true,
},
'/logout': {
target: 'http://localhost:3000',
target: DEV_BASE_URL,
changeOrigin: true,
},
},
Expand Down
10 changes: 2 additions & 8 deletions webpack/config/prod.env.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
const nconf = require('nconf');
const { join, resolve } = require('path');
const setupNconf = require('../../website/server/libs/setupNconf');

const PATH_TO_CONFIG = join(resolve(__dirname, '../../config.json'));
let configFile = PATH_TO_CONFIG;

nconf
.argv()
.env()
.file('user', configFile);

nconf.set('IS_PROD', nconf.get('NODE_ENV') === 'production');
nconf.set('IS_DEV', nconf.get('NODE_ENV') === 'development');
nconf.set('IS_TEST', nconf.get('NODE_ENV') === 'test');
setupNconf(configFile);

// @TODO: Check if we can import from client. Items like admin emails can be imported
// and that should be prefered
Expand Down
Loading

0 comments on commit f883786

Please sign in to comment.