Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize user data fetching and api logic (#11)
* Install vitest and test date utilities and validation functions - Installed **Vitest** for `unit testing` framework. - Created test cases for the `formatDate` utility function to ensure correct formatting of valid date strings. - Added validation tests for `username`, `email`, `password`, and `confirm password` fields to verify proper validation logic. - Updated the testing configuration to support the new tests and ensure they run successfully. * Add unit test for hooks - Implemented tests for the `useResize` hook to verify behavior across different screen sizes. - Added tests for the `useTheme` hook to check the default theme and verify that it updates to light or dark when changed. * Add unit test for providers - Added a test to ensure the `ThemeProvider` correctly applies the selected `theme` to the document's `root` element. - Mocked `localStorage` to return a predefined `theme` value for testing. - Verified that the appropriate `class` is applied to `document.documentElement` based on the `theme`. * Add unit test for zustand stores - Implemented tests for `userStore` to verify user state and persistence in session storage. - Created tests for `authStore` to ensure authentication logic and state management function correctly. * Add tests for authService methods Implemented tests for the following **AuthService** methods: - `signIn`: Verified successful sign-in and error handling. - `signUp`: Tested user registration process and error responses. - `signOut`: Checked the sign-out functionality. - `verifyEmail`: Confirmed email verification process. - `resendVerify`: Ensured resend verification logic works as expected. - `verifyToken`: Tested token verification and error handling. - `forgotPassword`: Validated forgot password request handling. - `resetPassword`: Checked password reset process. - `changePassword`: Tested password change functionality. * Add tests for guard components - Created unit tests for `AuthGuard` and `PrivateGuard` components to ensure proper functionality. - Verified that guards correctly redirect unauthorized users and allow access for authorized users. * Optimize user data fetching and api logic - Added `Select` to the user retrieval query to minimize the data fetched from the database, improving performance and reducing memory usage. - Updated the user object with the latest information fetched from the verifyToken function, ensuring that only the necessary fields are loaded and modified. - This change enhances the efficiency of user operations by focusing on relevant fields during database interactions.
- Loading branch information