Skip to content

Commit

Permalink
Add more tests for DB
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Oct 6, 2020
1 parent 13ccbca commit fc53143
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/api/db.spec.ts
Expand Up @@ -14,6 +14,16 @@ jest.mock('electron', () => ({
}
}));

jest.mock('fs', () => ({
promises: {
stat: jest
.fn()
.mockImplementationOnce(() => Promise.resolve(true))
.mockImplementationOnce(() => Promise.resolve(false))
.mockImplementation(() => Promise.resolve(true))
}
}));

jest.mock('electron-store', () => {
return jest.fn().mockImplementation(() => ({
get: jest.fn().mockImplementation((key: string) => {
Expand All @@ -27,6 +37,11 @@ jest.mock('electron-store', () => {
});

describe('handleRequest', () => {
it('get login state returns logged out correctly', async () => {
const result = await handleRequest({ type: DBRequestType.GET_LOGIN_STATE });
expect(result).toBe(LoginState.LOGGED_OUT);
});

it('init succesfully initializes the electron-store', async () => {
const result = await handleRequest({ type: DBRequestType.INIT, password: 'password' });
expect(result).toBe(true);
Expand All @@ -41,10 +56,16 @@ describe('handleRequest', () => {

it('get login state returns new user by default', async () => {
const result = await handleRequest({ type: DBRequestType.GET_LOGIN_STATE });
// @todo Test other cases
expect(result).toBe(LoginState.NEW_USER);
});

it('get login state returns logged in correctly', async () => {
const initResult = await handleRequest({ type: DBRequestType.INIT, password: 'password' });
expect(initResult).toBe(true);
const result = await handleRequest({ type: DBRequestType.GET_LOGIN_STATE });
expect(result).toBe(LoginState.LOGGED_IN);
});

it('get accounts', async () => {
const result = await handleRequest({ type: DBRequestType.GET_ACCOUNTS });
// @todo
Expand Down

0 comments on commit fc53143

Please sign in to comment.