-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add handling cases when redirect link is already stripped in nor…
…malizeRedirectUrl
- Loading branch information
MaxGenash
committed
Dec 4, 2020
1 parent
bbda39a
commit 88fee5d
Showing
3 changed files
with
56 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,58 @@ | ||
const utils = require('./utils'); | ||
const { uuid2int, int2uuid, normalizeRedirectUrl } = require('./utils'); | ||
|
||
describe('utils', () => { | ||
describe('uuid2int', () => { | ||
it('should return an int value presentation', () => { | ||
expect(utils.uuid2int('00000000-0000-0000-0000-000000000001')).toEqual(1); | ||
expect(utils.uuid2int('00000000-0000-0000-0000-000000000102')).toEqual(102); | ||
expect(uuid2int('00000000-0000-0000-0000-000000000001')).toEqual(1); | ||
expect(uuid2int('00000000-0000-0000-0000-000000000102')).toEqual(102); | ||
}); | ||
|
||
it('should throw an error if an invalid uuid is used', () => { | ||
expect(() => utils.uuid2int('00002')).toThrow(Error); | ||
expect(() => uuid2int('00002')).toThrow(Error); | ||
}); | ||
}); | ||
|
||
describe('int2uuid', () => { | ||
it('should return an uuid value presentation', () => { | ||
expect(utils.int2uuid(1)).toEqual('00000000-0000-0000-0000-000000000001'); | ||
expect(utils.int2uuid(505)).toEqual('00000000-0000-0000-0000-000000000505'); | ||
expect(int2uuid(1)).toEqual('00000000-0000-0000-0000-000000000001'); | ||
expect(int2uuid(505)).toEqual('00000000-0000-0000-0000-000000000505'); | ||
}); | ||
}); | ||
|
||
describe('normalizeRedirectUrl', () => { | ||
it('should return the original value if the redirectUrl is already striped', () => { | ||
const redirectUrl = '/products?filter=name#3'; | ||
expect(normalizeRedirectUrl(redirectUrl, {})).toEqual(redirectUrl); | ||
}); | ||
|
||
it('should return the original value if the redirectUrl has a host different from hosts in config', () => { | ||
const redirectUrl = 'https://google.com/search?q=this-product'; | ||
const config = { | ||
normalStoreUrl: 'https://store-12345678.mybigcommerce.com', | ||
storeUrl: 'https://my-awesome-store.com', | ||
}; | ||
|
||
expect(normalizeRedirectUrl(redirectUrl, config)).toEqual(redirectUrl); | ||
}); | ||
|
||
it('should return the url without host if the redirectUrl has a host = to normalStoreUrl', () => { | ||
const redirectUrl = 'https://store-12345678.mybigcommerce.com/products?filter=name#3'; | ||
const config = { | ||
normalStoreUrl: 'https://store-12345678.mybigcommerce.com', | ||
storeUrl: 'https://my-awesome-store.com', | ||
}; | ||
|
||
expect(normalizeRedirectUrl(redirectUrl, config)).toEqual('/products?filter=name#3'); | ||
}); | ||
|
||
it('should return the url without host if the redirectUrl has a host = to storeUrl', () => { | ||
const redirectUrl = 'https://my-awesome-store.com/products?filter=name#3'; | ||
const config = { | ||
normalStoreUrl: 'https://store-12345678.mybigcommerce.com', | ||
storeUrl: 'https://my-awesome-store.com', | ||
}; | ||
|
||
expect(normalizeRedirectUrl(redirectUrl, config)).toEqual('/products?filter=name#3'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters