move name validation to a non type specific validator

This commit is contained in:
Sebastian Sdorra
2018-08-08 13:45:27 +02:00
parent 3ff6129b09
commit 378a82244d
6 changed files with 64 additions and 73 deletions

View File

@@ -0,0 +1,6 @@
// @flow
const nameRegex = /^([A-z0-9.\-_@]|[^ ]([A-z0-9.\-_@ ]*[A-z0-9.\-_@]|[^\s])?)$/;
export const isNameValid = (name: string) => {
return nameRegex.test(name);
};

View File

@@ -0,0 +1,52 @@
// @flow
import * as validator from "./validation";
describe("test name validation", () => {
it("should return false", () => {
// invalid names taken from ValidationUtilTest.java
const invalidNames = [
" test 123",
" test 123 ",
"test 123 ",
"test/123",
"test%123",
"test:123",
"t ",
" t",
" t ",
"",
" invalid_name",
"another%one",
"!!!",
"!_!"
];
for (let name of invalidNames) {
expect(validator.isNameValid(name)).toBe(false);
}
});
it("should return true", () => {
// valid names taken from ValidationUtilTest.java
const validNames = [
"test",
"test.git",
"Test123.git",
"Test123-git",
"Test_user-123.git",
"test@scm-manager.de",
"test 123",
"tt",
"t",
"valid_name",
"another1",
"stillValid",
"this.one_as-well",
"and@this"
];
for (let name of validNames) {
expect(validator.isNameValid(name)).toBe(true);
}
});
});

View File

@@ -1,14 +1,8 @@
// @flow
import { isNameValid } from "../../components/validation";
//TODO: How should a group be validated
//TODO: Tests!
const nameRegex = /^([A-z0-9.\-_@]|[^ ]([A-z0-9.\-_@ ]*[A-z0-9.\-_@]|[^\s])?)$/;
export const isNameValid = (name: string) => {
return nameRegex.test(name);
};
export { isNameValid };
export const isMemberNameValid = (name: string) => {
return nameRegex.test(name);
}
return isNameValid(name);
};

View File

@@ -1,20 +0,0 @@
//@flow
import * as validator from "./groupValidation";
describe("validator", () => {
it("should validate allowed names correctly", () => {
const validNames = ["valid_name", "another1", "stillValid", "this.one_as-well", "and@this"];
for (let validName of validNames) {
expect(validator.isNameValid(validName)).toBeTruthy();
}
});
it("should reject invalid names", () => {
const invalidNames = [" invalid_name", "another%one", "!!!", "!_!"];
for (let invalidName of invalidNames) {
expect(validator.isNameValid(invalidName)).toBeFalsy();
}
})
});

View File

@@ -1,10 +1,8 @@
// @flow
const nameRegex = /^([A-z0-9.\-_@]|[^ ]([A-z0-9.\-_@ ]*[A-z0-9.\-_@]|[^\s])?)$/;
import { isNameValid } from "../../components/validation";
export const isNameValid = (name: string) => {
return nameRegex.test(name);
};
export { isNameValid };
export const isDisplayNameValid = (displayName: string) => {
if (displayName) {

View File

@@ -1,45 +1,6 @@
// @flow
import * as validator from "./userValidation";
describe("test name validation", () => {
it("should return false", () => {
// invalid names taken from ValidationUtilTest.java
const invalidNames = [
" test 123",
" test 123 ",
"test 123 ",
"test/123",
"test%123",
"test:123",
"t ",
" t",
" t ",
""
];
for (let name of invalidNames) {
expect(validator.isNameValid(name)).toBe(false);
}
});
it("should return true", () => {
// valid names taken from ValidationUtilTest.java
const validNames = [
"test",
"test.git",
"Test123.git",
"Test123-git",
"Test_user-123.git",
"test@scm-manager.de",
"test 123",
"tt",
"t"
];
for (let name of validNames) {
expect(validator.isNameValid(name)).toBe(true);
}
});
});
describe("test displayName validation", () => {
it("should return false", () => {
expect(validator.isDisplayNameValid("")).toBe(false);