Initial commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
var getExtraFields = require('../../../../../src/api/v4/error-handling/carto-error-extender').getExtraFields;
|
||||
|
||||
describe('api/v4/error-handling/carto-error-extender', function () {
|
||||
it('extending an error with no entry in the error list should return default values', function () {
|
||||
var extendedError = getExtraFields({});
|
||||
|
||||
expect(extendedError.friendlyMessage).toEqual('');
|
||||
expect(extendedError.errorCode).toEqual('unknown-error');
|
||||
});
|
||||
|
||||
it('extending an error with an entry in the error list that needs a regex replacement should return proper code and friendly message', function () {
|
||||
var error = {
|
||||
origin: 'windshaft',
|
||||
type: 'analysis',
|
||||
message: 'relation "invalid_value" does not exist'
|
||||
};
|
||||
|
||||
var extendedError = getExtraFields(error);
|
||||
|
||||
expect(extendedError.friendlyMessage).toEqual('Invalid dataset name used. Dataset "invalid_value" does not exist.');
|
||||
expect(extendedError.errorCode).toEqual('windshaft:analysis:invalid-dataset');
|
||||
});
|
||||
|
||||
it('extending an error with an entry that needs two regex replacements ($0 and $1) should return proper code and friendly message', function () {
|
||||
var error = {
|
||||
origin: 'validation',
|
||||
type: 'layer',
|
||||
message: 'wrongInteractivityColumns[column1, column2]#featureClick'
|
||||
};
|
||||
|
||||
var extendedError = getExtraFields(error);
|
||||
|
||||
expect(extendedError.friendlyMessage).toEqual('Columns [column1, column2] set on `featureClick` do not match the columns set in aggregation options.');
|
||||
expect(extendedError.errorCode).toEqual('validation:layer:wrong-interactivity-columns');
|
||||
});
|
||||
|
||||
it('extending an error with an entry in the error list that does not have friendly message should return proper code and original message', function () {
|
||||
var error = {
|
||||
origin: 'windshaft',
|
||||
type: 'analysis',
|
||||
message: 'syntax error: thruster is not a valid SQL word'
|
||||
};
|
||||
|
||||
var extendedError = getExtraFields(error);
|
||||
|
||||
expect(extendedError.friendlyMessage).toEqual('syntax error: thruster is not a valid SQL word');
|
||||
expect(extendedError.errorCode).toEqual('windshaft:analysis:sql-syntax-error');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
var CartoError = require('../../../../../src/api/v4/error-handling/carto-error');
|
||||
|
||||
describe('v4/error-handling/carto-error', function () {
|
||||
it('should return default values if the error is not qualified', function () {
|
||||
var cartoError = new CartoError({
|
||||
someProperty: 'some value'
|
||||
});
|
||||
|
||||
expect(cartoError instanceof Error).toBe(true);
|
||||
expect(cartoError.name).toEqual('CartoError');
|
||||
expect(cartoError.message).toEqual('unexpected error');
|
||||
expect(cartoError.origin).toEqual('generic');
|
||||
expect(cartoError.type).toEqual('');
|
||||
expect(cartoError.errorCode).toEqual('generic:unknown-error');
|
||||
expect(cartoError.originalError).toEqual(jasmine.objectContaining({
|
||||
someProperty: 'some value'
|
||||
}));
|
||||
});
|
||||
|
||||
describe('windshaft error', function () {
|
||||
it('should return the original values and proper friendly message if it is a windshaft error', function () {
|
||||
var cartoError = new CartoError({
|
||||
origin: 'windshaft',
|
||||
type: 'layer',
|
||||
message: 'column "jonica" does not exist'
|
||||
});
|
||||
|
||||
expect(cartoError instanceof Error).toBe(true);
|
||||
expect(cartoError.name).toEqual('CartoError');
|
||||
expect(cartoError.message).toEqual('Invalid column name. Column "jonica" does not exist.');
|
||||
expect(cartoError.origin).toEqual('windshaft');
|
||||
expect(cartoError.type).toEqual('layer');
|
||||
expect(cartoError.errorCode).toEqual('windshaft:layer:column-does-not-exist');
|
||||
expect(cartoError.originalError).toEqual(jasmine.objectContaining({
|
||||
origin: 'windshaft',
|
||||
type: 'layer',
|
||||
message: 'column "jonica" does not exist'
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return the source id if it is a windshaft analysis error and analysis is provided', function () {
|
||||
var cartoError = new CartoError({
|
||||
origin: 'windshaft',
|
||||
type: 'analysis',
|
||||
message: 'column "jonica" does not exist'
|
||||
}, {
|
||||
analysis: {
|
||||
aKey: 'a value',
|
||||
getId: function () { return 'S1'; }
|
||||
}
|
||||
});
|
||||
|
||||
expect(cartoError instanceof Error).toBe(true);
|
||||
expect(cartoError.source).toBeDefined();
|
||||
expect(cartoError.source.aKey).toEqual('a value');
|
||||
expect(cartoError.sourceId).toEqual('S1');
|
||||
});
|
||||
|
||||
it('should return the source id if the windshaft analysis error has that value', function () {
|
||||
var cartoError = new CartoError({
|
||||
origin: 'windshaft',
|
||||
type: 'analysis',
|
||||
message: 'column "jonica" does not exist',
|
||||
analysisId: 'A1'
|
||||
});
|
||||
|
||||
expect(cartoError instanceof Error).toBe(true);
|
||||
expect(cartoError.sourceId).toEqual('A1');
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse ajax error if original error is an ajax response', function () {
|
||||
var cartoError = new CartoError({
|
||||
responseText: '{ "errors": ["an error"] }',
|
||||
statusText: '404'
|
||||
});
|
||||
|
||||
expect(cartoError instanceof Error).toBe(true);
|
||||
expect(cartoError.name).toEqual('CartoError');
|
||||
expect(cartoError.message).toEqual('an error');
|
||||
expect(cartoError.origin).toEqual('ajax');
|
||||
expect(cartoError.type).toEqual('404');
|
||||
expect(cartoError.errorCode).toEqual('ajax:404:unknown-error');
|
||||
expect(cartoError.originalError).toEqual(jasmine.objectContaining({
|
||||
responseText: '{ "errors": ["an error"] }',
|
||||
statusText: '404'
|
||||
}));
|
||||
});
|
||||
|
||||
/**
|
||||
* There's a bug in PhantomJS that don't fill the stack property
|
||||
* of an error. We need to assert that the `stack` property gets
|
||||
* defined so we restrict the spec to run in the browser.
|
||||
*/
|
||||
it('should create an error with a stack trace', function () {
|
||||
var cartoError = new CartoError({
|
||||
someProperty: 'some value'
|
||||
});
|
||||
var userAgent = navigator.userAgent;
|
||||
|
||||
if (userAgent.toLowerCase().indexOf('phantomjs') < 0) {
|
||||
expect(cartoError.stack).toBeDefined();
|
||||
} else {
|
||||
expect(true).toBe(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
var CartoValidationError = require('../../../../../src/api/v4/error-handling/carto-validation-error');
|
||||
|
||||
describe('v4/error-handling/carto-validation-error', function () {
|
||||
it('should return a CartoError with validation as type', function () {
|
||||
var validationError = new CartoValidationError('layer', 'a message');
|
||||
|
||||
expect(validationError.name).toEqual('CartoError');
|
||||
expect(validationError.origin).toEqual('validation');
|
||||
expect(validationError.type).toEqual('layer');
|
||||
expect(validationError.message).toEqual('a message');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user