Skip to content

Commit

Permalink
Fixed a bug in the setTaskPriority
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-elhaddad committed Nov 7, 2023
1 parent 6f90b86 commit 98dea96
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/helpers/setTaskPriority.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"', () => {
Expand Down
6 changes: 2 additions & 4 deletions src/helpers/setTaskPriority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 98dea96

Please sign in to comment.