mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
test: remove cute data structure and make tests boring and not innovate
This commit is contained in:
parent
613ac145c6
commit
c42d172f67
1 changed files with 15 additions and 28 deletions
|
|
@ -2,34 +2,21 @@ import { assertEquals } from '@std/assert';
|
||||||
|
|
||||||
import { sanitizeWebsite } from '@/utils/accounts.ts';
|
import { sanitizeWebsite } from '@/utils/accounts.ts';
|
||||||
|
|
||||||
type testSanatizeWbsite = {
|
|
||||||
url: string | undefined;
|
|
||||||
expectedOutput: string | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
Deno.test('Sanitizes a URL to include an https prefix', () => {
|
Deno.test('Sanitizes a URL to include an https prefix', () => {
|
||||||
const testCases: testSanatizeWbsite[] = [
|
assertEquals(sanitizeWebsite('https://alexgleason.me/'), 'https://alexgleason.me/');
|
||||||
{ url: 'https://alexgleason.me/', expectedOutput: 'https://alexgleason.me/' },
|
assertEquals(sanitizeWebsite('http://alexgleason.me/'), 'http://alexgleason.me/');
|
||||||
{ url: 'http://alexgleason.me/', expectedOutput: 'http://alexgleason.me/' },
|
assertEquals(sanitizeWebsite('patrickdosreis.com'), 'https://patrickdosreis.com');
|
||||||
{ url: 'patrickdosreis.com', expectedOutput: 'https://patrickdosreis.com' },
|
// This is not a valid URL,
|
||||||
|
// however, the URL() constructor does not check for top level domain
|
||||||
|
// to prevent compatibility issues we'll allow this to pass as a URL
|
||||||
|
assertEquals(sanitizeWebsite('açsldkjfasd'), 'https://açsldkjfasd');
|
||||||
|
assertEquals(sanitizeWebsite('https/'), 'https://https/');
|
||||||
|
assertEquals(sanitizeWebsite('----------'), 'https://----------');
|
||||||
|
|
||||||
// This is not a valid URL,
|
assertEquals(sanitizeWebsite('https'), 'https://https');
|
||||||
// however, the URL() constructor does not check for top level domain
|
assertEquals(sanitizeWebsite('https:/'), 'https://https:/');
|
||||||
// to prevent compatibility issues we'll allow this to pass as a URL
|
assertEquals(sanitizeWebsite('http://'), 'https://http://');
|
||||||
{ url: 'açsldkjfasd', expectedOutput: 'https://açsldkjfasd' },
|
assertEquals(sanitizeWebsite('http:/'), 'https://http:/');
|
||||||
{ url: 'https/', expectedOutput: 'https://https/' },
|
assertEquals(sanitizeWebsite(' '), undefined);
|
||||||
{ url: '----------', expectedOutput: 'https://----------' },
|
assertEquals(sanitizeWebsite(undefined), undefined);
|
||||||
|
|
||||||
{ url: 'https', expectedOutput: undefined },
|
|
||||||
{ url: 'https://', expectedOutput: undefined },
|
|
||||||
{ url: 'https:/', expectedOutput: undefined },
|
|
||||||
{ url: 'http://', expectedOutput: undefined },
|
|
||||||
{ url: 'http:/', expectedOutput: undefined },
|
|
||||||
{ url: ' ', expectedOutput: undefined },
|
|
||||||
{ url: undefined, expectedOutput: undefined },
|
|
||||||
];
|
|
||||||
|
|
||||||
for (const testCase of testCases) {
|
|
||||||
assertEquals(sanitizeWebsite(testCase.url), testCase.expectedOutput);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue