Conversation
- Adjusted the indentation for better readability and consistency in the AddRecipientStep component. This change does not affect functionality but improves code maintainability.
- Enhance the OTP handling logic to display error messages for unhandled response types from the API. This includes showing appropriate toast notifications when the API returns unexpected response_type_ids, improving user feedback during the OTP submission process.
fix: handle unhandled response types in OTP flow
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request introduces error handling for unhandled API responses in the handleFetchBalance function by displaying a toast notification. It also adds a corresponding unit test and fixes indentation in the AddRecipientStep component. Feedback suggests using a more generic error title in the toast notification to accurately reflect different failure scenarios and recommends providing a more comprehensive mock for the useDigiKhataApi hook in tests to prevent potential runtime errors.
| // Handle all other cases (e.g., Send OTP Failed or any unhandled response_type_id) | ||
| else { | ||
| toast({ | ||
| title: res?.data?.message ?? "Send OTP Failed", |
There was a problem hiding this comment.
The fallback title "Send OTP Failed" might be misleading here. The handleFetchBalance function is also responsible for direct balance updates (response type 309) which don't involve sending an OTP. A more generic title like "Request Failed" or "Fetch Balance Failed" would be more accurate.
| title: res?.data?.message ?? "Send OTP Failed", | |
| title: res?.data?.message ?? "Request Failed", |
| jest.mock("features/digikhata/hooks/useDigiKhataApi", () => ({ | ||
| __esModule: true, | ||
| useDigiKhataApi: () => ({ | ||
| generateSenderOtp: mockGenerateSenderOtp, | ||
| isGeneratingSenderOtp: false, | ||
| verifySenderOtp: jest.fn(), | ||
| isVerifyingSenderOtp: false, | ||
| }), | ||
| })); |
There was a problem hiding this comment.
The mock for useDigiKhataApi is incomplete. It only includes 4 of the many properties returned by the hook. Since DigiKhataPage orchestrates multiple steps (e.g., AddRecipientStep, PanVerificationStep) that consume other parts of this hook, this mock will cause runtime errors if those steps are rendered during testing. Consider providing a more complete mock or using a helper to generate a default mock state.
Description
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
🚨 Checklist:
Further comments
🙏 Thank you!
Thank you for contributing to this project. We appreciate your time and effort. 🎉