mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
edit sitekey, router pattern matching, sitekey update optimization, rm level delete and level err handling
This commit is contained in:
@@ -34,11 +34,15 @@ class Levels {
|
||||
add = (newLevel: Level) => {
|
||||
log.debug(`[levels/index.ts] levels lenght: ${this.levels.length}`);
|
||||
if (newLevel.difficulty_factor <= 0) {
|
||||
throw new Error('Difficulty must be greater than zero');
|
||||
throw new Error(
|
||||
`Level ${this.levels.length}'s difficulty must be greater than zero`,
|
||||
);
|
||||
}
|
||||
|
||||
if (newLevel.visitor_threshold <= 0) {
|
||||
throw new Error('Visitors must be greater than zero');
|
||||
throw new Error(
|
||||
`Level ${this.levels.length}'s visitors must be greater than zero`,
|
||||
);
|
||||
}
|
||||
|
||||
if (this.levels.length == 0) {
|
||||
@@ -50,10 +54,10 @@ class Levels {
|
||||
|
||||
this.levels.forEach(level => {
|
||||
if (level.visitor_threshold >= newLevel.visitor_threshold) {
|
||||
const msg = `Level: ${newLevel} visitor count has to greater than previous levels. See ${count}`;
|
||||
const msg = `Level ${this.levels.length}'s visitor count should be greater than previous levels(Level ${count} is greater)`;
|
||||
throw new Error(msg);
|
||||
} else if (level.difficulty_factor >= newLevel.difficulty_factor) {
|
||||
const msg = `Level ${this.levels.length} difficulty has to greater than previous levels See ${count}`;
|
||||
const msg = `Level ${this.levels.length} difficulty should be greater than previous levels(Level ${count} is greater)`;
|
||||
throw new Error(msg);
|
||||
} else {
|
||||
count++;
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
import {LEVELS, Level} from './index';
|
||||
import {level1, level1visErr, level1diffErr, level2} from '../setupTests';
|
||||
|
||||
const visitorErr = 'visitor count has to greater than previous levels';
|
||||
const difficultyErr = 'difficulty has to greater than previous levels';
|
||||
const visitorErr = 'visitor count should be greater than previous levels';
|
||||
const difficultyErr = 'difficulty should be greater than previous levels';
|
||||
|
||||
const zeroVisError = 'Visitors must be greater than zero';
|
||||
const zeroDiffError = 'Difficulty must be greater than zero';
|
||||
const zeroVisError = 'visitors must be greater than zero';
|
||||
const zeroDiffError = 'difficulty must be greater than zero';
|
||||
|
||||
const zeroVis: Level = {
|
||||
difficulty_factor: 10,
|
||||
@@ -71,12 +71,12 @@ it('LEVELS works', () => {
|
||||
try {
|
||||
LEVELS.add(zeroVis);
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual(zeroVisError);
|
||||
expect(e.message).toContain(zeroVisError);
|
||||
}
|
||||
// difficulty is 0
|
||||
try {
|
||||
LEVELS.add(zeroDiff);
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual(zeroDiffError);
|
||||
expect(e.message).toContain(zeroDiffError);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -43,7 +43,7 @@ const updateLevel = (e: Event) => {
|
||||
const updatedLevel = getLevelFields(level);
|
||||
LEVELS.update(updatedLevel, level);
|
||||
} catch (e) {
|
||||
createError(e);
|
||||
createError(e.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -17,9 +17,12 @@
|
||||
|
||||
import validateLevel from './validateLevel';
|
||||
import {getAddForm, level1, fillAddLevel} from '../setupTests';
|
||||
import setup from '../../../../../components/error/setUpTests';
|
||||
|
||||
document.body.innerHTML = getAddForm();
|
||||
|
||||
document.body.appendChild(setup());
|
||||
|
||||
it('validate levels fields works', () => {
|
||||
// null error
|
||||
expect(validateLevel(1)).toEqual(false);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
import {LEVELS} from './index';
|
||||
import getLevelFields from './getLevelFields';
|
||||
import createError from '../../../../../components/error/';
|
||||
|
||||
/**
|
||||
* Fetches level from DOM using the ID passesd and validates
|
||||
@@ -28,6 +29,7 @@ const validateLevel = (id: number) => {
|
||||
LEVELS.add(level);
|
||||
return true;
|
||||
} catch (e) {
|
||||
createError(e.message);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user