port tests for score and randomDrop

This commit is contained in:
Matteo Pagliazzi
2015-12-09 10:21:15 +01:00
parent 72b2791bc4
commit 0f3b307f40
3 changed files with 30 additions and 88 deletions

View File

@@ -12,7 +12,7 @@ const CLOSE_ENOUGH = 0.00001;
function _getTaskValue (taskValue) {
if (taskValue < MIN_TASK_VALUE) {
return MIN_TASK_VALUE;
} else if (taskValue < MAX_TASK_VALUE) {
} else if (taskValue > MAX_TASK_VALUE) {
return MAX_TASK_VALUE;
} else {
return taskValue;
@@ -167,7 +167,7 @@ function _changeTaskValue (user, task, direction, times, cron) {
return addToDelta;
}
export default function scoreTask (options = {}, req) {
export default function scoreTask (options = {}, req = {}) {
let {user, task, direction, times = 1, cron = false} = options;
let delta = 0;
let stats = {
@@ -200,7 +200,7 @@ export default function scoreTask (options = {}, req) {
let thl = task.history.length;
if (th[thl - 1] && moment(th[thl - 1].date).isSame(new Date(), 'day')) {
th[thl - 1].value = task.value;
th[thl - 1].value = task.value; // TODO mark modified?
} else {
th.push({
date: Number(new Date()), // TODO are we going to cast history entries?