wip score tests

This commit is contained in:
Matteo Pagliazzi
2015-12-13 23:51:06 +01:00
parent 9394fb0d94
commit 409102ae19
3 changed files with 224 additions and 49 deletions

View File

@@ -2063,7 +2063,7 @@ api.wrap = function(user, main) {
return content.gear.flat[type + "_base_0"]; return content.gear.flat[type + "_base_0"];
} }
return item; return item;
}, },
handleTwoHanded: function(item, type, req) { handleTwoHanded: function(item, type, req) {
var message, currentWeapon, currentShield; var message, currentWeapon, currentShield;
if (type == null) { if (type == null) {
@@ -2071,17 +2071,17 @@ api.wrap = function(user, main) {
} }
currentShield = content.gear.flat[user.items.gear[type].shield]; currentShield = content.gear.flat[user.items.gear[type].shield];
currentWeapon = content.gear.flat[user.items.gear[type].weapon]; currentWeapon = content.gear.flat[user.items.gear[type].weapon];
if (item.type === "shield" && (currentWeapon ? currentWeapon.twoHanded : false)) { if (item.type === "shield" && (currentWeapon ? currentWeapon.twoHanded : false)) {
user.items.gear[type].weapon = 'weapon_base_0'; user.items.gear[type].weapon = 'weapon_base_0';
message = i18n.t('messageTwoHandedUnequip', { message = i18n.t('messageTwoHandedUnequip', {
twoHandedText: currentWeapon.text(req.language), offHandedText: item.text(req.language), twoHandedText: currentWeapon.text(req.language), offHandedText: item.text(req.language),
}, req.language); }, req.language);
} else if (item.twoHanded && (currentShield && user.items.gear[type].shield != "shield_base_0")) { } else if (item.twoHanded && (currentShield && user.items.gear[type].shield != "shield_base_0")) {
user.items.gear[type].shield = "shield_base_0"; user.items.gear[type].shield = "shield_base_0";
message = i18n.t('messageTwoHandedEquip', { message = i18n.t('messageTwoHandedEquip', {
twoHandedText: item.text(req.language), offHandedText: currentShield.text(req.language), twoHandedText: item.text(req.language), offHandedText: currentShield.text(req.language),
}, req.language); }, req.language);
} }
return message; return message;
}, },
@@ -2691,11 +2691,11 @@ api.wrap = function(user, main) {
return computed; return computed;
} }
}); });
return Object.defineProperty(user, 'tasks', { /*return Object.defineProperty(user, 'tasks', {
get: function() { get: function() {
var tasks; var tasks;
tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards); tasks = user.habits.concat(user.dailys).concat(user.todos).concat(user.rewards);
return _.object(_.pluck(tasks, "id"), tasks); return _.object(_.pluck(tasks, "id"), tasks);
} }
}); });*/
}; };

View File

