-
Notifications
You must be signed in to change notification settings - Fork 5
test: Add test for services #1320
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
base: development
Are you sure you want to change the base?
Conversation
…bsolete SyncProjectAuthorsActionTest
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development #1320 +/- ##
=================================================
+ Coverage 56.63% 62.55% +5.92%
Complexity 2268 2268
=================================================
Files 207 207
Lines 8733 8733
=================================================
+ Hits 4946 5463 +517
+ Misses 3787 3270 -517
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR reorganizes and expands test coverage for service classes by moving unit tests to feature tests, fixing namespaces, and adding comprehensive test suites for various services.
Key Changes:
- Moves unit tests for SyncProjectAuthors and CommonChemistry to feature tests in appropriate locations
- Fixes namespaces for ELN-related tests to match their directory structure (Tests\Feature\ExternalServices\ELN)
- Adds comprehensive test coverage for new service classes including FileIntegrityService, ELNMetadataServiceFactory, ChemotionMetadataService, DOIService, and others
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/SyncProjectAuthorsActionTest.php | Deleted - tests moved to ManageAuthorsTest.php as feature tests |
| tests/Unit/CommonChemistryTest.php | Deleted - tests moved to CASServiceTest.php as feature tests |
| tests/Feature/Auth/NFDIAAIProviderTest.php | Deleted - moved to ExternalServices directory with expanded coverage |
| tests/Feature/ExternalServices/ELN/ProcessDraftELNSubmissionProxyTest.php | Fixed namespace from Tests\Unit to Tests\Feature\ExternalServices\ELN |
| tests/Feature/ExternalServices/ELN/ELNSubmissionTrackingTest.php | Fixed namespace, unskipped tests, and updated to use Queue faking |
| tests/Feature/ExternalServices/ELN/ChemotionRepositoryTrackerServiceTest.php | Fixed namespace and added extensive error handling tests |
| tests/Feature/ManageAuthorsTest.php | Added SyncProjectAuthors action tests moved from unit tests |
| tests/Feature/FileSystemTest.php | Added comprehensive FileIntegrityService, StorageSignedUrlService, and PathGeneratorService tests |
| tests/Feature/ExternalServices/NFDIAAIProviderTest.php | New file with comprehensive provider tests including user mapping and authentication |
| tests/Feature/ExternalServices/ELN/ELNMetadataServiceFactoryTest.php | New file testing factory pattern for ELN metadata services |
| tests/Feature/ExternalServices/ELN/ChemotionMetadataServiceTest.php | New file with extensive tests for Chemotion metadata extraction and validation |
| tests/Feature/ExternalServices/DOIServiceTest.php | New file testing DOI service operations with DataCite |
| tests/Feature/ExternalServices/CASServiceTest.php | Renamed from CASIntegrationTest and added CommonChemistry service tests |
Comments suppressed due to low confidence (2)
tests/Feature/ExternalServices/ELN/ELNSubmissionTrackingTest.php:25
- The test was previously skipped with the comment "must be revisited." Now it's been unskipped and modified. Consider adding a comment or commit message explaining what was fixed or why it's now safe to run, to provide context for future developers.
tests/Feature/ExternalServices/ELN/ELNSubmissionTrackingTest.php:147 - The comment states "The tracking integration in PublishStudy might not be fully implemented yet" which suggests incomplete functionality. If this is the case, consider using markTestIncomplete() or adding a todo comment with a ticket reference to track when the full implementation will be added.
| DB::flushQueryLog(); | ||
| DB::enableQueryLog(); | ||
| $syncProjectAuthors->handle($project, $authorsData); | ||
| $queries = DB::getQueryLog(); | ||
| $this->assertLessThan(15, count($queries)); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using query log counting to prevent N+1 queries is fragile and can break with framework updates or unrelated changes. Consider using a package like Laravel's built-in query count assertions or a dedicated N+1 detection package. The threshold of 15 queries is also arbitrary and doesn't clearly communicate the expected behavior.
| DB::flushQueryLog(); | |
| DB::enableQueryLog(); | |
| $syncProjectAuthors->handle($project, $authorsData); | |
| $queries = DB::getQueryLog(); | |
| $this->assertLessThan(15, count($queries)); | |
| $this->expectsDatabaseQueryCount(14); | |
| $syncProjectAuthors->handle($project, $authorsData); |
| $this->assertEquals('varian', $varianFolder->instrument_type); | ||
| } | ||
|
|
||
| // FileIntegrityService Tests |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment "FileIntegrityService Tests" indicates a new section, but it's placed in the middle of the FileSystemTest class. Consider organizing these tests into a separate test file (e.g., FileIntegrityServiceTest.php) to follow single responsibility principle and improve test organization.
| // FileIntegrityService Tests | |
| // File integrity related tests |
|
|
||
| public function test_retry_failed_verifications(): void | ||
| { | ||
| \Illuminate\Support\Facades\Storage::fake('local'); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the fully qualified class name for Storage facade is inconsistent with the import at line 13. Use the imported facade class consistently throughout the file instead of the fully qualified name.
| 'integrity_status' => 'pending', | ||
| ]); | ||
|
|
||
| \Illuminate\Support\Facades\Storage::disk('local')->put('drafts/test.txt', $fileContent); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the fully qualified class name for Storage facade is inconsistent with the import at line 13. Use the imported facade class consistently throughout the file instead of the fully qualified name.
| 'integrity_status' => 'pending', | ||
| ]); | ||
|
|
||
| \Illuminate\Support\Facades\Storage::disk('local')->put('drafts/test.txt', $fileContent); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the fully qualified class name for Storage facade is inconsistent with the import at line 13. Use the imported facade class consistently throughout the file instead of the fully qualified name.
|
|
||
| public function test_download_file_from_storage_returns_null_when_missing(): void | ||
| { | ||
| \Illuminate\Support\Facades\Storage::fake('local'); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the fully qualified class name for Storage facade is inconsistent with the import at line 13. Use the imported facade class consistently throughout the file instead of the fully qualified name.
| 'verification_attempts' => 1, | ||
| ]); | ||
|
|
||
| \Illuminate\Support\Facades\Storage::disk('local')->put('drafts/test.txt', $fileContent); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the fully qualified class name for Storage facade is inconsistent with the import at line 13. Use the imported facade class consistently throughout the file instead of the fully qualified name.
| DB::shouldReceive('transaction')->once()->andReturnUsing(function ($callback) { | ||
| return $callback(); | ||
| }); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mocking the DB facade's transaction method in a feature test is an anti-pattern. This test should verify that the transaction behavior works correctly in integration, not mock it. If you need to test transaction behavior, consider using database transactions and verifying rollback on errors, or move this specific test to a unit test where mocking is more appropriate.
|
|
||
| public function test_verify_file_integrity_fails_with_mismatched_checksum(): void | ||
| { | ||
| \Illuminate\Support\Facades\Storage::fake('local'); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the fully qualified class name for Storage facade is inconsistent with the import at line 13. Use the imported facade class consistently throughout the file instead of the fully qualified name.
|
|
||
| public function test_verify_file_integrity_fails_with_size_mismatch(): void | ||
| { | ||
| \Illuminate\Support\Facades\Storage::fake('local'); |
Copilot
AI
Dec 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the fully qualified class name for Storage facade is inconsistent with the import at line 13. Use the imported facade class consistently throughout the file instead of the fully qualified name.
No description provided.