forked from clerk/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.test.ts
More file actions
70 lines (59 loc) · 2.1 KB
/
Copy pathproxy.test.ts
File metadata and controls
70 lines (59 loc) · 2.1 KB
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
import { isHttpOrHttps, isProxyUrlRelative, isValidProxyUrl, proxyUrlToAbsoluteURL } from './proxy';
describe('isValidProxyUrl(key)', () => {
it('returns true if the proxyUrl is valid', () => {
expect(isValidProxyUrl('https://proxy-app.dev/api/__clerk')).toBe(true);
});
it('returns true if the proxyUrl is valid', () => {
expect(isValidProxyUrl('/api/__clerk')).toBe(true);
});
it('returns false if the proxyUrl is invalid', () => {
expect(isValidProxyUrl('proxy-app.dev/api/__clerk')).toBe(false);
});
});
describe('isProxyUrlRelative(key)', () => {
it('returns true if the proxyUrl starts with `/`', () => {
expect(isProxyUrlRelative('/api/__clerk')).toBe(true);
});
it('returns false if the proxyUrl does not starts with `/`', () => {
expect(isProxyUrlRelative('proxy-app.dev/api/__clerk==')).toBe(false);
});
});
describe('isHttpOrHttps(key)', () => {
it.each([
['http://clerk.com/api/__clerk', true],
['http://clerk.com/api/__clerk', true],
[undefined, false],
['/api/__clerk', false],
['', false],
])('.isHttpOrHttps(%s)', (key, expected) => {
expect(isHttpOrHttps(key)).toBe(expected);
});
});
describe('proxyUrlToAbsoluteURL(url)', () => {
const currentLocation = global.window.location;
beforeEach(() => {
Object.defineProperty(global.window, 'location', {
get() {
return {
origin: 'https://clerk.com',
};
},
configurable: true,
});
});
afterEach(() => {
Object.defineProperty(global.window, 'location', {
value: currentLocation,
writable: true,
});
});
it('returns an absolute URL made from window.location.origin and the partial a path', () => {
expect(proxyUrlToAbsoluteURL('/api/__clerk')).toBe('https://clerk.com/api/__clerk');
});
it('returns the same value as the parameter given as it already an absolute URL', () => {
expect(proxyUrlToAbsoluteURL('https://clerk.com/api/__clerk')).toBe('https://clerk.com/api/__clerk');
});
it('returns empty string if parameter is undefined', () => {
expect(proxyUrlToAbsoluteURL(undefined)).toBe('');
});
});