Skip to content

Add unit tests for Rating, Notification, and Statistic components#26

Open
Copilot wants to merge 2 commits into
agent-testfrom
copilot/update-unit-tests
Open

Add unit tests for Rating, Notification, and Statistic components#26
Copilot wants to merge 2 commits into
agent-testfrom
copilot/update-unit-tests

Conversation

Copilot AI commented Mar 28, 2026

Copy link
Copy Markdown

Several controllers and services lacked test coverage: RatingController, NotificationService, NotificationController, StatisticService, and StatisticController.

New Tests (19 tests across 5 files)

  • RatingControllerTest — POST /rating success, GET /rating pagination, validation failures (star out of range, comment too short, invalid page)
  • NotificationServiceTestgetNotifications (success + empty + user-not-found), addEmitter (valid/invalid token), createNotification
  • NotificationControllerTest — GET /notifications (authenticated, empty list, unauthenticated 401)
  • StatisticServiceTestgetStatistics with full data and empty/null data edge case; verifies aggregated totals (e.g. totalCustomers = active + inactive)
  • StatisticControllerTest — ADMIN success, unauthenticated 401, non-admin 403

All tests follow the existing conventions: @SpringBootTest + @MockBean, @Nested HappyCase/UnHappyCase structure, @WithMockUser for auth context, Given-When-Then comments.

@Nested
class UnHappyCase {
    @Test
    @WithMockUser(username = "user@test.com", roles = {"USER"})
    void getStatistics_nonAdminUser_forbidden() throws Exception {
        mockMvc.perform(MockMvcRequestBuilders.get("/statistics"))
                .andExpect(status().isForbidden())
                .andExpect(jsonPath("internalCode").value(1004));
    }
}

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Update unit tests for improved coverage Add unit tests for Rating, Notification, and Statistic components Mar 28, 2026
Copilot AI requested a review from duongminhhieu March 28, 2026 05:31
@sonarqubecloud

Copy link
Copy Markdown

@duongminhhieu duongminhhieu marked this pull request as ready for review March 28, 2026 05:33
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.

2 participants