Merge branch 'api-v3' into api-v3-groups
This commit is contained in:
@@ -3,7 +3,7 @@ import {
|
||||
translate as t,
|
||||
} from '../../../helpers/api-integration.helper';
|
||||
|
||||
import { each } from 'lodash';
|
||||
import { each, get } from 'lodash';
|
||||
|
||||
describe('PUT /user', () => {
|
||||
let user;
|
||||
@@ -12,7 +12,7 @@ describe('PUT /user', () => {
|
||||
user = await generateUser();
|
||||
});
|
||||
|
||||
context('allowed operations', () => {
|
||||
context('Allowed Operations', () => {
|
||||
it('updates the user', async () => {
|
||||
let updatedUser = await user.put('/user', {
|
||||
'profile.name': 'Frodo',
|
||||
@@ -26,7 +26,7 @@ describe('PUT /user', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('top level protected operations', () => {
|
||||
context('Top Level Protected Operations', () => {
|
||||
let protectedOperations = {
|
||||
'gem balance': {balance: 100},
|
||||
auth: {'auth.blocked': true, 'auth.timestamps.created': new Date()},
|
||||
@@ -52,7 +52,7 @@ describe('PUT /user', () => {
|
||||
});
|
||||
});
|
||||
|
||||
context('sub-level protected operations', () => {
|
||||
context('Sub-Level Protected Operations', () => {
|
||||
let protectedOperations = {
|
||||
'class stat': {'stats.class': 'wizard'},
|
||||
};
|
||||
@@ -71,4 +71,106 @@ describe('PUT /user', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('Default Appearance Preferences', () => {
|
||||
let testCases = {
|
||||
shirt: 'yellow',
|
||||
skin: 'ddc994',
|
||||
'hair.color': 'blond',
|
||||
'hair.bangs': 2,
|
||||
'hair.base': 1,
|
||||
'hair.flower': 4,
|
||||
size: 'broad',
|
||||
};
|
||||
|
||||
each(testCases, (item, type) => {
|
||||
const update = {};
|
||||
update[`preferences.${type}`] = item;
|
||||
|
||||
it(`updates user with ${type} that is a default`, async () => {
|
||||
let dbUpdate = {};
|
||||
dbUpdate[`purchased.${type}.${item}`] = true;
|
||||
await user.update(dbUpdate);
|
||||
|
||||
// Sanity checks to make sure user is not already equipped with item
|
||||
expect(get(user.preferences, type)).to.not.eql(item);
|
||||
|
||||
let updatedUser = await user.put('/user', update);
|
||||
|
||||
expect(get(updatedUser.preferences, type)).to.eql(item);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if user tries to update body size with invalid type', async () => {
|
||||
await expect(user.put('/user', {
|
||||
'preferences.size': 'round',
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: ['Must purchase round to set it on preferences.size'],
|
||||
});
|
||||
});
|
||||
|
||||
it('can set beard to default', async () => {
|
||||
await user.update({
|
||||
'purchased.hair.beard': 3,
|
||||
'preferences.hair.beard': 3,
|
||||
});
|
||||
|
||||
let updatedUser = await user.put('/user', {
|
||||
'preferences.hair.beard': 0,
|
||||
});
|
||||
|
||||
expect(updatedUser.preferences.hair.beard).to.eql(0);
|
||||
});
|
||||
|
||||
it('can set mustache to default', async () => {
|
||||
await user.update({
|
||||
'purchased.hair.mustache': 2,
|
||||
'preferences.hair.mustache': 2,
|
||||
});
|
||||
|
||||
let updatedUser = await user.put('/user', {
|
||||
'preferences.hair.mustache': 0,
|
||||
});
|
||||
|
||||
expect(updatedUser.preferences.hair.mustache).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
context('Purchasable Appearance Preferences', () => {
|
||||
let testCases = {
|
||||
background: 'volcano',
|
||||
shirt: 'convict',
|
||||
skin: 'cactus',
|
||||
'hair.base': 7,
|
||||
'hair.beard': 2,
|
||||
'hair.color': 'rainbow',
|
||||
'hair.mustache': 2,
|
||||
};
|
||||
|
||||
each(testCases, (item, type) => {
|
||||
const update = {};
|
||||
update[`preferences.${type}`] = item;
|
||||
|
||||
it(`returns an error if user tries to update ${type} with ${type} the user does not own`, async () => {
|
||||
await expect(user.put('/user', update)).to.eventually.be.rejected.and.eql({
|
||||
code: 401,
|
||||
text: [`Must purchase ${item} to set it on preferences.${type}`],
|
||||
});
|
||||
});
|
||||
|
||||
it(`updates user with ${type} user does own`, async () => {
|
||||
let dbUpdate = {};
|
||||
dbUpdate[`purchased.${type}.${item}`] = true;
|
||||
await user.update(dbUpdate);
|
||||
|
||||
// Sanity check to make sure user is not already equipped with item
|
||||
expect(get(user.preferences, type)).to.not.eql(item);
|
||||
|
||||
let updatedUser = await user.put('/user', update);
|
||||
|
||||
expect(get(updatedUser.preferences, type)).to.eql(item);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('user.fns.updateStats', () => {
|
||||
user = generateUser({});
|
||||
});
|
||||
|
||||
context('no hp', () => {
|
||||
context('No Hp', () => {
|
||||
it('returns 0 if user\'s hp is 0', () => {
|
||||
let stats = {
|
||||
hp: 0,
|
||||
@@ -38,7 +38,19 @@ describe('user.fns.updateStats', () => {
|
||||
});
|
||||
|
||||
context('Stat Allocation', () => {
|
||||
it('Adds an attibute point when user\'s stat points are less than max level', () => {
|
||||
it('adds only attribute points up to user\'s level', () => {
|
||||
let stats = {
|
||||
exp: 261,
|
||||
};
|
||||
|
||||
user.stats.lvl = 10;
|
||||
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.stats.points).to.eql(11);
|
||||
});
|
||||
|
||||
it('adds an attibute point when user\'s stat points are less than max level', () => {
|
||||
let stats = {
|
||||
exp: 3581,
|
||||
};
|
||||
@@ -54,7 +66,7 @@ describe('user.fns.updateStats', () => {
|
||||
expect(user.stats.points).to.eql(1);
|
||||
});
|
||||
|
||||
it('Does not add an attibute point when user\'s stat points are equal to max level', () => {
|
||||
it('does not add an attibute point when user\'s stat points are equal to max level', () => {
|
||||
let stats = {
|
||||
exp: 3581,
|
||||
};
|
||||
@@ -69,5 +81,54 @@ describe('user.fns.updateStats', () => {
|
||||
|
||||
expect(user.stats.points).to.eql(0);
|
||||
});
|
||||
|
||||
it('does not add an attibute point when user\'s stat points + unallocated points are equal to max level', () => {
|
||||
let stats = {
|
||||
exp: 3581,
|
||||
};
|
||||
|
||||
user.stats.lvl = 99;
|
||||
user.stats.str = 25;
|
||||
user.stats.int = 25;
|
||||
user.stats.con = 25;
|
||||
user.stats.per = 15;
|
||||
user.stats.points = 10;
|
||||
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.stats.points).to.eql(10);
|
||||
});
|
||||
|
||||
it('only awards stat points up to level 100 if user is missing unallocated stat points and is over level 100', () => {
|
||||
let stats = {
|
||||
exp: 5581,
|
||||
};
|
||||
|
||||
user.stats.lvl = 104;
|
||||
user.stats.str = 25;
|
||||
user.stats.int = 25;
|
||||
user.stats.con = 25;
|
||||
user.stats.per = 15;
|
||||
user.stats.points = 0;
|
||||
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.stats.points).to.eql(10);
|
||||
});
|
||||
|
||||
// @TODO: Set up sinon sandbox
|
||||
xit('auto allocates stats if automaticAllocation is turned on', () => {
|
||||
sandbox.stub(user.fns, 'autoAllocate');
|
||||
|
||||
let stats = {
|
||||
exp: 261,
|
||||
};
|
||||
|
||||
user.stats.lvl = 10;
|
||||
|
||||
user.fns.updateStats(stats);
|
||||
|
||||
expect(user.fns.autoAllocate).to.be.calledOnce;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"rules": {
|
||||
"func-names": 0,
|
||||
"no-var": 0,
|
||||
"prefer-template": 0
|
||||
},
|
||||
"globals": {
|
||||
"browser": true,
|
||||
"by": true,
|
||||
"element": true,
|
||||
"jasmine": true
|
||||
}
|
||||
}
|
||||
+14
-13
@@ -1,20 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
describe('front page', function() {
|
||||
beforeEach(function(){
|
||||
var fs = require('fs');
|
||||
|
||||
describe('front page', function () {
|
||||
beforeEach(function () {
|
||||
browser.ignoreSynchronization = true;
|
||||
browser.get('/');
|
||||
browser.sleep(1000);
|
||||
});
|
||||
|
||||
// based on https://github.com/angular/protractor/issues/114#issuecomment-29046939
|
||||
afterEach(function(){
|
||||
afterEach(function () {
|
||||
var currentSpec = jasmine.getEnv().currentSpec;
|
||||
var passed = currentSpec.results().passed();
|
||||
if(!passed){
|
||||
if (!passed) {
|
||||
var filename = 'exception_' + currentSpec.description + '.png';
|
||||
browser.takeScreenshot().then(function(png){
|
||||
var fs = require('fs');
|
||||
browser.takeScreenshot().then(function (png) {
|
||||
var buffer = new Buffer(png, 'base64');
|
||||
var stream = fs.createWriteStream(filename);
|
||||
stream.write(buffer);
|
||||
@@ -23,25 +24,25 @@ describe('front page', function() {
|
||||
}
|
||||
});
|
||||
|
||||
it('shows the front page', function(){
|
||||
it('shows the front page', function () {
|
||||
var button = element(by.id('play-btn'));
|
||||
expect(button.getText()).toEqual('Join for free');
|
||||
});
|
||||
|
||||
it("don't login when using wrong credentials", function(){
|
||||
it('does not login when using wrong credentials', function () {
|
||||
var button = element(by.id('play-btn'));
|
||||
button.click();
|
||||
browser.sleep(1000);
|
||||
element(by.model('loginUsername')).sendKeys('username');
|
||||
element(by.model('loginPassword')).sendKeys('pass');
|
||||
var login = element(by.css("#loginForm input[value='Login']"));
|
||||
var login = element(by.css('#loginForm input[value="Login"]'));
|
||||
login.click();
|
||||
var alertDialog = browser.switchTo().alert();
|
||||
expect(alertDialog.getText()).toMatch("Uh-oh - your username or password is incorrect.\n- Make sure your username or email is typed correctly.\n- You may have signed up with Facebook, not email. Double-check by trying Facebook login.\n- If you forgot your password, click \"Forgot Password\" on the habitica.com website's login form.");
|
||||
expect(alertDialog.getText()).toMatch('Uh-oh - your username or password is incorrect.\n- Make sure your username or email is typed correctly.\n- You may have signed up with Facebook, not email. Double-check by trying Facebook login.\n- If you forgot your password, click "Forgot Password" on the habitica.com website\'s login form.');
|
||||
alertDialog.accept();
|
||||
});
|
||||
|
||||
xit('registers a new user', function(){
|
||||
xit('registers a new user', function () {
|
||||
var button = element(by.id('play-btn'));
|
||||
button.click();
|
||||
browser.sleep(1000);
|
||||
@@ -51,10 +52,10 @@ describe('front page', function() {
|
||||
element(by.model('registerVals.email')).sendKeys('user@example.com');
|
||||
element(by.model('registerVals.password')).sendKeys('pass');
|
||||
element(by.model('registerVals.confirmPassword')).sendKeys('pass');
|
||||
var register = element(by.css("#registrationForm input[value='Register']"));
|
||||
var register = element(by.css('#registrationForm input[value="Register"]'));
|
||||
register.click();
|
||||
browser.sleep(1000);
|
||||
browser.getCurrentUrl().then(function(url){
|
||||
browser.getCurrentUrl().then(function (url) {
|
||||
expect(url).not.toMatch(/static\/front/);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user