Skip to content

Commit 0e6bacc

Browse files
committed
test: validation
1 parent a4c5fc6 commit 0e6bacc

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/tests/validation.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { it, expect } from 'vitest';
2+
import { isValidEmail, isValidUrl } from '../utils/validation';
3+
4+
it("an email name can contain a-zA-Z and numbers with - and .", () => {
5+
expect(isValidEmail("my-email.familyNAME1234@ymail.ae")).toBe(true);
6+
})
7+
8+
it("an email name can be short", () => {
9+
expect(isValidEmail("a@mail.com")).toBe(true);
10+
})
11+
12+
it("an email name can be long", () => {
13+
expect(isValidEmail("mygmailusernameistoolongtoberemembered@mail.com")).toBe(true);
14+
})
15+
16+
it("an email name can not contain special characters", () => {
17+
expect(isValidEmail("my@email.familyName1234@ymail.ae")).toBe(false);
18+
expect(isValidEmail("my&email@ymail.ae")).toBe(false);
19+
expect(isValidEmail("my$email@ymail.ae")).toBe(false);
20+
})
21+
22+
it("an email name can not contain persian or arabic characters", () => {
23+
expect(isValidEmail("مهدي@email.ir")).toBe(false);
24+
expect(isValidEmail("پیمان@gmail.ir")).toBe(false);
25+
})
26+
27+
it("a valid email should follow the username@server.domain format", () => {
28+
expect(isValidEmail("myname.mysurename.q")).toBe(false);
29+
})
30+
31+
it("valid url should have two slash after http[s]:", () => {
32+
expect(isValidUrl("https:/www.google.com")).toBe(false);
33+
})
34+
35+
it("valid url is formatted like http[s]://[www].name.domain", () => {
36+
expect(isValidUrl("https://www.github.com")).toBe(true);
37+
})
38+
39+
it("valid url can either be secured (https) or not (http)", () => {
40+
expect(isValidUrl("http://www.mo.nanoman.space/")).toBe(true);
41+
expect(isValidUrl("https://www.mo.nanoman.space/")).toBe(true);
42+
})
43+
44+
it("valid url should have http or https identifier", () => {
45+
expect(isValidUrl("www.github.com")).toBe(false);
46+
})
47+
48+
it("valid url can have persian or arabic name and domain", () => {
49+
expect(isValidUrl("www.ایران.ربات")).toBe(true);
50+
})

0 commit comments

Comments
 (0)