-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
83 additions
and
10 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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { OptionsError } from '@/common/errors' | ||
import { UrlValidator } from '@/index' | ||
import { createUrlSchema, UrlValidator } from '@/index' | ||
import { UrlValidationError } from '@/url/errors' | ||
|
||
describe('UrlValidator with default options', () => { | ||
|
@@ -116,3 +116,41 @@ describe('UrlValidator with invalid options', () => { | |
expect(() => new UrlValidator({ baseOrigin: 'https://example.com/path' })).toThrow(OptionsError) | ||
}) | ||
}) | ||
|
||
describe('createUrlSchema', () => { | ||
it('should create a schema with default options', () => { | ||
const schema = createUrlSchema() | ||
expect(() => schema.parse('https://example.com')).not.toThrow() | ||
}) | ||
|
||
it('should create a schema with custom options', () => { | ||
const schema = createUrlSchema({ | ||
whitelist: { | ||
protocols: ['http', 'https', 'mailto'], | ||
}, | ||
}) | ||
expect(() => schema.parse('mailto:[email protected]')).not.toThrow() | ||
}) | ||
|
||
it('should throw an error when the options are invalid', () => { | ||
expect(() => createUrlSchema({ baseOrigin: 'invalid' })).toThrow(OptionsError) | ||
expect(() => createUrlSchema({ baseOrigin: 'ftp://example.com' })).toThrow(OptionsError) | ||
expect(() => createUrlSchema({ baseOrigin: 'https://example.com/path' })).toThrow(OptionsError) | ||
}) | ||
|
||
it('should not throw an error when the options are valid', () => { | ||
expect(() => | ||
createUrlSchema({ | ||
whitelist: { | ||
protocols: ['http', 'https'], | ||
hosts: ['example.com'], | ||
}, | ||
}), | ||
).not.toThrow() | ||
}) | ||
|
||
it('should reject relaative URLs when the base URL is not provided', () => { | ||
const schema = createUrlSchema() | ||
expect(() => schema.parse('/path')).toThrow(UrlValidationError) | ||
}) | ||
}) |
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
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