Skip to content

test: add unit tests for MedicalRecordService#141

Open
annikaholmqvist94 wants to merge 1 commit intomainfrom
feat/medical-record-service-tests
Open

test: add unit tests for MedicalRecordService#141
annikaholmqvist94 wants to merge 1 commit intomainfrom
feat/medical-record-service-tests

Conversation

@annikaholmqvist94
Copy link
Copy Markdown
Contributor

@annikaholmqvist94 annikaholmqvist94 commented Apr 7, 2026

  • Introduced MedicalRecordServiceTest to provide thorough coverage for service methods.
  • Verified create, getById, getByPet, getByOwner, getByClinic, and similar retrieval methods.
  • Added tests for core functionalities: update, assignVet, updateStatus, and close.
  • Ensured validation of policies, exception handling, and logging behavior. closes Test: Implement Unit Tests for MedicalRecord Service #100

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests for medical record service functionality to ensure reliability and correctness of record management operations.

- Introduced `MedicalRecordServiceTest` to provide thorough coverage for service methods.
- Verified `create`, `getById`, `getByPet`, `getByOwner`, `getByClinic`, and similar retrieval methods.
- Added tests for core functionalities: `update`, `assignVet`, `updateStatus`, and `close`.
- Ensured validation of policies, exception handling, and logging behavior.
closes #100
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 56467797-4f91-4d72-8d60-0363dd4d89e6

📥 Commits

Reviewing files that changed from the base of the PR and between 1cf45a8 and f613a01.

📒 Files selected for processing (1)
  • src/test/java/org/example/vet1177/services/MedicalRecordServiceTest.java

📝 Walkthrough

Walkthrough

A comprehensive JUnit 5 test suite for MedicalRecordService was added with Mockito-based unit tests covering CRUD operations, validation logic (business rules, resource existence), and audit logging integration across multiple service methods and error scenarios.

Changes

Cohort / File(s) Summary
MedicalRecordService Unit Tests
src/test/java/org/example/vet1177/services/MedicalRecordServiceTest.java
Added 428 lines of comprehensive test coverage for create, getById, getByPet/Owner/Clinic/ClinicAndStatus, getByPetAllowedForUser/getByOwnerAllowedForUser, update, assignVet, updateStatus, close, and save operations. Tests verify repository delegation, permission filtering, business rule enforcement (closed record transitions), resource existence validation, and ActivityLogService logging calls.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • #87: Tests verify that ActivityLogService is invoked and activity logs are created for create/update/assignVet/updateStatus/close operations, directly validating the audit logging integration.
  • #71: Tests directly exercise the new MedicalRecordService method signatures and behavior changes (create, assignVet, updateStatus, permission-based filtering) introduced in that PR.
  • #6: Tests construct and verify the behavior of MedicalRecord, RecordStatus, and MedicalRecordRepository query methods (findByPetId, findByClinicIdAndStatus) that were established in that PR.

Suggested reviewers

  • johanbriger
  • TatjanaTrajkovic
  • lindaeskilsson

Poem

🐰 Hopping through the test suite with glee,
Mocks and assertions dance in unity,
Medical records verified with care,
Business rules caught—nothing slips through there!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding unit tests for MedicalRecordService.
Linked Issues check ✅ Passed All objectives from issue #100 are met: CRUD operations tested, data integrity validated through repository mocks, and audit logging verified.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing unit tests for MedicalRecordService; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/medical-record-service-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lindaeskilsson
Copy link
Copy Markdown
Contributor

Snygg testat! Ser omfattande ut!

Copy link
Copy Markdown
Contributor

@TatjanaTrajkovic TatjanaTrajkovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ser väldigt bra ut! Bra täckning och tydliga tester. Fundera på att kanske implementera hjälp metoder, för att få mindre kod och mer läsbar test. Ett exempel :
private void mockValidCreateSetup() {
when(petRepository.findById(petId)).thenReturn(Optional.of(pet));
when(clinicRepository.findById(clinicId)).thenReturn(Optional.of(clinic));
when(medicalRecordRepository.save(any(MedicalRecord.class))).thenReturn(record);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: Implement Unit Tests for MedicalRecord Service

3 participants