Skip to content

Commit

Permalink
fix tests and missing refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dharmadeveloper108 committed May 28, 2024
1 parent 4c98a87 commit 7b67f84
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/PortingEmbed/PortingFormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ export function PortingFormContainer({
useEffect(() => {
if (!error) return

onError(new Error(error), { code: 'initializationError' })
onError(new Error(error), {
code: 'initializationError',
porting: subscription?.porting || undefined,
})
console.error(error)
}, [error, onError])
}, [error, onError, subscription?.porting])

// TODO: move onLoaded into the initial data fetching instead of an effect, so
// it can't trigger multiple times, and will only be triggered for the initial
Expand Down Expand Up @@ -134,6 +137,7 @@ export function PortingFormContainer({
)
onError(e instanceof ApiError ? e : new Error('Something went wrong.'), {
code: 'unexpectedError',
porting: subscription?.porting || undefined,
})
} finally {
setSubmitting(false)
Expand Down
9 changes: 4 additions & 5 deletions src/PortingEmbed/__tests__/PortingFormContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,14 @@ describe('PortingFormContainer', () => {
)

await waitFor(() => {
expect(onError).toBeCalledWith(
undefined,
{
expect(onError).toBeCalledWith(new Error('Porting is declined'), {
code: 'portingDeclined',
porting: {
...porting,
status: 'declined',
declinedCode: 'portingUserInformationMismatch',
},
'portingDeclined'
)
})
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ export function DonorProviderForm({
const options = useOptionsContext()

if (!serviceProviders || !serviceProviders.items.length || fetchError) {
options?.onError(fetchError || new Error('Service Providers not found.'))
options?.onError(fetchError || new Error('Service Providers not found.'), {
code: 'providersNotFound',
porting,
})
return null
}

Expand Down

0 comments on commit 7b67f84

Please sign in to comment.