-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/astro-e2e
- Loading branch information
Showing
14 changed files
with
189 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/shared': minor | ||
--- | ||
|
||
Change `useReverification` to handle error in a callback, but still allow an error to be thrown via options. |
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
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
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
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
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
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
61 changes: 61 additions & 0 deletions
61
packages/shared/src/react/__tests__/useReverification.test.ts
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,61 @@ | ||
import { expectTypeOf } from 'expect-type'; | ||
|
||
import { __experimental_reverificationError } from '../../authorization-errors'; | ||
import type { __experimental_useReverification as useReverification } from '../hooks/useReverification'; | ||
|
||
type ExcludeClerkError<T> = T extends { clerk_error: any } ? never : T; | ||
|
||
const fetcher = async (key: string, options: { id: string }) => { | ||
return { | ||
key, | ||
options, | ||
}; | ||
}; | ||
|
||
const fetcherWithHelper = async (key: string, options: { id: string }) => { | ||
if (key == 'a') { | ||
return __experimental_reverificationError(); | ||
} | ||
|
||
return { | ||
key, | ||
options, | ||
}; | ||
}; | ||
|
||
type Fetcher = typeof fetcherWithHelper; | ||
|
||
describe('useReverification type tests', () => { | ||
it('allow pass through types', () => { | ||
type UseReverificationWithFetcher = typeof useReverification<typeof fetcher, object>; | ||
type VerifiedFetcher = ReturnType<UseReverificationWithFetcher>[0]; | ||
expectTypeOf(fetcher).toEqualTypeOf<VerifiedFetcher>(); | ||
}); | ||
|
||
it('returned callback with clerk error excluded and possible null in case of cancelled flow', () => { | ||
type UseReverificationWithFetcherHelper = typeof useReverification<typeof fetcherWithHelper, object>; | ||
type VerifiedFetcherHelper = ReturnType<UseReverificationWithFetcherHelper>[0]; | ||
|
||
expectTypeOf(fetcherWithHelper).not.toEqualTypeOf<VerifiedFetcherHelper>(); | ||
|
||
expectTypeOf<Parameters<Fetcher>>().toEqualTypeOf<Parameters<VerifiedFetcherHelper>>(); | ||
expectTypeOf<ReturnType<Fetcher>>().not.toEqualTypeOf<ReturnType<VerifiedFetcherHelper>>(); | ||
expectTypeOf<ExcludeClerkError<Awaited<ReturnType<Fetcher>>> | null>().toEqualTypeOf< | ||
Awaited<ReturnType<VerifiedFetcherHelper>> | ||
>(); | ||
}); | ||
|
||
it('returned callback with clerk error excluded but without null since we throw', () => { | ||
type UseReverificationWithFetcherHelperThrow = typeof useReverification< | ||
typeof fetcherWithHelper, | ||
{ | ||
throwOnCancel: true; | ||
} | ||
>; | ||
type VerifiedFetcherHelperThrow = ReturnType<UseReverificationWithFetcherHelperThrow>[0]; | ||
expectTypeOf(fetcherWithHelper).not.toEqualTypeOf<VerifiedFetcherHelperThrow>(); | ||
expectTypeOf<ExcludeClerkError<Awaited<ReturnType<Fetcher>>>>().toEqualTypeOf< | ||
Awaited<ReturnType<VerifiedFetcherHelperThrow>> | ||
>(); | ||
}); | ||
}); |
Oops, something went wrong.