Skip to content

Test/integration tests activitylog#189

Merged
TatjanaTrajkovic merged 7 commits into
mainfrom
test/integration_tests_activitylog
Apr 10, 2026
Merged

Test/integration tests activitylog#189
TatjanaTrajkovic merged 7 commits into
mainfrom
test/integration_tests_activitylog

Conversation

@TatjanaTrajkovic

@TatjanaTrajkovic TatjanaTrajkovic commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for requests missing required headers; API now returns HTTP 400 with a clear message naming the missing header.
  • Tests

    • Test suite switched to an in-memory database for faster, isolated runs; added reusable test data factories and new integration tests covering activity log retrieval across roles and clinic boundaries.

- Added end-to-end integration test for ActivityLog
- Configured H2 in-memory DB for test profile
- Updated application-test.properties
- Ensured entity relationships and constraints are correctly handled

Foundation for further integration testing
- Added integration tests for ActivityLog (owner, vet access, missing header)
- Introduced TestDataFactory for reusable test setup
- Updated application-test.properties to use H2 in-memory DB
- Added exception handling for missing request headers (400 instead of 500)
@coderabbitai

coderabbitai Bot commented Apr 10, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@TatjanaTrajkovic has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 27 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 13 minutes and 27 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bdd404a1-4349-4e31-a95f-ffcdae463dc9

📥 Commits

Reviewing files that changed from the base of the PR and between f7433df and 22ffb6d.

📒 Files selected for processing (2)
  • src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java
  • src/test/resources/application-test.properties
📝 Walkthrough

Walkthrough

Adds H2 as the test database, a MissingRequestHeaderException handler, a TestDataFactory for integration tests, and new ActivityLog integration tests exercising GET /api/activity-logs/record/{recordId}, including a missing userId header case.

Changes

Cohort / File(s) Summary
Build & Test DB
pom.xml, src/test/resources/application-test.properties
Added com.h2database:h2 as a test dependency and switched test profile to in-memory H2 (driver, dialect, credentials); updated Spring SQL init settings for tests.
Exception Handling
src/main/java/org/example/vet1177/exception/GlobalExceptionHandler.java
Added handler for MissingRequestHeaderException that logs the missing header and returns HTTP 400 with an ErrorResponse.
Test Utilities
src/test/java/org/example/vet1177/integration/TestDataFactory.java
New test factory with static helpers to create and persist Clinic, User, Pet, MedicalRecord, and ActivityLog entities for integration tests.
Integration Tests
src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java
New Spring Boot integration tests (4 cases) for GET /api/activity-logs/record/{recordId} covering owner access, same-clinic vet access, cross-clinic filtering, and missing userId header (expects 400).

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

test

Suggested reviewers

  • lindaeskilsson
  • annikaholmqvist94
  • johanbriger

Poem

🐇 Hopped into tests with a cheerful cheer,

H2 for a burrow where quick checks appear,
Factories plant pets and records so spry,
Headers are counted — don't let one slip by,
Logs nibble carrots under Springtime sky.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Test/integration tests activitylog' is partially related to the changeset. While it correctly references the addition of integration tests for activity logs (the primary addition), it is somewhat generic and uses a slash-prefix pattern that suggests it may be referencing a branch naming convention rather than clearly communicating the main change.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/integration_tests_activitylog

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java (1)

44-106: Remove the large commented-out legacy test block.

Keeping disabled test code in the class adds noise and makes maintenance harder. Please delete it now that TestDataFactory-based setup is in place.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java`
around lines 44 - 106, Remove the large disabled test block for
should_return_logs_for_owner_only in ActivityLogIntegrationTest: delete the
entire commented-out test (the lines starting with //    `@Test` and ending with
the closing comment) so the file no longer contains the legacy commented test
that duplicates TestDataFactory-based setup; ensure you only remove the
commented block and do not alter other tests or imports in
ActivityLogIntegrationTest.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/test/resources/application-test.properties`:
- Around line 18-19: The comment "Kör schema.sql men INTE data.sql" conflicts
with the properties: currently spring.sql.init.mode=never disables Spring SQL
initialization so schema.sql won't run; decide which behavior you want and make
one of two fixes: if you want Spring to run schema.sql but not data.sql, set
spring.sql.init.mode=embedded (or always) and keep
spring.sql.init.data-locations= (or set spring.sql.init.data-locations=none) and
update the comment accordingly; if you do not want schema.sql and rely on
Hibernate ddl-auto, update the comment to state that schema.sql is not run and
keep spring.sql.init.mode=never (and optionally remove or empty
spring.sql.init.data-locations). Ensure changes reference the properties
spring.sql.init.mode and spring.sql.init.data-locations and the comment text
"Kör schema.sql men INTE data.sql".

