-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add minimal validation to config
- Loading branch information
Showing
7 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
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,40 @@ | ||
import { isPositiveInteger, isURL } from "./validators"; | ||
|
||
describe("isURL", () => { | ||
it("validates if the URL is valid", () => { | ||
const res = isURL("https://example.com"); | ||
expect(res).toBe(true); | ||
}); | ||
|
||
it("returns false if the URL is invalid", () => { | ||
const res = isURL("example.com"); | ||
expect(res).toBe(false); | ||
}); | ||
|
||
it("returns false if the URL is empty", () => { | ||
const res = isURL(""); | ||
expect(res).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("isPositiveInteger", () => { | ||
it("validates if the number is a positive integer", () => { | ||
const res = isPositiveInteger(1); | ||
expect(res).toBe(true); | ||
}); | ||
|
||
it("returns false if the number is not a positive integer", () => { | ||
const res = isPositiveInteger(1.1); | ||
expect(res).toBe(false); | ||
}); | ||
|
||
it("returns false if the number is negative", () => { | ||
const res = isPositiveInteger(-1); | ||
expect(res).toBe(false); | ||
}); | ||
|
||
it("returns false if the number is zero", () => { | ||
const res = isPositiveInteger(0); | ||
expect(res).toBe(false); | ||
}); | ||
}); |
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,12 @@ | ||
export const isPositiveInteger = (value: number): boolean => { | ||
return value > 0 && value % 1 === 0; | ||
}; | ||
|
||
export const isURL = (value: string): boolean => { | ||
try { | ||
new URL(value); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; |
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