2021-10-20 02:10:48 +00:00
|
|
|
import { mocked } from 'ts-jest/utils';
|
|
|
|
|
2021-10-24 03:05:41 +00:00
|
|
|
import { ConfigError, getConfigSettings as _getConfigSettings } from '../../models/helpers/settings';
|
2021-10-20 02:10:48 +00:00
|
|
|
import { validateInsomniaConfig } from '../validate-insomnia-config';
|
|
|
|
|
|
|
|
jest.mock('../../models/helpers/settings');
|
|
|
|
const getConfigSettings = mocked(_getConfigSettings);
|
|
|
|
|
|
|
|
describe('validateInsomniaConfig', () => {
|
2021-10-22 22:35:18 +00:00
|
|
|
it('should return error if there is a parse error', () => {
|
2021-10-20 19:34:28 +00:00
|
|
|
// Arrange
|
|
|
|
const errorReturn = {
|
|
|
|
error: {
|
|
|
|
syntaxError: new SyntaxError('mock syntax error'),
|
|
|
|
fileContents: '{ "mock": ["insomnia", "config"] }',
|
|
|
|
configPath: '/mock/insomnia/config/path',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
getConfigSettings.mockReturnValue(errorReturn);
|
|
|
|
|
|
|
|
// Act
|
2021-10-22 22:35:18 +00:00
|
|
|
const result = validateInsomniaConfig();
|
2021-10-20 19:34:28 +00:00
|
|
|
|
|
|
|
// Assert
|
2021-10-22 22:35:18 +00:00
|
|
|
expect(result.error?.title).toBe('Invalid Insomnia Config');
|
|
|
|
expect(result.error?.message).toMatchSnapshot();
|
2021-10-20 19:34:28 +00:00
|
|
|
});
|
|
|
|
|
2021-10-22 22:35:18 +00:00
|
|
|
it('should return error if there is a config error', () => {
|
2021-10-24 03:05:41 +00:00
|
|
|
// Arrange
|
|
|
|
const errorReturn: ConfigError = {
|
|
|
|
error: {
|
|
|
|
errors: [],
|
|
|
|
humanReadableErrors: [{
|
|
|
|
message: 'message',
|
|
|
|
path: 'path',
|
|
|
|
suggestion: 'suggestion',
|
|
|
|
context: { errorType: 'const' },
|
|
|
|
}],
|
|
|
|
insomniaConfig: '{ "mock": ["insomnia", "config"] }',
|
|
|
|
configPath: '/mock/insomnia/config/path',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
getConfigSettings.mockReturnValue(errorReturn);
|
|
|
|
|
|
|
|
// Act
|
|
|
|
const result = validateInsomniaConfig();
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
expect(result.error?.title).toBe('Invalid Insomnia Config');
|
|
|
|
expect(result.error?.message).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return error if there is an unexpected error', () => {
|
2021-10-20 02:10:48 +00:00
|
|
|
// 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
|
2021-10-22 22:35:18 +00:00
|
|
|
const result = validateInsomniaConfig();
|
2021-10-20 02:10:48 +00:00
|
|
|
|
|
|
|
// Assert
|
2021-10-22 22:35:18 +00:00
|
|
|
expect(result.error?.title).toBe('An unexpected error occured while parsing Insomnia Config');
|
|
|
|
expect(result.error?.message).toMatchSnapshot();
|
2021-10-20 02:10:48 +00:00
|
|
|
});
|
|
|
|
|
2021-10-22 22:35:18 +00:00
|
|
|
it('should not return any errors', () => {
|
2021-10-20 02:10:48 +00:00
|
|
|
// Arrange
|
|
|
|
const validReturn = { enableAnalytics: true };
|
|
|
|
getConfigSettings.mockReturnValue(validReturn);
|
|
|
|
|
|
|
|
// Act
|
2021-10-22 22:35:18 +00:00
|
|
|
const result = validateInsomniaConfig();
|
2021-10-20 02:10:48 +00:00
|
|
|
|
|
|
|
// Assert
|
2021-10-22 22:35:18 +00:00
|
|
|
expect(result.error).not.toBeDefined();
|
2021-10-20 02:10:48 +00:00
|
|
|
});
|
|
|
|
});
|