---

Nitpick comments:
In
`@src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java`:
- Around line 44-106: Remove the large disabled test block for
should_return_logs_for_owner_only in ActivityLogIntegrationTest: delete the
entire commented-out test (the lines starting with //    `@Test` and ending with
the closing comment) so the file no longer contains the legacy commented test
that duplicates TestDataFactory-based setup; ensure you only remove the
commented block and do not alter other tests or imports in
ActivityLogIntegrationTest.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 13f2b87f-30c6-4486-822e-deea769fd856

📥 Commits

Reviewing files that changed from the base of the PR and between 697f434 and 3767d6c.

📒 Files selected for processing (5)
  • pom.xml
  • src/main/java/org/example/vet1177/exception/GlobalExceptionHandler.java
  • src/test/java/org/example/vet1177/integration/TestDataFactory.java
  • src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java
  • src/test/resources/application-test.properties

Comment thread src/test/resources/application-test.properties

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
src/test/resources/application-test.properties (1)

19-20: ⚠️ Potential issue | 🟡 Minor

Comment and SQL-init behavior are still contradictory.

Line 19 says schema.sql should run, but Line 20 (spring.sql.init.mode=never) disables Spring SQL initialization entirely. Please either update the comment or switch init mode to match the intended behavior.

#!/bin/bash
# Verify current test SQL init intent vs effective configuration.
cat -n src/test/resources/application-test.properties | sed -n '16,22p'
fd -i "schema.sql" src
fd -i "data.sql" src
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/test/resources/application-test.properties` around lines 19 - 20, The
comment and property disagree: the comment says "Kör schema.sql men INTE
data.sql" (run schema.sql but not data.sql) while spring.sql.init.mode=never
disables SQL init entirely; fix by either (A) updating spring.sql.init.mode to
an init mode that runs schema.sql (e.g., set spring.sql.init.mode=embedded or
always depending on your test DB) and ensure only schema.sql is present (no
data.sql), or (B) change the comment to reflect that SQL init is disabled;
adjust the file around the spring.sql.init.mode property and the schema/data
files accordingly so the intent and configuration match.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/test/resources/application-test.properties`:
- Around line 19-20: The comment and property disagree: the comment says "Kör
schema.sql men INTE data.sql" (run schema.sql but not data.sql) while
spring.sql.init.mode=never disables SQL init entirely; fix by either (A)
updating spring.sql.init.mode to an init mode that runs schema.sql (e.g., set
spring.sql.init.mode=embedded or always depending on your test DB) and ensure
only schema.sql is present (no data.sql), or (B) change the comment to reflect
that SQL init is disabled; adjust the file around the spring.sql.init.mode
property and the schema/data files accordingly so the intent and configuration
match.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 80be89ba-2206-4080-b64c-bc8b47a9b53b

📥 Commits

Reviewing files that changed from the base of the PR and between 3767d6c and 562e527.

📒 Files selected for processing (1)
  • src/test/resources/application-test.properties

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java (1)

54-116: Remove the commented-out legacy test implementation.

This block is dead code now that TestDataFactory-based setup is in place; keeping it increases maintenance noise.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java`
around lines 54 - 116, Remove the commented-out legacy test block for
should_return_logs_for_owner_only from ActivityLogIntegrationTest.java (the
large commented region that creates Clinic, User, Pet, MedicalRecord,
ActivityLog instances) since TestDataFactory-based setup replaces it; delete the
entire commented method and any nearby commented helper code to reduce noise,
then run tests to ensure no unused imports or references remain (adjust imports
if the removal makes any unused).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java`:
- Around line 54-116: Remove the commented-out legacy test block for
should_return_logs_for_owner_only from ActivityLogIntegrationTest.java (the
large commented region that creates Clinic, User, Pet, MedicalRecord,
ActivityLog instances) since TestDataFactory-based setup replaces it; delete the
entire commented method and any nearby commented helper code to reduce noise,
then run tests to ensure no unused imports or references remain (adjust imports
if the removal makes any unused).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 29a16c78-2ff6-4c63-8099-1070feb72421

📥 Commits

Reviewing files that changed from the base of the PR and between 562e527 and f7433df.

📒 Files selected for processing (1)
  • src/test/java/org/example/vet1177/integration/activitylog/ActivityLogIntegrationTest.java

@TatjanaTrajkovic TatjanaTrajkovic linked an issue Apr 10, 2026 that may be closed by this pull request
@TatjanaTrajkovic
TatjanaTrajkovic merged commit 81b593f into main Apr 10, 2026
2 checks passed
@TatjanaTrajkovic TatjanaTrajkovic self-assigned this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: integrationtests for ActivityLog

1 participant