-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
daa5b03
commit 6f90b86
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"'); | ||
}); | ||
}); |