Add comprehensive unit tests for service, controller, audit, and legacy layers - #17
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…cy layers Part A - Service layer unit tests (Mockito, no Spring context): - PatientServiceTest: getPatientById, createPatient, findBySsn tests - EncounterServiceTest: create, checkIn, startEncounter, completeEncounter, cancelEncounter, markNoShow tests - AuditServiceTest: saveAuditEventAsync delegation and exception swallowing tests - ChronicMedicationServiceTest: UnsupportedOperationException tests for all stub methods Part B - Controller + legacy layer tests: - PatientControllerTest: WebMvcTest with MockBean for GET/POST endpoints - InsuranceCacheTest: Plain JUnit 5 cache operations + HIPAA gap documentation - EncounterExportServiceHipaaTest: Documents SSN exposure in export output All 29 tests pass. No production code modified. Co-Authored-By: Stephen Cornwell <stephen@cognition.ai>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds 29 unit tests across 7 new test files, covering the service layer, controller layer, audit service, and legacy modules. No production code was modified.
Part A — Service layer (Mockito, no Spring context):
PatientServiceTest(5 tests): CRUD operations, MRN generation, SSN lookup blockingEncounterServiceTest(7 tests): Encounter creation with number generation, all status transitions (checkIn → completeEncounter → cancelEncounter → markNoShow)AuditServiceTest(2 tests): Repository delegation and exception swallowingChronicMedicationServiceTest(4 tests): Verifies all stub methods throwUnsupportedOperationExceptionPart B — Controller + legacy layer:
PatientControllerTest(4 tests):@WebMvcTestslice with@MockBeanand@WithMockUser, covering GET/POST endpointsInsuranceCacheTest(6 tests): Plain JUnit 5 for cache CRUD + HIPAA gap documentation (SSN stored with no TTL)EncounterExportServiceHipaaTest(1 test): Documents SSN exported unmasked in plain text outputReview & Testing Checklist for Human
PatientControllerTest.getPatient_returns404_whenServiceThrowsEntityNotFoundException: The test name says "returns 404" but the app has no@ControllerAdvice—EntityNotFoundExceptionactually propagates as aNestedServletException(500 to clients). The test verifies the exception's root cause, not an HTTP 404 status. Decide whether the test name is acceptable as-is or whether a global exception handler should be added to the production code.InsuranceCacheTest.cacheEligibility_storesSsnWithNoTtl_hipaaGapandEncounterExportServiceHipaaTest): Verify these tests adequately capture the compliance gaps you want documented. TheInsuranceCacheTestuses reflection to check for the absence of TTL/expiration fields — confirm this approach meets your documentation needs.ifPresentand silently no-ops when encounters aren't found — there are no tests for that silent failure path. Decide if this is sufficient coverage.mvn testlocally to confirm all 29 tests pass in your environment.Notes
PatientServiceTesthas an unusedsavedEntityvariable increatePatient_succeedsAndGeneratesMrn_whenNoMrnProvided— harmless but could be cleaned up.AuditService.saveAuditEventAsyncis annotated@Asyncand@Transactional(REQUIRES_NEW)in production, but these annotations have no effect in pure Mockito tests (no Spring context). The tests verify the method's internal logic only.EncounterExportServiceHipaaTestis tightly coupled to the exact SQL strings inEncounterExportService— changes to those queries will break the test mock setup.Link to Devin session: https://app.devin.ai/sessions/e090341500b74a939e07ccd8a0ed85dd
Requested by: @stephencornwell