feat(join): A4 — Join household (accept invite) #61
@@ -205,7 +205,9 @@ public class HouseholdService {
|
|||||||
HouseholdInvite invite = householdInviteRepository.findByInviteCode(code)
|
HouseholdInvite invite = householdInviteRepository.findByInviteCode(code)
|
||||||
.orElseThrow(() -> new ResourceNotFoundException("Invite not found or invalid"));
|
.orElseThrow(() -> new ResourceNotFoundException("Invite not found or invalid"));
|
||||||
|
|
||||||
if ("used".equals(invite.getStatus()) || invite.getExpiresAt().isBefore(Instant.now())) {
|
if ("used".equals(invite.getStatus())
|
||||||
|
|| invite.getInvalidatedAt() != null
|
||||||
|
|| invite.getExpiresAt().isBefore(Instant.now())) {
|
||||||
throw new ResourceNotFoundException("Invite not found or invalid");
|
throw new ResourceNotFoundException("Invite not found or invalid");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -288,6 +288,20 @@ class HouseholdServiceTest {
|
|||||||
.isInstanceOf(ResourceNotFoundException.class);
|
.isInstanceOf(ResourceNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void acceptInviteShouldThrow404WhenInviteIsInvalidated() {
|
||||||
|
var owner = testUser();
|
||||||
|
var household = new Household("Smith family", owner);
|
||||||
|
var invite = new HouseholdInvite(household, "SUPERSEDED", Instant.now().plusSeconds(86400));
|
||||||
|
invite.setInvalidatedAt(Instant.now()); // superseded by a new invite
|
||||||
|
|
||||||
|
when(userAccountRepository.existsByEmailIgnoreCase("tom@example.com")).thenReturn(false);
|
||||||
|
when(householdInviteRepository.findByInviteCode("SUPERSEDED")).thenReturn(Optional.of(invite));
|
||||||
|
|
||||||
|
assertThatThrownBy(() -> householdService.acceptInvite("SUPERSEDED", "Tom", "tom@example.com", "secret123"))
|
||||||
|
.isInstanceOf(ResourceNotFoundException.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void createHouseholdShouldThrowWhenUserNotFound() {
|
void createHouseholdShouldThrowWhenUserNotFound() {
|
||||||
when(userAccountRepository.findByEmailIgnoreCase("unknown@example.com")).thenReturn(Optional.empty());
|
when(userAccountRepository.findByEmailIgnoreCase("unknown@example.com")).thenReturn(Optional.empty());
|
||||||
|
|||||||
Reference in New Issue
Block a user