@@ -46,25 +46,77 @@ describe('POST /tasks/:id/score/:direction', () => {
}); });
}); });
it('completes todo when direction is up'); it('completes todo when direction is up', () => {
return api.post(`/tasks/${todo._id}/score/up`)
.then((res) => api.get(`/tasks/${todo._id}`))
.then((task) => expect(task.completed).to.equal(true));
});
it('uncompletes todo when direction is down'); it('uncompletes todo when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/tasks/${todo._id}`))
.then((updatedTask) => {
expect(updatedTask.completed).to.equal(false);
});
});
it('scores up todo even if it is already completed'); // Yes? it('scores up todo even if it is already completed'); // Yes?
it('scores down todo even if it is already uncompleted'); // Yes? it('scores down todo even if it is already uncompleted'); // Yes?
it('increases user\'s mp when direction is up'); it('increases user\'s mp when direction is up', () => {
return api.post(`/tasks/${todo._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp < updatedUser.stats.mp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s mp when direction is down'); it('decreases user\'s mp when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp > updatedUser.stats.mp).to.equal(true);
user = updatedUser;
});
});
it('increases user\'s exp when direction is up'); it('increases user\'s exp when direction is up', () => {
return api.post(`/tasks/${todo._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.exp < updatedUser.stats.exp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s exp when direction is down'); it('decreases user\'s exp when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.exp > updatedUser.stats.exp).to.equal(true);
user = updatedUser;
});
});
it('increases user\'s gold when direction is up'); it('increases user\'s gold when direction is up', () => {
return api.post(`/tasks/${todo._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.gp < updatedUser.stats.gp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s gold when direction is down'); it('decreases user\'s gold when direction is down', () => {
return api.post(`/tasks/${todo._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.gp > updatedUser.stats.gp).to.equal(true);
user = updatedUser;
});
});
}); });
context('dailys', () => { context('dailys', () => {
@@ -79,57 +131,108 @@ describe('POST /tasks/:id/score/:direction', () => {
}); });
}); });
it('completes daily when direction is up'); it('completes daily when direction is up', () => {
return api.post(`/tasks/${daily._id}/score/up`)
.then((res) => api.get(`/tasks/${daily._id}`))
.then((task) => expect(task.completed).to.equal(true));
});
it('uncompletes daily when direction is down'); it('uncompletes daily when direction is down', () => {
return api.post(`/tasks/${daily._id}/score/down`)
.then((res) => api.get(`/tasks/${daily._id}`))
.then((task) => expect(task.completed).to.equal(false));
});
it('scores up daily even if it is already completed'); // Yes? it('scores up daily even if it is already completed'); // Yes?
it('scores down daily even if it is already uncompleted'); // Yes? it('scores down daily even if it is already uncompleted'); // Yes?
it('increases user\'s mp when direction is up'); it('increases user\'s mp when direction is up', () => {
return api.post(`/tasks/${daily._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp < updatedUser.stats.mp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s mp when direction is down'); it('decreases user\'s mp when direction is down', () => {
return api.post(`/tasks/${daily._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp > updatedUser.stats.mp).to.equal(true);
user = updatedUser;
});
});
it('increases user\'s exp when direction is up'); it('increases user\'s exp when direction is up', () => {
return api.post(`/tasks/${daily._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.exp < updatedUser.stats.exp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s exp when direction is down'); it('decreases user\'s exp when direction is down', () => {
return api.post(`/tasks/${daily._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.exp > updatedUser.stats.exp).to.equal(true);
user = updatedUser;
});
});
it('increases user\'s gold when direction is up'); it('increases user\'s gold when direction is up', () => {
return api.post(`/tasks/${daily._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.gp < updatedUser.stats.gp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s gold when direction is down'); it('decreases user\'s gold when direction is down', () => {
return api.post(`/tasks/${daily._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.gp > updatedUser.stats.gp).to.equal(true);
user = updatedUser;
});
});
}); });
context('habits', () => { context('habits', () => {
let habit, minusHabit, plusHabit, neitherHabit; let habit, minusHabit, plusHabit, neitherHabit;
beforeEach(() => { beforeEach(() => {
return Q.all([ return api.post('/tasks', {
api.post('/tasks', { text: 'test habit',
text: 'test habit', type: 'habit',
type: 'habit', }).then((task) => {
}), habit = task;
api.post('/tasks', { return api.post('/tasks', {
text: 'test min habit', text: 'test min habit',
type: 'habit', type: 'habit',
up: false, up: false,
}), });
api.post('/tasks', { }).then((task) => {
minusHabit = task;
return api.post('/tasks', {
text: 'test plus habit', text: 'test plus habit',
type: 'habit', type: 'habit',
down: false, down: false,
}), })
}).then((task) => {
plusHabit = task;
api.post('/tasks', { api.post('/tasks', {
text: 'test neither habit', text: 'test neither habit',
type: 'habit', type: 'habit',
up: false, up: false,
down: false, down: false,
}), })
]).then(tasks => { }).then((task) => {
habit = tasks[0]; neitherHabit = task;
minusHabit = tasks[1];
plusHabit = tasks[2];
neitherHabit = tasks[3];
}); });
}); });
@@ -137,17 +240,59 @@ describe('POST /tasks/:id/score/:direction', () => {
it('prevents minus only habit from scoring up'); // Yes? it('prevents minus only habit from scoring up'); // Yes?
it('increases user\'s mp when direction is up'); it('increases user\'s mp when direction is up', () => {
return api.post(`/tasks/${habit._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp < updatedUser.stats.mp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s mp when direction is down'); it('decreases user\'s mp when direction is down', () => {
return api.post(`/tasks/${habit._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp > updatedUser.stats.mp).to.equal(true);
user = updatedUser;
});
});
it('increases user\'s exp when direction is up'); it('increases user\'s exp when direction is up', () => {
return api.post(`/tasks/${habit._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.exp < updatedUser.stats.exp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s exp when direction is down'); it('decreases user\'s exp when direction is down', () => {
return api.post(`/tasks/${habit._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.exp > updatedUser.stats.exp).to.equal(true);
user = updatedUser;
});
});
it('increases user\'s gold when direction is up'); it('increases user\'s gold when direction is up', () => {
return api.post(`/tasks/${habit._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.gp < updatedUser.stats.gp).to.equal(true);
user = updatedUser;
});
});
it('decreases user\'s gold when direction is down'); it('decreases user\'s gold when direction is down', () => {
return api.post(`/tasks/${habit._id}/score/down`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.gp > updatedUser.stats.gp).to.equal(true);
user = updatedUser;
});
});
}); });
context('reward', () => { context('reward', () => {
@@ -157,17 +302,46 @@ describe('POST /tasks/:id/score/:direction', () => {
return api.post('/tasks', { return api.post('/tasks', {
text: 'test reward', text: 'test reward',
type: 'reward', type: 'reward',
value: 5,
}).then((task) => { }).then((task) => {
reward = task; reward = task;
}); });
}); });
it('purchases reward'); it('purchases reward', () => {
return api.post(`/tasks/${reward._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.hp).to.equal(updatedUser.stats.mp + 5);
user = updatedUser;
});
});
it('does not change user\'s mp'); it('does not change user\'s mp', () => {
return api.post(`/tasks/${reward._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp).to.equal(updatedUser.stats.mp);
user = updatedUser;
});
});
it('does not change user\'s exp'); it('does not change user\'s exp', () => {
return api.post(`/tasks/${reward._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.exp).to.equal(updatedUser.stats.exp);
user = updatedUser;
});
});
it('does not allow a down direction'); it('does not allow a down direction', () => {
return api.post(`/tasks/${reward._id}/score/up`)
.then((res) => api.get(`/user`))
.then((updatedUser) => {
expect(user.stats.mp).to.equal(updatedUser.stats.mp);
user = updatedUser;
});
});
}); });
}); });

View File

@@ -469,7 +469,8 @@ export let schema = new Schema({
}); });
schema.plugin(baseModel, { schema.plugin(baseModel, {
noSet: ['_id', 'apiToken', 'auth.blocked', 'auth.timestamps', 'lastCron', 'auth.local.hashed_password', 'auth.local.salt', 'tasksOrder', 'tags'], // TODO revisit a lot of things are missing
noSet: ['_id', 'apiToken', 'auth.blocked', 'auth.timestamps', 'lastCron', 'auth.local.hashed_password', 'auth.local.salt', 'tasksOrder', 'tags', 'stats'],
private: ['auth.local.hashed_password', 'auth.local.salt'], private: ['auth.local.hashed_password', 'auth.local.salt'],
toJSONTransform: function toJSON (doc) { toJSONTransform: function toJSON (doc) {
// FIXME? Is this a reference to `doc.filters` or just disabled code? Remove? // FIXME? Is this a reference to `doc.filters` or just disabled code? Remove?