-
Notifications
You must be signed in to change notification settings - Fork 1
Add QBO service implementation and tests #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Introduced `OAuth2TokenManager` for managing access and refresh tokens, including validation and automatic refreshing. - Added `FileTokenStorage` for persistent token storage, allowing tokens to be saved and loaded from a file. - Created `IOAuth2TokenManager` and `TokenRefreshProvider` interfaces to define the structure for token management and refreshing. - Implemented `OAuth2TokenRefreshProvider` to handle token refresh logic using QuickBooks Online API. - Added constants for token configuration and error messages to improve maintainability and clarity. These changes enhance the application's OAuth2 integration, ensuring robust token management and storage capabilities.
- Removed console logging and the `logRefreshTokenChange` method from `OAuth2TokenManager` to streamline the token management process. - Deleted unused interfaces `TokenManagementResult` and `TokenInfo` from `types.ts`, simplifying the codebase and improving maintainability. These changes enhance the clarity and efficiency of the OAuth2 token management implementation.
- Introduced the QBORepository class for handling QuickBooks Online interactions, including methods for retrieving paid invoices and calculating effective revenue. - Added types for CustomerRevenueByRef and Invoice to define the data structure. - Created comprehensive unit tests for QBORepository and related types to ensure functionality and error handling. - Implemented tests for the QBO service exports to validate the structure and instantiation of key classes. These changes enhance the integration with QuickBooks Online, providing a robust foundation for financial data management and reporting.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
🔍 Vulnerabilities of
|
| digest | sha256:e952149b2246785b2b956cda2bc4e02bbfa30db0b008eeb9820d271552a4f9c6 |
| vulnerabilities | |
| platform | linux/amd64 |
| size | 243 MB |
| packages | 1628 |
📦 Base Image node:20-alpine
Description
Description
| ||||||||||||||||
Description
| ||||||||||||||||
Description
| ||||||||||||||||
Description
| ||||||||||||||||
Description
| ||||||||||||||||
Description
| ||||||||||||||||
Description
| ||||||||||||||||
Description
| ||||||||||||||||
Description
| ||||||||||||||||
Description
|
- Removed unnecessary validation for `refreshToken`, `companyId`, and `apiUrl` in the QBORepository constructor, simplifying the initialization process. - Cleaned up comments related to axios instance creation and retry configuration for better clarity. These changes streamline the QBORepository class, enhancing maintainability and readability.
- Introduced `OAuth2Error` class for better error handling in OAuth2 processes. - Updated `FileTokenStorage` and `OAuth2TokenManager` to throw `OAuth2Error` instead of generic errors, improving error specificity. - Added unit tests for `OAuth2Error` to ensure correct functionality. These changes enhance the robustness of the OAuth2 token management implementation by providing clearer error messages and improving maintainability.
- Added tests to verify the behavior of `getAccessToken` and `getCurrentRefreshToken` methods in various scenarios, including valid, expired, and malformed tokens. - Implemented checks for concurrent access to ensure that multiple calls to `getAccessToken` handle token refresh correctly without causing multiple refresh requests. - Improved error handling tests for token refresh failures, ensuring that appropriate errors are thrown and tokens are cleared when necessary. These changes strengthen the test coverage of the OAuth2 token management implementation, ensuring robustness and reliability in token handling.
- Added a `setTokenDataForTesting` method to `OAuth2TokenManager` for improved testing capabilities. - Removed unnecessary comments and streamlined the `TokenData` interface in `types.ts`. - Introduced unit tests for `OAuth2TokenManager` focusing on storage and error handling scenarios, ensuring robustness in token management. These changes improve the maintainability and testability of the OAuth2 token management implementation, enhancing overall code quality.
- Added new error messages for loading and clearing OAuth2 tokens in `constants.ts`. - Updated `OAuth2TokenManager` to throw specific errors when loading and clearing tokens fails. - Refactored tests to ensure comprehensive coverage of token validation scenarios, including handling of empty, null, and expired tokens. These changes improve the robustness and clarity of the OAuth2 token management implementation, enhancing error handling and overall code quality.
…mprovements - Added a new method `isValidTokenData` in `OAuth2TokenManager` to validate token data before processing. - Updated the token loading logic to ensure only valid token data is set. - Introduced a new test case to verify the handling of malformed token data, ensuring the manager gracefully manages invalid tokens. These changes improve the robustness of the OAuth2 token management implementation by ensuring only valid tokens are processed and enhancing error handling capabilities.
- Updated the `isTokenValid` method to include checks for the presence of the refresh token. - Improved the `isValidTokenData` method to validate token data structure and values more thoroughly, ensuring that access and refresh tokens are non-empty strings and that the expiry date is a valid finite number. - Modified the `setTokenData` method to throw an error if invalid token data is provided. - Enhanced the `setTokenDataForTesting` method to handle null token data appropriately. These changes further strengthen the OAuth2 token management implementation by ensuring comprehensive validation of token data, improving error handling, and enhancing overall code reliability.
- Removed the `IOAuth2TokenManager` interface and integrated its functionality into the new `OAuth2TokenManagerInterface` in `types.ts`. - Updated imports in `FileTokenStorage`, `OAuth2TokenManager`, and `OAuth2TokenRefreshProvider` to reference the consolidated types. - This refactor improves code organization and maintainability by centralizing type definitions related to OAuth2 token management.
- Updated the `load` method in `FileTokenStorage` to be asynchronous, utilizing `fs.promises.readFile` for improved performance and non-blocking behavior. - Modified the `loadTokens` method in `OAuth2TokenManager` to handle the asynchronous loading of token data. - Adjusted unit tests for `OAuth2TokenManager` to accommodate the asynchronous nature of the `load` method, ensuring proper initialization and handling of token data. These changes enhance the efficiency and responsiveness of the OAuth2 token management implementation by allowing for non-blocking token loading operations.
- Updated the `OAuth2Error` class to include a `code` property, allowing for custom error codes alongside the message and name. - Modified unit tests for `OAuth2Error` to verify the correct setting of default and custom error codes. - Introduced new error codes in `constants.ts` for better error handling across the OAuth2 service. These changes improve the error handling capabilities of the OAuth2 implementation by providing more granular error information, enhancing debugging and user feedback.
- Updated the `setTokenDataForTesting` method to throw an error if called outside of the test environment, ensuring it is only used in appropriate contexts. - This change improves the safety and reliability of the testing process by preventing misuse of the method in production environments.
- Introduced comprehensive unit tests for the `FileTokenStorage` class, covering methods for saving, loading, and clearing token data, including error handling scenarios. - Added tests for the `OAuth2TokenRefreshProvider` to ensure proper instantiation and method availability. - These tests enhance the reliability and maintainability of the OAuth2 token management implementation by ensuring critical functionalities are thoroughly validated.
- Introduced new test cases in `OAuth2TokenManager` to handle scenarios for empty access and refresh tokens, as well as invalid expiry dates, ensuring robust validation of token data. - Added a test in `OAuth2TokenRefreshProvider` to verify that the `refreshToken` method returns a promise, enhancing the reliability of the token refresh functionality. - These tests improve the overall coverage and reliability of the OAuth2 token management implementation by validating critical edge cases and ensuring proper asynchronous behavior.
- Introduced new test cases in `OAuth2TokenManager` to handle edge cases for negative, zero, and very small expiry dates, ensuring the `isTokenValid` method correctly identifies invalid token data. - These tests enhance the robustness of the token validation logic by covering additional scenarios that could lead to incorrect token handling. This update improves the overall reliability of the OAuth2 token management implementation by validating critical edge cases in token expiry handling.
- Introduced new test cases in `OAuth2TokenManager` to verify the handling of token refresh when the token is within the buffer time, ensuring that valid tokens are correctly returned. - Added tests for concurrent token refresh requests to ensure that multiple simultaneous requests are handled properly, returning the expected new access token. - Included tests for handling null and undefined token data in `setTokenDataForTesting`, ensuring that the token manager correctly identifies invalid token states. These updates enhance the reliability and robustness of the OAuth2 token management implementation by validating critical scenarios related to token refresh behavior and data integrity.
These changes enhance the integration with QuickBooks Online, providing a robust foundation for financial data management and reporting.