From 465b5772763ccb8d4970d4c55e30a518abb7be3e Mon Sep 17 00:00:00 2001 From: Ricardo Cino Date: Sun, 26 Jun 2022 01:26:19 +0200 Subject: chore: moved tests to ./test directory (#366) * chore: allow coverage to be generated from non-tested files --- src/helpers/array-helpers.ts | 2 +- src/helpers/password-helpers.ts | 4 +- src/helpers/url-helpers.test.ts | 119 ---------------------------------------- 3 files changed, 3 insertions(+), 122 deletions(-) delete mode 100644 src/helpers/url-helpers.test.ts (limited to 'src/helpers') diff --git a/src/helpers/array-helpers.ts b/src/helpers/array-helpers.ts index 3f8806176..45ff932ba 100644 --- a/src/helpers/array-helpers.ts +++ b/src/helpers/array-helpers.ts @@ -1,4 +1,4 @@ -export const shuffleArray = (arr: any[]) => +export const shuffleArray = (arr: any[]): any[] => arr .map(a => [Math.random(), a]) .sort((a, b) => a[0] - b[0]) diff --git a/src/helpers/password-helpers.ts b/src/helpers/password-helpers.ts index 053321bbf..d5f2d0c49 100644 --- a/src/helpers/password-helpers.ts +++ b/src/helpers/password-helpers.ts @@ -1,10 +1,10 @@ import { createHash, BinaryLike } from 'crypto'; -export function hash(password: BinaryLike) { +export function hash(password: BinaryLike): string { return createHash('sha256').update(password).digest('base64'); } -export function scorePassword(password: string) { +export function scorePassword(password: string): number { let score = 0; if (!password) { return score; diff --git a/src/helpers/url-helpers.test.ts b/src/helpers/url-helpers.test.ts deleted file mode 100644 index 5af3025e9..000000000 --- a/src/helpers/url-helpers.test.ts +++ /dev/null @@ -1,119 +0,0 @@ -import * as url_helpers from './url-helpers' - -describe('url_helpers', () => { - describe('isValidExternalURL', () => { - describe('with string', () => { - it('returns false for empty string', () => { - const result = url_helpers.isValidExternalURL(''); - expect(result).toBe(false); - }); - - it('returns false for whitespace string', () => { - const result = url_helpers.isValidExternalURL(' '); - expect(result).toBe(false); - }); - - it('returns false for random string', () => { - const result = url_helpers.isValidExternalURL('some random string'); - expect(result).toBe(false); - }); - - it('returns false for invalid url', () => { - const result = url_helpers.isValidExternalURL('shttps://google'); - expect(result).toBe(false); - }); - - it('returns true for valid http url', () => { - const result = url_helpers.isValidExternalURL('http://google'); - expect(result).toBe(true); - }); - - it('returns true for valid https url', () => { - const result = url_helpers.isValidExternalURL('https://google'); - expect(result).toBe(true); - }); - }); - - describe('with URL', () => { - // Note: not testing the invalid string urls - since the URL ctor itself will raise an error - - it('returns false for invalid url', () => { - const result = url_helpers.isValidExternalURL(new URL('shttps://google')); - expect(result).toBe(false); - }); - - it('returns true for valid http url', () => { - const result = url_helpers.isValidExternalURL(new URL('http://google')); - expect(result).toBe(true); - }); - - it('returns true for valid https url', () => { - const result = url_helpers.isValidExternalURL(new URL('https://google')); - expect(result).toBe(true); - }); - }); - }); - - describe('fixUrl', () => { - it('handles with empty string', () => { - const result = url_helpers.fixUrl(''); - expect(result).toEqual(''); - }); - - it('handles with whitespace string', () => { - const result = url_helpers.fixUrl(' '); - expect(result).toEqual(' '); - }); - - it('handles with random string', () => { - const result = url_helpers.fixUrl('some random string'); - expect(result).toEqual('some random string'); - }); - - it('handles string starting with http://', () => { - expect(url_helpers.fixUrl('http://some/random/url')).toEqual('http://some/random/url'); - expect(url_helpers.fixUrl('http://some//random//url')).toEqual('http://some/random/url'); - - const gmailEmbeddedUrl = 'https://www.google.com/url?q=https://github.com/ferdium/ferdium-app/issues/87&source=gmail'; - expect(url_helpers.fixUrl(gmailEmbeddedUrl)).toEqual(gmailEmbeddedUrl); // it should NOT remove the double-slash from the embedded url in the query string - }); - - it('handles string starting with https://', () => { - expect(url_helpers.fixUrl('https://some/random/url')).toEqual('https://some/random/url'); - expect(url_helpers.fixUrl('https://some//random//url')).toEqual('https://some/random/url'); - }); - - it('handles string starting with file://', () => { - expect(url_helpers.fixUrl('file://some/random/url')).toEqual('file://some/random/url'); - expect(url_helpers.fixUrl('file://some//random//url')).toEqual('file://some/random/url'); - }); - }); - - describe('isValidFileUrl', () => { - it('returns false for empty string', () => { - const result = url_helpers.isValidFileUrl(''); - expect(result).toBe(false); - }); - - it('returns false for whitespace string', () => { - const result = url_helpers.isValidFileUrl(' '); - expect(result).toBe(false); - }); - - it('returns false for random string', () => { - const result = url_helpers.isValidFileUrl('some random string'); - expect(result).toBe(false); - }); - - it('returns false for invalid url', () => { - const result = url_helpers.isValidFileUrl('sfile://google'); - expect(result).toBe(false); - }); - - it('returns true for valid file url', () => { - const fileName = process.platform === 'win32' ? 'file:///c:\\' : 'file:///'; - const result = url_helpers.isValidFileUrl(fileName); - expect(result).toBe(true); - }); - }); -}); -- cgit v1.2.3-54-g00ecf