test(#248): add deleteWithDescendants test coverage to TagServiceTest
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -375,6 +375,46 @@ class TagServiceTest {
|
||||
assertThat(result).isEqualTo(target);
|
||||
}
|
||||
|
||||
// ─── deleteWithDescendants ────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void deleteWithDescendants_throwsNotFound_whenTagMissing() {
|
||||
UUID id = UUID.randomUUID();
|
||||
when(tagRepository.findById(id)).thenReturn(Optional.empty());
|
||||
|
||||
assertThatThrownBy(() -> tagService.deleteWithDescendants(id))
|
||||
.isInstanceOf(DomainException.class)
|
||||
.extracting(e -> ((DomainException) e).getCode())
|
||||
.isEqualTo(ErrorCode.TAG_NOT_FOUND);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteWithDescendants_deletesSubtreeDocTagsAndAllTags() {
|
||||
UUID id = UUID.randomUUID();
|
||||
UUID childId = UUID.randomUUID();
|
||||
Tag tag = Tag.builder().id(id).name("Root").build();
|
||||
when(tagRepository.findById(id)).thenReturn(Optional.of(tag));
|
||||
when(tagRepository.findDescendantIds(id)).thenReturn(List.of(id, childId));
|
||||
|
||||
tagService.deleteWithDescendants(id);
|
||||
|
||||
verify(tagRepository).deleteDocumentTagsByTagIds(List.of(id, childId));
|
||||
verify(tagRepository).deleteAllById(List.of(id, childId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteWithDescendants_whenLeafTag_deletesTagAndItsOwnDocTags() {
|
||||
UUID id = UUID.randomUUID();
|
||||
Tag tag = Tag.builder().id(id).name("Leaf").build();
|
||||
when(tagRepository.findById(id)).thenReturn(Optional.of(tag));
|
||||
when(tagRepository.findDescendantIds(id)).thenReturn(List.of(id));
|
||||
|
||||
tagService.deleteWithDescendants(id);
|
||||
|
||||
verify(tagRepository).deleteDocumentTagsByTagIds(List.of(id));
|
||||
verify(tagRepository).deleteAllById(List.of(id));
|
||||
}
|
||||
|
||||
// ─── delete ───────────────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user