aboutsummaryrefslogtreecommitdiffstats
path: root/src/helpers
diff options
context:
space:
mode:
authorLibravatar Ricardo Cino <ricardo@cino.io>2022-06-26 01:26:19 +0200
committerLibravatar GitHub <noreply@github.com>2022-06-25 23:26:19 +0000
commit465b5772763ccb8d4970d4c55e30a518abb7be3e (patch)
treee929e34910dbf6a3958cdc4de77dc1dcae93e7b0 /src/helpers
parentchore: add more strict types in electron directory (#367) (diff)
downloadferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.tar.gz
ferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.tar.zst
ferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.zip
chore: moved tests to ./test directory (#366)
* chore: allow coverage to be generated from non-tested files
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/array-helpers.ts2
-rw-r--r--src/helpers/password-helpers.ts4
-rw-r--r--src/helpers/url-helpers.test.ts119
3 files changed, 3 insertions, 122 deletions
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 @@
1export const shuffleArray = (arr: any[]) => 1export const shuffleArray = (arr: any[]): any[] =>
2 arr 2 arr
3 .map(a => [Math.random(), a]) 3 .map(a => [Math.random(), a])
4 .sort((a, b) => a[0] - b[0]) 4 .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 @@
1import { createHash, BinaryLike } from 'crypto'; 1import { createHash, BinaryLike } from 'crypto';
2 2
3export function hash(password: BinaryLike) { 3export function hash(password: BinaryLike): string {
4 return createHash('sha256').update(password).digest('base64'); 4 return createHash('sha256').update(password).digest('base64');
5} 5}
6 6
7export function scorePassword(password: string) { 7export function scorePassword(password: string): number {
8 let score = 0; 8 let score = 0;
9 if (!password) { 9 if (!password) {
10 return score; 10 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 @@
1import * as url_helpers from './url-helpers'
2
3describe('url_helpers', () => {
4 describe('isValidExternalURL', () => {
5 describe('with string', () => {
6 it('returns false for empty string', () => {
7 const result = url_helpers.isValidExternalURL('');
8 expect(result).toBe(false);
9 });
10
11 it('returns false for whitespace string', () => {
12 const result = url_helpers.isValidExternalURL(' ');
13 expect(result).toBe(false);
14 });
15
16 it('returns false for random string', () => {
17 const result = url_helpers.isValidExternalURL('some random string');
18 expect(result).toBe(false);
19 });
20
21 it('returns false for invalid url', () => {
22 const result = url_helpers.isValidExternalURL('shttps://google');
23 expect(result).toBe(false);
24 });
25
26 it('returns true for valid http url', () => {
27 const result = url_helpers.isValidExternalURL('http://google');
28 expect(result).toBe(true);
29 });
30
31 it('returns true for valid https url', () => {
32 const result = url_helpers.isValidExternalURL('https://google');
33 expect(result).toBe(true);
34 });
35 });
36
37 describe('with URL', () => {
38 // Note: not testing the invalid string urls - since the URL ctor itself will raise an error
39
40 it('returns false for invalid url', () => {
41 const result = url_helpers.isValidExternalURL(new URL('shttps://google'));
42 expect(result).toBe(false);
43 });
44
45 it('returns true for valid http url', () => {
46 const result = url_helpers.isValidExternalURL(new URL('http://google'));
47 expect(result).toBe(true);
48 });
49
50 it('returns true for valid https url', () => {
51 const result = url_helpers.isValidExternalURL(new URL('https://google'));
52 expect(result).toBe(true);
53 });
54 });
55 });
56
57 describe('fixUrl', () => {
58 it('handles with empty string', () => {
59 const result = url_helpers.fixUrl('');
60 expect(result).toEqual('');
61 });
62
63 it('handles with whitespace string', () => {
64 const result = url_helpers.fixUrl(' ');
65 expect(result).toEqual(' ');
66 });
67
68 it('handles with random string', () => {
69 const result = url_helpers.fixUrl('some random string');
70 expect(result).toEqual('some random string');
71 });
72
73 it('handles string starting with http://', () => {
74 expect(url_helpers.fixUrl('http://some/random/url')).toEqual('http://some/random/url');
75 expect(url_helpers.fixUrl('http://some//random//url')).toEqual('http://some/random/url');
76
77 const gmailEmbeddedUrl = 'https://www.google.com/url?q=https://github.com/ferdium/ferdium-app/issues/87&source=gmail';
78 expect(url_helpers.fixUrl(gmailEmbeddedUrl)).toEqual(gmailEmbeddedUrl); // it should NOT remove the double-slash from the embedded url in the query string
79 });
80
81 it('handles string starting with https://', () => {
82 expect(url_helpers.fixUrl('https://some/random/url')).toEqual('https://some/random/url');
83 expect(url_helpers.fixUrl('https://some//random//url')).toEqual('https://some/random/url');
84 });
85
86 it('handles string starting with file://', () => {
87 expect(url_helpers.fixUrl('file://some/random/url')).toEqual('file://some/random/url');
88 expect(url_helpers.fixUrl('file://some//random//url')).toEqual('file://some/random/url');
89 });
90 });
91
92 describe('isValidFileUrl', () => {
93 it('returns false for empty string', () => {
94 const result = url_helpers.isValidFileUrl('');
95 expect(result).toBe(false);
96 });
97
98 it('returns false for whitespace string', () => {
99 const result = url_helpers.isValidFileUrl(' ');
100 expect(result).toBe(false);
101 });
102
103 it('returns false for random string', () => {
104 const result = url_helpers.isValidFileUrl('some random string');
105 expect(result).toBe(false);
106 });
107
108 it('returns false for invalid url', () => {
109 const result = url_helpers.isValidFileUrl('sfile://google');
110 expect(result).toBe(false);
111 });
112
113 it('returns true for valid file url', () => {
114 const fileName = process.platform === 'win32' ? 'file:///c:\\' : 'file:///';
115 const result = url_helpers.isValidFileUrl(fileName);
116 expect(result).toBe(true);
117 });
118 });
119});