Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
feat: add validation function for other checks and use it for bas (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler authored Dec 23, 2020
1 parent 834b780 commit 8f66671
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions server/lib/validation/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const bas = require('./languages/bas');
const en = require('./languages/en');
const it = require('./languages/it');
const ne = require('./languages/ne');
Expand All @@ -8,6 +9,7 @@ const ur = require('./languages/ur');
const or = require('./languages/or');

const VALIDATORS = {
bas,
en,
it,
kab,
Expand Down Expand Up @@ -72,6 +74,8 @@ function validateSentence(validator, sentence) {
validationResult.error = 'Contains multiple sentences';
} else if (!validateWithoutEnglishCharacters(validator, sentence)) {
validationResult.error = 'Contains English characters';
} else if (!validateOthers(validator, sentence)) {
validationResult.error = 'Other issues';
}

return validationResult;
Expand Down Expand Up @@ -131,6 +135,15 @@ function validateWithoutEnglishCharacters(validator, sentence) {
return result;
}

function validateOthers(validator, sentence) {
const result =
typeof validator.filterOthers !== 'function'
? true
: validator.filterOthers(sentence);

return result;
}

function getValidatorFor(language) {
return VALIDATORS[language] || DEFAULT_VALIDATOR;
}
10 changes: 10 additions & 0 deletions server/lib/validation/languages/bas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
filterOthers,
};

function filterOthers(sentence) {
return !sentence.endsWith(' .') &&
!sentence.endsWith('!.') &&
!sentence.endsWith(';') &&
!sentence.endsWith(',');
}
17 changes: 17 additions & 0 deletions server/tests/lib/validation/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,20 @@ test('validates invalid sentences - english chars', validate, 'ru', {
sentence: 'This too',
error: 'Contains English characters',
}]);

test('validates invalid sentences - other rules', validate, 'bas', {
unreviewed: ['This is valid', 'This is wrong .', 'This as well!.', 'No;', 'Definitely not,'],
validated: ['This too'],
}, [{
sentence: 'This is wrong .',
error: 'Other issues',
}, {
sentence: 'This as well!.',
error: 'Other issues',
}, {
sentence: 'No;',
error: 'Other issues',
}, {
sentence: 'Definitely not,',
error: 'Other issues',
}]);

0 comments on commit 8f66671

Please sign in to comment.