-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#26] Create test for crud-sessions.js
- Loading branch information
1 parent
13d7377
commit d7601fa
Showing
1 changed file
with
40 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,40 @@ | ||
import crudSessions from '../crud-sessions'; | ||
jest.mock('expo-sqlite'); | ||
|
||
describe('crudSessions function', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('addSession', () => { | ||
it('should insert the session', async () => { | ||
const result = await crudSessions.addSession({ token: 'Bearer abcefg', passcode: '123456' }); | ||
expect(result).toEqual({ rowsAffected: 1 }); | ||
}); | ||
}); | ||
|
||
describe('selectLastSession', () => { | ||
it('should return false if session does not exist', async () => { | ||
const result = await crudSessions.selectLastSession(); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return last session', async () => { | ||
// Mock the result set for select | ||
const sessions = [ | ||
{ | ||
token: 'Bearer 1', | ||
passcode: '123', | ||
}, | ||
{ | ||
token: 'Bearer 2', | ||
passcode: '321', | ||
}, | ||
]; | ||
const mockSelectSql = jest.fn(() => sessions[1]); | ||
crudSessions.selectLastSession = mockSelectSql; | ||
const result = await crudSessions.selectLastSession(); | ||
expect(result).toEqual(sessions[1]); | ||
}); | ||
}); | ||
}); |