fix(invites): validate groupIds existence in createInvite — throw GROUP_NOT_FOUND
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,6 +53,9 @@ public class InviteService {
|
|||||||
Set<UUID> groupIds = new HashSet<>();
|
Set<UUID> groupIds = new HashSet<>();
|
||||||
if (dto.getGroupIds() != null && !dto.getGroupIds().isEmpty()) {
|
if (dto.getGroupIds() != null && !dto.getGroupIds().isEmpty()) {
|
||||||
List<UserGroup> groups = userService.findGroupsByIds(dto.getGroupIds());
|
List<UserGroup> groups = userService.findGroupsByIds(dto.getGroupIds());
|
||||||
|
if (groups.size() != dto.getGroupIds().size()) {
|
||||||
|
throw DomainException.notFound(ErrorCode.GROUP_NOT_FOUND, "One or more group IDs do not exist");
|
||||||
|
}
|
||||||
groups.forEach(g -> groupIds.add(g.getId()));
|
groups.forEach(g -> groupIds.add(g.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,6 +156,20 @@ class InviteServiceTest {
|
|||||||
assertThat(result.getGroupIds()).contains(g.getId());
|
assertThat(result.getGroupIds()).contains(g.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void createInvite_throwsGroupNotFound_whenSubmittedGroupIdDoesNotExist() {
|
||||||
|
UUID unknownGroupId = UUID.randomUUID();
|
||||||
|
when(userService.findGroupsByIds(List.of(unknownGroupId))).thenReturn(List.of());
|
||||||
|
|
||||||
|
CreateInviteRequest req = new CreateInviteRequest();
|
||||||
|
req.setGroupIds(List.of(unknownGroupId));
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> inviteService.createInvite(req, admin))
|
||||||
|
.isInstanceOf(DomainException.class)
|
||||||
|
.extracting(e -> ((DomainException) e).getCode())
|
||||||
|
.isEqualTo(ErrorCode.GROUP_NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
// ─── redeemInvite ─────────────────────────────────────────────────────────
|
// ─── redeemInvite ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user