From bf461041e79da7c9dac066bd9f522b9f89bbb1e0 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Fri, 24 May 2024 10:43:18 -0300 Subject: [PATCH] test: absolute url sanitizer --- src/utils/accounts.test.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/utils/accounts.test.ts diff --git a/src/utils/accounts.test.ts b/src/utils/accounts.test.ts new file mode 100644 index 00000000..2d81e2b0 --- /dev/null +++ b/src/utils/accounts.test.ts @@ -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); + } +});