-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix, test: [M3-8830] - Use unit tested function for Pendo url transfo…
…rmation (#11211) * Use transform function and unit test it * Use singular function name * Added changeset: Use unit tested function for Pendo url transformation * Address feedback @coliu-akamai: add missing test case * Address feedback @hkhalil-akamai: remove unnecessary conditionals
- Loading branch information
Showing
3 changed files
with
138 additions
and
19 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-11211-tech-stories-1730836470267.md
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Tech Stories | ||
--- | ||
|
||
Use unit tested function for Pendo url transformation ([#11211](https://github.com/linode/manager/pull/11211)) |
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { transformUrl } from './usePendo'; | ||
|
||
const ID_URLS = [ | ||
{ | ||
expectedTransform: 'https://cloud.linode.com/nodebalancers/XXXX', | ||
position: 'end', | ||
url: 'https://cloud.linode.com/nodebalancers/123', | ||
}, | ||
{ | ||
expectedTransform: | ||
'https://cloud.linode.com/nodebalancers/XXXX/configurations', | ||
position: 'middle', | ||
url: 'https://cloud.linode.com/nodebalancers/123/configurations', | ||
}, | ||
{ | ||
expectedTransform: | ||
'https://cloud.linode.com/nodebalancers/XXXX/configurations/XXXX', | ||
position: 'multiple', | ||
url: 'https://cloud.linode.com/nodebalancers/123/configurations/456', | ||
}, | ||
]; | ||
|
||
const USERNAME_URLS = [ | ||
{ | ||
path: 'my-username', | ||
}, | ||
{ | ||
path: 'my-username/profile', | ||
}, | ||
{ | ||
path: 'my-username/permissions', | ||
}, | ||
{ | ||
path: '123-my-username/profile', | ||
}, | ||
]; | ||
|
||
const OBJ_URLS = [ | ||
{ | ||
expectedTransform: | ||
'http://cloud.linode.com/object-storage/buckets/XXXX/XXXX', | ||
path: 'us-west/abc123', | ||
}, | ||
{ | ||
expectedTransform: | ||
'http://cloud.linode.com/object-storage/buckets/XXXX/XXXX/ssl', | ||
path: 'us-west/abc123/ssl', | ||
}, | ||
{ | ||
expectedTransform: | ||
'http://cloud.linode.com/object-storage/buckets/XXXX/XXXX', | ||
path: 'us-west/123abc', | ||
}, | ||
{ | ||
expectedTransform: | ||
'http://cloud.linode.com/object-storage/buckets/XXXX/XXXX/access', | ||
path: 'us-west/123abc/access', | ||
}, | ||
]; | ||
|
||
describe('transformUrl', () => { | ||
it.each(ID_URLS)( | ||
'replaces id(s) in $position positions in the url path', | ||
({ expectedTransform, url }) => { | ||
const actualTransform = transformUrl(url); | ||
expect(actualTransform).toEqual(expectedTransform); | ||
} | ||
); | ||
|
||
it.each(USERNAME_URLS)( | ||
'truncates $path from the /users url path', | ||
({ path }) => { | ||
const baseUrl = 'https://cloud.linode.com/account/users/'; | ||
const actualTransform = transformUrl(`${baseUrl}${path}`); | ||
expect(actualTransform).toEqual(baseUrl); | ||
} | ||
); | ||
|
||
it.each(OBJ_URLS)( | ||
'replaces the OBJ region and bucket name in the url path ($path)', | ||
({ expectedTransform, path }) => { | ||
const baseUrl = 'http://cloud.linode.com/object-storage/buckets/'; | ||
const actualTransform = transformUrl(`${baseUrl}${path}`); | ||
expect(actualTransform).toEqual(expectedTransform); | ||
} | ||
); | ||
|
||
it('truncates the url after "access_token" in the url path', () => { | ||
const url = | ||
'https://cloud.linode.com/oauth/callback#access_token=12345&token_type=bearer&expires_in=5678'; | ||
const actualTransform = transformUrl(url); | ||
const expectedTransform = | ||
'https://cloud.linode.com/oauth/callback#access_token'; | ||
expect(actualTransform).toEqual(expectedTransform); | ||
}); | ||
|
||
it('returns the original url if no transformation is needed', () => { | ||
const url = 'https://cloud.linode.com/linodes/create'; | ||
const actualTransform = transformUrl(url); | ||
expect(actualTransform).toEqual(url); | ||
}); | ||
}); |
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