mirror of
https://github.com/itdoginfo/podkop.git
synced 2026-01-28 21:30:41 +03:00
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { validateUrl } from '../validateUrl';
|
|
|
|
const validUrls = [
|
|
['Simple HTTP', 'http://example.com'],
|
|
['Simple HTTPS', 'https://example.com'],
|
|
['With path', 'https://example.com/path/to/page'],
|
|
['With query', 'https://example.com/?q=test'],
|
|
['With port', 'http://example.com:8080'],
|
|
['With subdomain', 'https://sub.example.com'],
|
|
];
|
|
|
|
const invalidUrls = [
|
|
['Invalid format', 'not a url'],
|
|
['Missing protocol', 'example.com'],
|
|
['Unsupported protocol (ftp)', 'ftp://example.com'],
|
|
['Unsupported protocol (ws)', 'ws://example.com'],
|
|
['Empty string', ''],
|
|
['Without tld', 'https://google'],
|
|
];
|
|
|
|
describe('validateUrl', () => {
|
|
describe.each(validUrls)('Valid URL: %s', (_desc, url) => {
|
|
it(`returns valid=true for "${url}"`, () => {
|
|
const res = validateUrl(url);
|
|
expect(res.valid).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe.each(invalidUrls)('Invalid URL: %s', (_desc, url) => {
|
|
it(`returns valid=false for "${url}"`, () => {
|
|
const res = validateUrl(url);
|
|
expect(res.valid).toBe(false);
|
|
});
|
|
});
|
|
|
|
it('allows custom protocol list (ftp)', () => {
|
|
const res = validateUrl('ftp://example.com', ['ftp:']);
|
|
expect(res.valid).toBe(true);
|
|
});
|
|
});
|