mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
test: absolute url sanitizer
This commit is contained in:
parent
9df50a167a
commit
bf461041e7
1 changed files with 35 additions and 0 deletions
35
src/utils/accounts.test.ts
Normal file
35
src/utils/accounts.test.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
import { assertEquals } from '@std/assert';
|
||||||
|
|
||||||
|
import { sanitizeWebsite } from '@/utils/accounts.ts';
|
||||||
|
|
||||||
|
type testSanatizeWbsite = {
|
||||||
|
url: string | undefined;
|
||||||
|
expectedOutput: string | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
Deno.test('throws a RelayError when inserting an event deleted by a user', () => {
|
||||||
|
const testCases: testSanatizeWbsite[] = [
|
||||||
|
{ url: 'https://alexgleason.me/', expectedOutput: 'https://alexgleason.me/' },
|
||||||
|
{ url: 'http://alexgleason.me/', expectedOutput: 'http://alexgleason.me/' },
|
||||||
|
{ 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
|
||||||
|
{ url: 'açsldkjfasd', expectedOutput: 'https://açsldkjfasd' },
|
||||||
|
{ url: 'https/', expectedOutput: 'https://https/' },
|
||||||
|
{ url: '----------', expectedOutput: 'https://----------' },
|
||||||
|
|
||||||
|
{ 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