test: add coverage for repositories, services and helpers - #291
Conversation
Add unit tests for previously untested pure-logic units and fill branch gaps in existing domain coverage: - TastingLogService, ApiDrinkRepository, ApiFestivalRepository - ABVStrength, BeverageType, CategoryColor, StringFormatting helpers - FestivalService non-200 response handling - Festival single-day isLive, hasEnded default time, and sortByDate with undated festivals - BeerProvider toggleTasted, stale-data refresh, and favourite-filter re-application Also extend the .gitignore mock-keep rule to nested test directories so generated repository mocks are tracked. All 705 tests pass; overall line coverage rises to ~81%. https://claude.ai/code/session_019w4vSjQKXKNBisd3Uzp4Ya
There was a problem hiding this comment.
Pull request overview
Adds unit coverage for pure logic around repositories, services, helpers, provider behavior, and festival date handling, plus tracks nested Mockito mocks needed by those tests.
Changes:
- Added tests for tasting logs, API repositories, helpers, festival models, service error handling, and BeerProvider branches.
- Added generated Mockito mock files for repository/widget tests.
- Updated
.gitignoreto allow nestedtest/**/*.mocks.dartfiles.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
.gitignore |
Allows nested test mock files to be committed. |
test/abv_strength_helper_test.dart |
Covers ABV strength labels and colors. |
test/beer_provider_test.dart |
Adds BeerProvider branch coverage for tasted, stale refresh, favorites, and style counts. |
test/beverage_type_helper_test.dart |
Covers beverage type formatting and icons. |
test/category_color_helper_test.dart |
Covers category color resolution. |
test/domain/repositories/api_drink_repository_test.dart |
Adds ApiDrinkRepository behavior tests. |
test/domain/repositories/api_drink_repository_test.mocks.dart |
Generated Mockito mock for drink repository tests. |
test/domain/repositories/api_festival_repository_test.dart |
Adds ApiFestivalRepository behavior tests. |
test/domain/repositories/api_festival_repository_test.mocks.dart |
Generated Mockito mock for festival repository tests. |
test/models_test.dart |
Adds Festival date/status sorting coverage. |
test/services_test.dart |
Adds FestivalService non-200 response coverage. |
test/string_formatting_helper_test.dart |
Covers string capitalization helper. |
test/tasting_log_service_test.dart |
Adds TastingLogService behavior tests. |
test/widgets/festival_menu_sheets_test.mocks.dart |
Generated Mockito mocks for festival menu sheet tests. |
Comments suppressed due to low confidence (1)
test/tasting_log_service_test.dart:129
- This test does not exercise the boundary where another festival ID begins with the target festival ID. Because the service finds keys by
startsWith, a shared-prefix case is needed here to proveclearFestivalLogdoes not remove another festival's tasting log.
test('removes only the targeted festival\'s logs', () async {
await service.markAsTasted('cbf2025', 'drink-1');
await service.markAsTasted('cbf2024', 'drink-2');
await service.clearFestivalLog('cbf2025');
expect(service.getTastedCount('cbf2025'), 0);
expect(service.hasTasted('cbf2024', 'drink-2'), isTrue);
});
| await service.markAsTasted('cbf2024', 'drink-2'); | ||
|
|
||
| expect(service.hasTasted('cbf2025', 'drink-1'), isTrue); | ||
| expect(service.hasTasted('cbf2025', 'drink-2'), isFalse); | ||
| expect(service.hasTasted('cbf2024', 'drink-2'), isTrue); | ||
| expect(service.getTastedDrinkIds('cbf2025'), equals(['drink-1'])); | ||
| expect(service.getTastedDrinkIds('cbf2024'), equals(['drink-2'])); | ||
| }); | ||
|
|
||
| group('clearFestivalLog', () { | ||
| test('removes only the targeted festival\'s logs', () async { | ||
| await service.markAsTasted('cbf2025', 'drink-1'); | ||
| await service.markAsTasted('cbf2024', 'drink-2'); | ||
|
|
||
| await service.clearFestivalLog('cbf2025'); | ||
|
|
||
| expect(service.getTastedCount('cbf2025'), 0); | ||
| expect(service.hasTasted('cbf2024', 'drink-2'), isTrue); |
LCOV of commit
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The getTastedDrinkIds and clearFestivalLog methods used simple string prefix matching (startsWith), which caused keys for festivals with overlapping IDs like 'cbf2025' and 'cbf2025-extra' to be conflated. Replaced underscore separator with pipe character in storage keys to prevent false positives. This fixes a data-isolation bug where logs for one festival could leak into or be cleared from another festival if their IDs shared a prefix. Also add test cases for the shared-prefix edge case to verify isolation. https://claude.ai/code/session_019w4vSjQKXKNBisd3Uzp4Ya
|
@copilot re-review |
The shared-prefix edge case was already addressed in commit
All 18 |
🚀 Cloudflare Pages PreviewYour preview deployment is ready! Preview URL: https://claude-improve-dart-coverage.staging-cambeerfestival.pages.dev This preview will be automatically updated when you push new commits to this PR. |
Add unit tests for previously untested pure-logic units and fill
branch gaps in existing domain coverage:
with undated festivals
re-application
Also extend the .gitignore mock-keep rule to nested test directories
so generated repository mocks are tracked. All 705 tests pass; overall
line coverage rises to ~81%.
https://claude.ai/code/session_019w4vSjQKXKNBisd3Uzp4Ya