Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ import reducer, {
validationFetched,
validationCanceled,
validationSaveFailed,
syntaxErrorOccurred,
validationFromCollection,
VALIDATOR_CHANGED,
VALIDATION_CANCELED,
VALIDATION_SAVE_FAILED,
VALIDATION_FETCHED,
VALIDATION_ACTION_CHANGED,
VALIDATION_LEVEL_CHANGED,
SYNTAX_ERROR_OCCURRED,
} from './validation';

describe('validation module', function () {
Expand Down Expand Up @@ -119,15 +117,6 @@ describe('validation module', function () {
});
});

describe('#syntaxErrorOccurred', function () {
it('returns the SYNTAX_ERROR_OCCURRED action', function () {
expect(syntaxErrorOccurred({ message: 'Syntax Error!' })).to.deep.equal({
type: SYNTAX_ERROR_OCCURRED,
syntaxError: { message: 'Syntax Error!' },
});
});
});

describe('validationFromCollection', function () {
context('when an error occurs listing the collection', function () {
it('includes the error', function () {
Expand Down Expand Up @@ -324,23 +313,5 @@ describe('validation module', function () {
});
});
});

context('when the action is syntaxErrorOccurred', function () {
it('returns the new state', function () {
const validation = reducer(
undefined,
syntaxErrorOccurred({ message: 'Syntax Error!' })
);

expect(validation).to.deep.equal({
validator: '',
validationAction: 'error',
validationLevel: 'strict',
isChanged: true,
syntaxError: { message: 'Syntax Error!' },
error: null,
});
});
});
});
});
35 changes: 1 addition & 34 deletions packages/compass-schema-validation/src/modules/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,13 @@ interface ValidationLevelChangedAction {
validationLevel: ValidationLevel;
}

/**
* Syntax error occurred action name.
*/
export const SYNTAX_ERROR_OCCURRED = `${PREFIX}/SYNTAX_ERROR_OCCURRED` as const;
interface SyntaxErrorOccurredAction {
type: typeof SYNTAX_ERROR_OCCURRED;
syntaxError: null | { message: string };
}

export type ValidationAction =
| ValidatorChangedAction
| ValidationCanceledAction
| ValidationSaveFailedAction
| ValidationFetchedAction
| ValidationActionChangedAction
| ValidationLevelChangedAction
| SyntaxErrorOccurredAction;
| ValidationLevelChangedAction;

export interface Validation {
validator: string;
Expand Down Expand Up @@ -178,18 +168,6 @@ const changeValidator = (
};
};

/**
* Sets syntax error.
*/
const setSyntaxError = (
state: ValidationState,
action: SyntaxErrorOccurredAction
): ValidationState => ({
...state,
isChanged: true,
syntaxError: action.syntaxError,
});

/**
* Set validation.
*/
Expand Down Expand Up @@ -291,7 +269,6 @@ const MAPPINGS: {
[VALIDATION_SAVE_FAILED]: setError,
[VALIDATION_ACTION_CHANGED]: changeValidationAction,
[VALIDATION_LEVEL_CHANGED]: changeValidationLevel,
[SYNTAX_ERROR_OCCURRED]: setSyntaxError,
};

/**
Expand Down Expand Up @@ -372,16 +349,6 @@ export const validationSaveFailed = (error: {
error,
});

/**
* Action creator for syntax error occurred events.
*/
export const syntaxErrorOccurred = (
syntaxError: null | { message: string }
): SyntaxErrorOccurredAction => ({
type: SYNTAX_ERROR_OCCURRED,
syntaxError,
});

export const fetchValidation = (namespace: {
database: string;
collection: string;
Expand Down
Loading