-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/refactor validation for emailAdress and website (#122)
* refactor: email validation * fix: Email-Validation and add a test for it * fix: Website Validation and add a test for it * feat: change regexp from Url * chore: version bump * refactor: test for website * refactor: changed wording of the test * refactor: Tests for Email and Website * refactor: change string in regexp * refactor: test for Website and AbstractURL * refactor: name and AbstractURL without escape * refactor: Change Tests and RegExp * chore: version bump * feat: make regexp more readable * fix: changed an error * fix: error and last changes * feat: last changes * chore: version bump * fix: delete unnecessary file --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f7dd1f2
commit 45dc922
Showing
7 changed files
with
100 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { ParsingError } from "@js-soft/ts-serval"; | ||
import { EMailAddress } from "../../src"; | ||
|
||
describe("Test valid EMailAddresses", () => { | ||
const validEMailAddresses = ["peter123@inwind.it", "peter123@inwänd.it"]; | ||
|
||
test.each(validEMailAddresses)("EMail %s is recognized as valid", (email) => { | ||
const validEMailAddress = EMailAddress.from({ value: email }); | ||
expect(validEMailAddress.value.toString()).toBe(email); | ||
}); | ||
}); | ||
|
||
describe("Test invalid EMailAddresses", () => { | ||
const invalidEMailAddresses = ["Hugo Becker@gmx.de", "Becker@gmx", "Becker@gmx-.de", "Becker@gmx-.de", ".Becker@gmx.de", "test@.address", "test@test..address"]; | ||
|
||
test.each(invalidEMailAddresses)("EMail %s is recognized as invalid", (email) => { | ||
const invalidEMailAddressCall = () => { | ||
EMailAddress.from({ | ||
value: email | ||
}); | ||
}; | ||
expect(invalidEMailAddressCall).toThrow( | ||
new ParsingError( | ||
"EMailAddress", | ||
"value", | ||
"Value does not match regular expression /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@([A-Za-z0-9ÄäÖöÜüß]([A-Za-z0-9ÄäÖöÜüß-]{0,61}[A-Za-z0-9ÄäÖöÜüß])?\\.)+[A-Za-z0-9ÄäÖöÜüß][A-Za-z0-9ÄäÖöÜüß-]{0,61}[A-Za-z0-9ÄäÖöÜüß]$/" | ||
) | ||
); | ||
}); | ||
test("returns an error when trying to create an Attribute Value Type EMailAddress wich is empty", function () { | ||
const invalidEMailAddressCall = () => { | ||
EMailAddress.from({ | ||
value: "" | ||
}); | ||
}; | ||
expect(invalidEMailAddressCall).toThrow(new ParsingError("EMailAddress", "value", "Value is shorter than 3 characters")); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ParsingError } from "@js-soft/ts-serval"; | ||
import { Website } from "../../src"; | ||
|
||
describe("Test valid URLs", () => { | ||
const validUrls = [ | ||
"www.google.com", | ||
"https://inwänd.it", | ||
"http://inwind.it", | ||
"https://enmeshed.de/blog/meilenstein-enmeshed-als-komponente-ablage-in-mein-bildungsraum-geht-in-die-testphase-der-beta-version/", | ||
"www.foo.www.www.enmeshed.eu", | ||
"https://example.org:8080/mein/ordner/bericht" | ||
]; | ||
|
||
test.each(validUrls)("URL %s is recognized as valid", (url) => { | ||
const validWebsite = Website.from({ value: url }); | ||
expect(validWebsite.value.toString()).toBe(url); | ||
}); | ||
}); | ||
|
||
describe("Test invalid URLs", () => { | ||
const invalidUrls = ["google-.de", "www.google", "www.-google", "https://inwind.test it"]; | ||
|
||
test.each(invalidUrls)("URL %s is recognized as invalid", (url) => { | ||
const invalidWebsiteCall = () => { | ||
Website.from({ | ||
value: url | ||
}); | ||
}; | ||
expect(invalidWebsiteCall).toThrow( | ||
new ParsingError( | ||
"Website", | ||
"value", | ||
"Value does not match regular expression /^([A-Za-z]+:\\/\\/)?((www\\.)|(?!www\\.))([A-Za-z0-9ÄäÖöÜüß]([A-Za-zÄäÖöÜüß0-9-]{0,61}[A-Za-zÄäÖöÜüß0-9])?\\.)+([A-Za-z0-9ÄäÖöÜüß]([A-Za-zÄäÖöÜüß0-9-]{0,61}[A-Za-zÄäÖöÜüß0-9])?)(:[0-9]+)?(\\/[A-Za-zÄäÖöÜüß0-9?#@!$&'()*+,;=%-]*)*$/" | ||
) | ||
); | ||
}); | ||
test("returns an error when trying to create an Attribute Value Type Website wich is empty", function () { | ||
const invalidWebsiteCall = () => { | ||
Website.from({ | ||
value: "" | ||
}); | ||
}; | ||
expect(invalidWebsiteCall).toThrow(new ParsingError("Website", "value", "Value is shorter than 3 characters")); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters