-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #820 from commercelayer/token-provider-extras-user
Allow to pass an user from TokenProvider `extras` prop
- Loading branch information
Showing
4 changed files
with
90 additions
and
3 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,3 +1,4 @@ | ||
import { isValidUser } from '#providers/TokenProvider/extras' | ||
import { decodeExtras, encodeExtras, getExtrasFromUrl } from './extras' | ||
import type { TokenProviderExtras } from './types' | ||
|
||
|
@@ -116,3 +117,44 @@ describe('Encode object > Add in URL query string > Decode it from URL', () => { | |
expect(decodeExtras(getExtrasFromUrl())).toEqual(undefined) | ||
}) | ||
}) | ||
|
||
describe('isValidUser', () => { | ||
test('should return true if user is valid', () => { | ||
const user = { | ||
id: '1', | ||
email: '[email protected]', | ||
displayName: 'J.Doe', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
fullName: 'John Doe', | ||
timezone: 'UTC' | ||
} | ||
expect(isValidUser(user)).toBe(true) | ||
}) | ||
|
||
test('should return false if user is null', () => { | ||
expect(isValidUser(null)).toBe(false) | ||
}) | ||
|
||
test('should return false if user is undefined', () => { | ||
expect(isValidUser(undefined)).toBe(false) | ||
}) | ||
|
||
test('should return false if user is empty', () => { | ||
// @ts-expect-error mismatching type for testing invalid user | ||
expect(isValidUser({})).toBe(false) | ||
}) | ||
|
||
test('should return false if user is missing keys', () => { | ||
const user = { | ||
id: '1', | ||
email: '[email protected]', | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
fullName: 'John Doe', | ||
timezone: 'UTC' | ||
} | ||
// @ts-expect-error mismatching type for testing invalid user | ||
expect(isValidUser(user)).toBe(false) | ||
}) | ||
}) |
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