• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ProjectOpenSea / opensea-js / 18541551701

15 Oct 2025 08:19PM UTC coverage: 87.318% (+0.5%) from 86.787%
18541551701

push

github

web-flow
feat: add Fetcher interface, test fixture, and improve API architecture (#1787)

This commit introduces a dependency injection pattern for API classes using the Fetcher interface, making the codebase more maintainable and testable.

## Changes

### Core Architecture
- **Fetcher Interface**: Created `src/api/fetcher.ts` defining a clean abstraction for HTTP operations (get/post methods)
- **API Refactoring**: Updated all API classes (OrdersAPI, OffersAPI, ListingsAPI, CollectionsAPI, NFTsAPI, AccountsAPI, EventsAPI) to accept a Fetcher dependency instead of individual get/post functions
- **OpenSeaAPI Update**: Modified to create and pass a fetcher context to all API clients

### Testing Infrastructure
- **Mock Fetcher Fixture**: Created `test/fixtures/fetcher.ts` providing a reusable `createMockFetcher()` function for consistent test mocking
- **Test Refactoring**: Updated all API test files to use the new fixture, ensuring consistent mocking patterns across the test suite
- **Fetcher Tests**: Added comprehensive test suite in `test/api/fetcher.spec.ts` with 14 test cases covering interface implementation, generic types, error handling, and dependency injection patterns

### Bug Fixes
- Fixed `serializeOrdersQueryOptions` in `src/orders/utils.ts` to handle `next` parameter with fallback: `cursor: options.cursor ?? options.next`

### Documentation
- Added API reference documentation in `developerDocs/api-reference.md`

## Benefits
- **Improved Testability**: Mock fetcher fixture enables consistent and easier test setup across all API tests
- **Better Separation of Concerns**: Fetcher interface decouples HTTP client implementation from API logic
- **Enhanced Maintainability**: Dependency injection pattern makes code more flexible and easier to maintain
- **Type Safety**: Full TypeScript support with generics for type-safe HTTP responses

## Testing
- All 333 existing tests pass
- All linting checks pass (TypeScript, ESLint, Prettier)

🤖 Generated with [... (continued)

432 of 625 branches covered (69.12%)

Branch coverage included in aggregate %.

425 of 451 new or added lines in 17 files covered. (94.24%)

1 existing line in 1 file now uncovered.

3885 of 4319 relevant lines covered (89.95%)

4.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.14
/src/api/api.ts


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc