mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Add unit test
This commit is contained in:
@@ -2,102 +2,117 @@
|
|||||||
import * as validator from "./validation";
|
import * as validator from "./validation";
|
||||||
|
|
||||||
describe("test name validation", () => {
|
describe("test name validation", () => {
|
||||||
it("should return false", () => {
|
// invalid names taken from ValidationUtilTest.java
|
||||||
// invalid names taken from ValidationUtilTest.java
|
const invalidNames = [
|
||||||
const invalidNames = [
|
"@test",
|
||||||
"@test",
|
" test 123",
|
||||||
" test 123",
|
" test 123 ",
|
||||||
" test 123 ",
|
"test 123 ",
|
||||||
"test 123 ",
|
"test/123",
|
||||||
"test/123",
|
"test%123",
|
||||||
"test%123",
|
"test:123",
|
||||||
"test:123",
|
"t ",
|
||||||
"t ",
|
" t",
|
||||||
" t",
|
" t ",
|
||||||
" t ",
|
"",
|
||||||
"",
|
|
||||||
|
|
||||||
" invalid_name",
|
" invalid_name",
|
||||||
"another%one",
|
"another%one",
|
||||||
"!!!",
|
"!!!",
|
||||||
"!_!"
|
"!_!"
|
||||||
];
|
];
|
||||||
for (let name of invalidNames) {
|
for (let name of invalidNames) {
|
||||||
|
it(`should return false for '${name}'`, () => {
|
||||||
expect(validator.isNameValid(name)).toBe(false);
|
expect(validator.isNameValid(name)).toBe(false);
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
it("should return true", () => {
|
// valid names taken from ValidationUtilTest.java
|
||||||
// valid names taken from ValidationUtilTest.java
|
const validNames = [
|
||||||
const validNames = [
|
"test",
|
||||||
"test",
|
"test.git",
|
||||||
"test.git",
|
"Test123.git",
|
||||||
"Test123.git",
|
"Test123-git",
|
||||||
"Test123-git",
|
"Test_user-123.git",
|
||||||
"Test_user-123.git",
|
"test@scm-manager.de",
|
||||||
"test@scm-manager.de",
|
"test123",
|
||||||
"test123",
|
"tt",
|
||||||
"tt",
|
"t",
|
||||||
"t",
|
"valid_name",
|
||||||
"valid_name",
|
"another1",
|
||||||
"another1",
|
"stillValid",
|
||||||
"stillValid",
|
"this.one_as-well",
|
||||||
"this.one_as-well",
|
"and@this"
|
||||||
"and@this"
|
];
|
||||||
];
|
for (let name of validNames) {
|
||||||
for (let name of validNames) {
|
it(`should return true for '${name}'`, () => {
|
||||||
expect(validator.isNameValid(name)).toBe(true);
|
expect(validator.isNameValid(name)).toBe(true);
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("test mail validation", () => {
|
describe("test mail validation", () => {
|
||||||
it("should return false", () => {
|
// invalid taken from ValidationUtilTest.java
|
||||||
// invalid taken from ValidationUtilTest.java
|
const invalid = [
|
||||||
const invalid = [
|
"ostfalia.de",
|
||||||
"ostfalia.de",
|
"@ostfalia.de",
|
||||||
"@ostfalia.de",
|
"s.sdorra@",
|
||||||
"s.sdorra@",
|
"s.sdorra@ostfalia",
|
||||||
"s.sdorra@ostfalia",
|
"s.sdorra@ ostfalia.de",
|
||||||
"s.sdorra@ ostfalia.de",
|
"s.sdorra@[ostfalia.de"
|
||||||
"s.sdorra@[ostfalia.de"
|
];
|
||||||
];
|
for (let mail of invalid) {
|
||||||
for (let mail of invalid) {
|
it(`should return false for '${mail}'`, () => {
|
||||||
expect(validator.isMailValid(mail)).toBe(false);
|
expect(validator.isMailValid(mail)).toBe(false);
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
it("should return true", () => {
|
// valid taken from ValidationUtilTest.java
|
||||||
// valid taken from ValidationUtilTest.java
|
const valid = [
|
||||||
const valid = [
|
"s.sdorra@ostfalia.de",
|
||||||
"s.sdorra@ostfalia.de",
|
"sdorra@ostfalia.de",
|
||||||
"sdorra@ostfalia.de",
|
"s.sdorra@hbk-bs.de",
|
||||||
"s.sdorra@hbk-bs.de",
|
"s.sdorra@gmail.com",
|
||||||
"s.sdorra@gmail.com",
|
"s.sdorra@t.co",
|
||||||
"s.sdorra@t.co",
|
"s.sdorra@ucla.college",
|
||||||
"s.sdorra@ucla.college",
|
"s.sdorra@example.xn--p1ai",
|
||||||
"s.sdorra@example.xn--p1ai",
|
"s.sdorra@scm.solutions",
|
||||||
"s.sdorra@scm.solutions",
|
"s'sdorra@scm.solutions",
|
||||||
"s'sdorra@scm.solutions",
|
"\"S Sdorra\"@scm.solutions"
|
||||||
"\"S Sdorra\"@scm.solutions"
|
];
|
||||||
];
|
for (let mail of valid) {
|
||||||
for (let mail of valid) {
|
it(`should return true for '${mail}'`, () => {
|
||||||
expect(validator.isMailValid(mail)).toBe(true);
|
expect(validator.isMailValid(mail)).toBe(true);
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("test number validation", () => {
|
describe("test number validation", () => {
|
||||||
it("should return false", () => {
|
const invalid = ["1a", "35gu", "dj6", "45,5", "test"];
|
||||||
const invalid = ["1a", "35gu", "dj6", "45,5", "test"];
|
for (let number of invalid) {
|
||||||
for (let number of invalid) {
|
it(`should return false for '${number}'`, () => {
|
||||||
expect(validator.isNumberValid(number)).toBe(false);
|
expect(validator.isNumberValid(number)).toBe(false);
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
it("should return true", () => {
|
const valid = ["1", "35", "2", "235", "34.4"];
|
||||||
const valid = ["1", "35", "2", "235", "34.4"];
|
for (let number of valid) {
|
||||||
for (let number of valid) {
|
it(`should return true for '${number}'`, () => {
|
||||||
expect(validator.isNumberValid(number)).toBe(true);
|
expect(validator.isNumberValid(number)).toBe(true);
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("test path validation", () => {
|
||||||
|
const invalid = ["//", "some//path", "end//"];
|
||||||
|
for (let path of invalid) {
|
||||||
|
it(`should return false for '${path}'`, () => {
|
||||||
|
expect(validator.isValidPath(path)).toBe(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const valid = ["", "/", "dir", "some/path", "end/"];
|
||||||
|
for (let path of valid) {
|
||||||
|
it(`should return true for '${path}'`, () => {
|
||||||
|
expect(validator.isValidPath(path)).toBe(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user