forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #86 from utkarsha-deriv/UPM-938/utkarsha/integrate…
…-API-for-verification-SMS-Whatsapp feat: integrate phone number challenge api
- Loading branch information
Showing
8 changed files
with
165 additions
and
4 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
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
39 changes: 39 additions & 0 deletions
39
packages/hooks/src/__tests__/useGetPhoneNumberOTP.spec.tsx
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,39 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useMutation } from '@deriv/api'; | ||
import useGetPhoneNumberOTP from '../useGetPhoneNumberOTP'; | ||
|
||
jest.mock('@deriv/api', () => ({ | ||
...jest.requireActual('@deriv/api'), | ||
useMutation: jest.fn(), | ||
})); | ||
|
||
const mock_response = { | ||
data: { | ||
phone_number_challenge: 1, | ||
}, | ||
mutate: jest.fn(), | ||
}; | ||
|
||
describe('useGetPhoneNumberOTP', () => { | ||
it('should call mutate with correct payload for SMS request and return correct response', () => { | ||
(useMutation as jest.Mock).mockReturnValueOnce(mock_response); | ||
const { result } = renderHook(() => useGetPhoneNumberOTP()); | ||
|
||
result.current.requestOnSMS(); | ||
|
||
expect(useMutation).toHaveBeenCalledWith('phone_number_challenge'); | ||
expect(result.current.mutate).toHaveBeenCalledWith({ payload: { carrier: 'sms' } }); | ||
expect(result.current.data).toEqual(1); | ||
}); | ||
|
||
it('should call mutate with correct payload for WhatsApp request and return correct response', () => { | ||
(useMutation as jest.Mock).mockReturnValueOnce(mock_response); | ||
const { result } = renderHook(() => useGetPhoneNumberOTP()); | ||
|
||
result.current.requestOnWhatsApp(); | ||
|
||
expect(useMutation).toHaveBeenCalledWith('phone_number_challenge'); | ||
expect(result.current.mutate).toHaveBeenCalledWith({ payload: { carrier: 'whatsapp' } }); | ||
expect(result.current.data).toEqual(1); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { useMutation } from '@deriv/api'; | ||
import { VERIFICATION_SERVICES } from '@deriv/shared'; | ||
|
||
/** A hook for requesting OTP which is sent on whatsapp or sms platforms */ | ||
const useGetPhoneNumberOTP = () => { | ||
const { data, mutate, ...rest } = useMutation('phone_number_challenge'); | ||
|
||
const requestOnSMS = () => { | ||
mutate({ payload: { carrier: VERIFICATION_SERVICES.SMS } }); | ||
}; | ||
const requestOnWhatsApp = () => { | ||
mutate({ payload: { carrier: VERIFICATION_SERVICES.WHATSAPP } }); | ||
}; | ||
|
||
return { | ||
data: data?.phone_number_challenge, | ||
requestOnWhatsApp, | ||
requestOnSMS, | ||
mutate, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default useGetPhoneNumberOTP; |
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
4 changes: 4 additions & 0 deletions
4
packages/shared/src/utils/constants/phone-number-verification.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,4 @@ | ||
export const VERIFICATION_SERVICES = { | ||
SMS: 'sms', | ||
WHATSAPP: 'whatsapp', | ||
} as const; |