Today’s Code Developments: Testing, Refactoring & New API
What developments have taken place today?
Today’s commits focused on enhancing testing, improving data handling, and refining API endpoints. Here’s a summary of the changes:
- Comprehensive Unit Tests for Logger: New unit tests were added to thoroughly validate the
InMemoryLogger
component. These tests cover logging methods (levels, filenames, timing), buffer management (empty flush prevention), synchronous stop behavior, and error handling during writer operations. This improves code reliability and reduces potential bugs related to logger functionality. - Pagination Refactor: The pagination logic in
UserController
andWebsiteController
was refactored by replacing a customNewPagination
helper function with a newNewPagination
function that takes input parameters for page number, items per page, total item count, and existing query parameters. This promotes better organization, clarity, and maintainability of the pagination logic. Unit tests were added to verify the correctness of this new function in various scenarios, including edge cases. - Random String & Interface Refactoring: Tests for randomly generated strings (length and uniqueness) were introduced. Simultaneously, several types and structs were refactored to use interfaces instead of concrete implementations. This enhances testability, reduces coupling between components (e.g.,
RabbitEnqueuer
,PingChecker
), and promotes a more flexible design. - New Domain Lighthouse API Endpoint: A new API endpoint
/api/v1/domain/{id}/lighthouse
was added to retrieve website URL lighthouse scores for specified domains. This expands the API’s functionality and provides valuable performance data. The implementation includes fetching URLs, querying lighthouse metrics, and returning a JSON response. - Dependency Updates: Several npm dependencies were upgraded, including Babel compiler components (
@babel/compat-data
,@babel/helper-compilation-targets
, etc.). These updates likely address bug fixes, performance improvements, or new features in the Babel ecosystem. - Website URL Metadata Refactor: The process for handling website URLs was updated to directly incorporate the
URL
itself into the object’s structure rather than relying on an ID as a unique identifier. This change ensures consistent and correct representation of URLs within data structures. - Website Metrics Error Handling: Methods were added to the
MockWebsiteRepository
class (UpdateDomainError
,UpdateCertificateError
) for updating error information associated with websites. A newDomainMetadataRepositoryInterface
was also introduced, along with a corresponding implementation class and updates to other repositories. This improves error tracking and management related to website processing. - Lighthouse Rating Refactor: The lighthouse rating calculation logic has been centralized into the
helper_lighthouse_rating
package. This promotes code reusability and simplifies future maintenance. The changes include updating API handlers, adding aRating
field to theUrlLightHouseData
struct, and introducing new unit tests. - Dependency Update for
remote-daemon-client-typescript
: The version of theremote-daemon-client-typescript
library was updated to the latest commit identifier (04930c10266d12d3a404daa22ef0d4b61f9cd1f2).
These changes collectively contribute to a more robust, maintainable, and feature-rich codebase. The increased test coverage improves reliability, the refactoring enhances code organization, and the new API endpoint expands application capabilities. The improvements in error handling and data management ensure data integrity and facilitate efficient monitoring and analysis.
testing api development refactoring data handling lighthouse scores