1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
| import { isUrl, getRouteAuthority } from './utils';
|
| describe('isUrl tests', () => {
| it('should return false for invalid and corner case inputs', () => {
| expect(isUrl([])).toBeFalsy();
| expect(isUrl({})).toBeFalsy();
| expect(isUrl(false)).toBeFalsy();
| expect(isUrl(true)).toBeFalsy();
| expect(isUrl(NaN)).toBeFalsy();
| expect(isUrl(null)).toBeFalsy();
| expect(isUrl(undefined)).toBeFalsy();
| expect(isUrl('')).toBeFalsy();
| });
| it('should return false for invalid URLs', () => {
| expect(isUrl('foo')).toBeFalsy();
| expect(isUrl('bar')).toBeFalsy();
| expect(isUrl('bar/test')).toBeFalsy();
| expect(isUrl('http:/example.com/')).toBeFalsy();
| expect(isUrl('ttp://example.com/')).toBeFalsy();
| });
| it('should return true for valid URLs', () => {
| expect(isUrl('http://example.com/')).toBeTruthy();
| expect(isUrl('https://example.com/')).toBeTruthy();
| expect(isUrl('http://example.com/test/123')).toBeTruthy();
| expect(isUrl('https://example.com/test/123')).toBeTruthy();
| expect(isUrl('http://example.com/test/123?foo=bar')).toBeTruthy();
| expect(isUrl('https://example.com/test/123?foo=bar')).toBeTruthy();
| expect(isUrl('http://www.example.com/')).toBeTruthy();
| expect(isUrl('https://www.example.com/')).toBeTruthy();
| expect(isUrl('http://www.example.com/test/123')).toBeTruthy();
| expect(isUrl('https://www.example.com/test/123')).toBeTruthy();
| expect(isUrl('http://www.example.com/test/123?foo=bar')).toBeTruthy();
| expect(isUrl('https://www.example.com/test/123?foo=bar')).toBeTruthy();
| });
| });
| describe('getRouteAuthority tests', () => {
| it('should return authority for each route', () => {
| const routes = [
| {
| path: '/user',
| name: 'user',
| authority: ['user'],
| exact: true,
| },
| {
| path: '/admin',
| name: 'admin',
| authority: ['admin'],
| exact: true,
| },
| ];
| expect(getRouteAuthority('/user', routes)).toEqual(['user']);
| expect(getRouteAuthority('/admin', routes)).toEqual(['admin']);
| });
| it('should return inherited authority for unconfigured route', () => {
| const routes = [
| {
| path: '/nested',
| authority: ['admin', 'user'],
| exact: true,
| },
| {
| path: '/nested/user',
| name: 'user',
| exact: true,
| },
| ];
| expect(getRouteAuthority('/nested/user', routes)).toEqual(['admin', 'user']);
| });
| it('should return authority for configured route', () => {
| const routes = [
| {
| path: '/nested',
| authority: ['admin', 'user'],
| exact: true,
| },
| {
| path: '/nested/user',
| name: 'user',
| authority: ['user'],
| exact: true,
| },
| {
| path: '/nested/admin',
| name: 'admin',
| authority: ['admin'],
| exact: true,
| },
| ];
| expect(getRouteAuthority('/nested/user', routes)).toEqual(['user']);
| expect(getRouteAuthority('/nested/admin', routes)).toEqual(['admin']);
| });
| it('should return authority for substring route', () => {
| const routes = [
| {
| path: '/nested',
| authority: ['user', 'users'],
| exact: true,
| },
| {
| path: '/nested/users',
| name: 'users',
| authority: ['users'],
| exact: true,
| },
| {
| path: '/nested/user',
| name: 'user',
| authority: ['user'],
| exact: true,
| },
| ];
| expect(getRouteAuthority('/nested/user', routes)).toEqual(['user']);
| expect(getRouteAuthority('/nested/users', routes)).toEqual(['users']);
| });
| });
|
|