diff --git a/test/api/v3/integration/tasks/POST-tasks_user.test.js b/test/api/v3/integration/tasks/POST-tasks_user.test.js index 8b25698d59..29469f78df 100644 --- a/test/api/v3/integration/tasks/POST-tasks_user.test.js +++ b/test/api/v3/integration/tasks/POST-tasks_user.test.js @@ -302,6 +302,17 @@ describe('POST /tasks/user', () => { expect(task.alias).to.eql('a_alias012'); }); + + // This is a special case for iOS requests + it('will round a priority (difficulty)', async () => { + let task = await user.post('/tasks/user', { + text: 'test habit', + type: 'habit', + priority: 0.10000000000005, + }); + + expect(task.priority).to.eql(0.1); + }); }); context('habits', () => { diff --git a/website/server/libs/taskManager.js b/website/server/libs/taskManager.js index 154e07e61c..b956419f73 100644 --- a/website/server/libs/taskManager.js +++ b/website/server/libs/taskManager.js @@ -86,6 +86,11 @@ export async function createTasks (req, res, options = {}) { let taskType = taskData.type; let newTask = new Tasks[taskType](Tasks.Task.sanitize(taskData)); + // Attempt to round priority + if (newTask.priority && !Number.isNaN(Number.parseFloat(newTask.priority))) { + newTask.priority = Number(newTask.priority.toFixed(1)); + } + if (challenge) { newTask.challenge.id = challenge.id; } else if (group) {