2021-10-20 02:10:48 +00:00
|
|
|
import electron from 'electron';
|
|
|
|
import { mocked } from 'ts-jest/utils';
|
|
|
|
|
|
|
|
import { getConfigSettings as _getConfigSettings } from '../../models/helpers/settings';
|
|
|
|
import { validateInsomniaConfig } from '../validate-insomnia-config';
|
|
|
|
|
|
|
|
jest.mock('electron');
|
|
|
|
jest.mock('../../models/helpers/settings');
|
|
|
|
const electronAppExit = mocked(electron.app.exit);
|
|
|
|
const electronShowErrorBox = mocked(electron.dialog.showErrorBox);
|
|
|
|
const getConfigSettings = mocked(_getConfigSettings);
|
|
|
|
|
|
|
|
describe('validateInsomniaConfig', () => {
|
|
|
|
it('should show error box and exit if there is an error', () => {
|
|
|
|
// Arrange
|
|
|
|
const errorReturn = {
|
|
|
|
error: {
|
|
|
|
errors: [],
|
2021-10-20 18:06:24 +00:00
|
|
|
humanReadableErrors: [],
|
|
|
|
insomniaConfig: '{ "mock": ["insomnia", "config"] }',
|
|
|
|
configPath: '/mock/insomnia/config/path',
|
2021-10-20 02:10:48 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
getConfigSettings.mockReturnValue(errorReturn);
|
|
|
|
|
|
|
|
// Act
|
|
|
|
validateInsomniaConfig();
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(electronShowErrorBox).toHaveBeenCalled();
|
|
|
|
expect(electronAppExit).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not exit if there are no errors', () => {
|
|
|
|
// Arrange
|
|
|
|
const validReturn = { enableAnalytics: true };
|
|
|
|
getConfigSettings.mockReturnValue(validReturn);
|
|
|
|
|
|
|
|
// Act
|
|
|
|
validateInsomniaConfig();
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(electronShowErrorBox).not.toHaveBeenCalled();
|
|
|
|
expect(electronAppExit).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|