-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(shared): Improve test coverage
- Loading branch information
Showing
2 changed files
with
115 additions
and
2 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,4 +1,4 @@ | ||
import { addClerkPrefix, parseSearchParams, stripScheme } from '../url'; | ||
import { addClerkPrefix, getClerkJsMajorVersionOrTag, getScriptUrl, parseSearchParams, stripScheme } from '../url'; | ||
|
||
describe('parseSearchParams(queryString)', () => { | ||
it('parses query string and returns a URLSearchParams object', () => { | ||
|
@@ -56,3 +56,59 @@ describe('addClerkPrefix(str)', () => { | |
expect(addClerkPrefix(urlInput)).toBe(urlOutput); | ||
}); | ||
}); | ||
|
||
describe('getClerkJsMajorVersionOrTag', () => { | ||
const stagingFrontendApi = 'foobar.lclstage.dev'; | ||
|
||
it('returns staging if pkgVersion is not provided and frontendApi is staging', () => { | ||
expect(getClerkJsMajorVersionOrTag(stagingFrontendApi)).toBe('staging'); | ||
}); | ||
|
||
it('returns latest if pkgVersion is not provided and frontendApi is not staging', () => { | ||
expect(getClerkJsMajorVersionOrTag('foobar.dev')).toBe('latest'); | ||
}); | ||
|
||
it('returns next if pkgVersion contains next', () => { | ||
expect(getClerkJsMajorVersionOrTag('foobar.dev', '1.2.3-next.4')).toBe('next'); | ||
}); | ||
|
||
it('returns the major version if pkgVersion is provided', () => { | ||
expect(getClerkJsMajorVersionOrTag('foobar.dev', '1.2.3')).toBe('1'); | ||
}); | ||
|
||
it('returns latest if pkgVersion is empty string', () => { | ||
expect(getClerkJsMajorVersionOrTag('foobar.dev', '')).toBe('latest'); | ||
}); | ||
}); | ||
|
||
describe('getScriptUrl', () => { | ||
const frontendApi = 'https://foobar.dev'; | ||
|
||
it('returns URL using the clerkJSVersion if provided', () => { | ||
expect(getScriptUrl(frontendApi, { clerkJSVersion: '1.2.3' })).toBe( | ||
'https://foobar.dev/npm/@clerk/[email protected]/dist/clerk.browser.js', | ||
); | ||
}); | ||
|
||
it('returns URL using the latest version if clerkJSVersion & pkgVersion is not provided + frontendApi is not staging', () => { | ||
expect(getScriptUrl(frontendApi, {})).toBe('https://foobar.dev/npm/@clerk/clerk-js@latest/dist/clerk.browser.js'); | ||
}); | ||
|
||
it('returns URL using the major version if only pkgVersion is provided', () => { | ||
expect(getScriptUrl(frontendApi, { pkgVersion: '1.2.3' })).toBe( | ||
'https://foobar.dev/npm/@clerk/clerk-js@1/dist/clerk.browser.js', | ||
); | ||
}); | ||
|
||
it('returns URL using the major version if only pkgVersion contains next', () => { | ||
expect(getScriptUrl(frontendApi, { pkgVersion: '1.2.3-next.4' })).toBe( | ||
'https://foobar.dev/npm/@clerk/clerk-js@next/dist/clerk.browser.js', | ||
); | ||
}); | ||
|
||
it('returns URL using the staging tag if frontendApi is staging', () => { | ||
expect(getScriptUrl('https://foobar.lclstage.dev', {})).toBe( | ||
'https://foobar.lclstage.dev/npm/@clerk/clerk-js@staging/dist/clerk.browser.js', | ||
); | ||
}); | ||
}); |