Skip to content

Commit

Permalink
Added helpers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-elhaddad committed Nov 7, 2023
1 parent daa5b03 commit 6f90b86
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/__tests__/helpers/generateListURL.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import jwt from 'jsonwebtoken';
import { config } from '../../configuration/config';
import shareList from '../../helpers/generateListURL';

jest.mock('jsonwebtoken');

describe('generateListURL', () => {
const mockToken = 'mockToken';
const mockUrl = 'http://localhost:3000/lists/mockToken';
const mockListId = 1;

beforeAll(() => {
(jwt.sign as jest.Mock).mockReturnValue(mockToken);
});

afterAll(() => {
jest.restoreAllMocks();
});

describe('shareList', () => {
it('should generate a shareable URL for a given list ID', () => {
const result = shareList(mockListId);

expect(jwt.sign).toHaveBeenCalledWith(String(mockListId), config.jwtSecretKey);
expect(result).toBe(mockUrl);
});
});
});
32 changes: 32 additions & 0 deletions src/__tests__/helpers/setTaskPriority.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import setTaskPriority from '../../helpers/setTaskPriority';
import Task from '../../types/Task.type';

describe('setTaskPriority', () => {
it('should set task priority to 1 if t_priority is "low"', () => {
const task = { t_priority: 'low' };
setTaskPriority(task as Task);
expect(task.t_priority).toBe(1);
});

it('should set task priority to 2 if t_priority is "medium"', () => {
const task = { t_priority: 'medium' };
setTaskPriority(task as Task);
expect(task.t_priority).toBe(2);
});

it('should set task priority to 3 if t_priority is "high"', () => {
const task = { t_priority: 'high' };
setTaskPriority(task as Task);
expect(task.t_priority).toBe(3);
});

it('should throw error if t_priority is not set', () => {
const task = {};
expect(() => setTaskPriority(task as Task)).toThrowError('Invalid priority. Must be "low", "medium", or "high"');
});

it('should not modify task priority if t_priority is not "low", "medium", or "high"', () => {
const task = { t_priority: 'urgent' };
expect(() => setTaskPriority(task as Task)).toThrowError('Invalid priority. Must be "low", "medium", or "high"');
});
});

0 comments on commit 6f90b86

Please sign in to comment.