diff --git a/src/__tests__/helpers/setTaskPriority.test.ts b/src/__tests__/helpers/setTaskPriority.test.ts index c254a46..02610b7 100644 --- a/src/__tests__/helpers/setTaskPriority.test.ts +++ b/src/__tests__/helpers/setTaskPriority.test.ts @@ -20,9 +20,9 @@ describe('setTaskPriority', () => { expect(task.t_priority).toBe(3); }); - it('should throw error if t_priority is not set', () => { + it('should retur null if t_priority is not set', () => { const task = {}; - expect(() => setTaskPriority(task as Task)).toThrowError('Invalid priority. Must be "low", "medium", or "high"'); + expect(setTaskPriority(task as Task)).toBeUndefined(); }); it('should not modify task priority if t_priority is not "low", "medium", or "high"', () => { diff --git a/src/helpers/setTaskPriority.ts b/src/helpers/setTaskPriority.ts index 9b51caa..08dc887 100644 --- a/src/helpers/setTaskPriority.ts +++ b/src/helpers/setTaskPriority.ts @@ -3,13 +3,11 @@ import Task from './../types/Task.type'; * Sets the priority of the task from string to a number. */ const setTaskPriority = (task: Task) => { - const err = Error('Invalid priority. Must be "low", "medium", or "high"'); - if (!task?.t_priority) throw err; - + if (!task.t_priority) return; if (task.t_priority === 'low') task.t_priority = 1; else if (task.t_priority === 'medium') task.t_priority = 2; else if (task.t_priority === 'high') task.t_priority = 3; - else throw err; + else throw Error('Invalid priority. Must be "low", "medium", or "high"'); }; export default setTaskPriority;