From 3b594c0b0bcce4285168d0fc12b57e9fe003088f Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 31 May 2026 15:55:14 +0200 Subject: [PATCH] test(document): pin undated null->false coercion on /ids (#683) The /search path already pins the Boolean-undated->primitive coercion via search_withoutUndatedParam_forwardsFalseToService; add the symmetric pin for getDocumentIds so an absent param provably resolves to undated=false on the record (never NPE). Raised in the #702 review. Co-Authored-By: Claude Sonnet 4.6 --- .../document/DocumentControllerTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentControllerTest.java b/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentControllerTest.java index 60a141b7..f1e34554 100644 --- a/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentControllerTest.java +++ b/backend/src/test/java/org/raddatz/familienarchiv/document/DocumentControllerTest.java @@ -1233,6 +1233,24 @@ class DocumentControllerTest { assertThat(filtersCaptor.getValue().sender()).isEqualTo(senderId); } + @Test + @WithMockUser(authorities = "WRITE_ALL") + void getDocumentIds_withoutUndatedParam_coercesNullToFalse() throws Exception { + // The controller coerces a null boxed Boolean to primitive false + // (Boolean.TRUE.equals(undated)) so the absent param never NPEs and the + // record always holds a concrete boolean. + when(userService.findByEmail(any())).thenReturn(AppUser.builder().id(UUID.randomUUID()).build()); + ArgumentCaptor filtersCaptor = ArgumentCaptor.forClass(SearchFilters.class); + when(documentService.findIdsForFilter(any())) + .thenReturn(List.of()); + + mockMvc.perform(get("/api/documents/ids")) + .andExpect(status().isOk()); + + verify(documentService).findIdsForFilter(filtersCaptor.capture()); + assertThat(filtersCaptor.getValue().undated()).isFalse(); + } + @Test @WithMockUser(authorities = "WRITE_ALL") void getDocumentIds_returns400_whenResultExceedsFilterCap() throws Exception {