This commit is contained in:
@@ -85,7 +85,7 @@ public class FriendshipServiceTest {
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.flush();
|
||||
|
||||
// already pending: only sender reverse missing -> unexpected throw
|
||||
// already pending: only sender side exists, reverse missing -> unexpected throw
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.REQUESTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.requestFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
@@ -98,7 +98,7 @@ public class FriendshipServiceTest {
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.flush();
|
||||
|
||||
// already pending reverse: only sender reverse missing -> unexpected throw
|
||||
// already pending reverse: only sender side exists, reverse missing -> unexpected throw
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.PENDING));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.requestFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
@@ -111,7 +111,7 @@ public class FriendshipServiceTest {
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.flush();
|
||||
|
||||
// already friends: only sender reverse missing -> unexpected throw
|
||||
// already friends: only sender side exists, reverse missing -> unexpected throw
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.ACCEPTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.requestFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
@@ -121,6 +121,22 @@ public class FriendshipServiceTest {
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.REJECTED));
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.PENDING));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.requestFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.flush();
|
||||
|
||||
// PENDING check: relation to Friend != REQUESTED, rel to Sender == PENDING
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.ACCEPTED));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.PENDING));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.requestFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.flush();
|
||||
|
||||
// ACCEPTED check: relation to Friend != ACCEPTED, rel to Sender == ACCEPTED
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.REQUESTED));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.ACCEPTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.requestFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.flush();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -174,6 +190,31 @@ public class FriendshipServiceTest {
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.ACCEPTED));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.ACCEPTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.acceptFriendship(sender, friend.getId()));
|
||||
|
||||
// wrong status: sender is REQUESTED instead of PENDING (swapped)
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.REQUESTED));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.PENDING));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.acceptFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
|
||||
// wrong status: both ACCEPTED
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.ACCEPTED));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.ACCEPTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.acceptFriendship(sender, friend.getId()));
|
||||
|
||||
// relation to Friend != PENDING, relation to Sender == REQUESTED
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.ACCEPTED));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.REQUESTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.acceptFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.flush();
|
||||
|
||||
// relation to Friend == PENDING, relation to sender != REQUESTED
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.PENDING));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.ACCEPTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.acceptFriendship(sender, friend.getId()));
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +246,22 @@ public class FriendshipServiceTest {
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.ACCEPTED));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.ACCEPTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.rejectFriendship(sender, friend.getId()));
|
||||
|
||||
// only one side exists (sender has PENDING, friend missing)
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.PENDING));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.rejectFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
|
||||
// only one side exists (friend has REQUESTED, sender missing)
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.REQUESTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.rejectFriendship(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
|
||||
// wrong status: sender is REQUESTED instead of PENDING
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.REQUESTED));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.PENDING));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.rejectFriendship(sender, friend.getId()));
|
||||
}
|
||||
|
||||
|
||||
@@ -236,6 +293,16 @@ public class FriendshipServiceTest {
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.PENDING));
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.REQUESTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.unfriend(sender, friend.getId()));
|
||||
|
||||
// only one side exists (only sender has ACCEPTED)
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
friendshipRepository.save(new Friendship(sender, friend, FriendShipStatus.ACCEPTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.unfriend(sender, friend.getId()));
|
||||
friendshipRepository.deleteAllInBatch();
|
||||
|
||||
// only one side exists (only friend has ACCEPTED)
|
||||
friendshipRepository.save(new Friendship(friend, sender, FriendShipStatus.ACCEPTED));
|
||||
assertThrows(RuntimeException.class, () -> friendshipService.unfriend(sender, friend.getId()));
|
||||
}
|
||||
|
||||
|
||||
@@ -446,4 +513,33 @@ public class FriendshipServiceTest {
|
||||
assertThrows(RuntimeException.class,
|
||||
() -> friendshipService.getPrivateNameIfFriendshipAccepted(sender, List.of(99999L)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// getByFriendcode
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Test
|
||||
void requestFriendshipByFriendcode_Success() {
|
||||
friendshipService.requestFriendshipByFriendcode(sender, friend.getFriendCode());
|
||||
|
||||
assertEquals(FriendShipStatus.REQUESTED, friendshipRepository.findByUserAndFriend(sender, friend).getStatus());
|
||||
assertEquals(FriendShipStatus.PENDING, friendshipRepository.findByUserAndFriend(friend, sender).getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestFriendshipByFriendcode_NotFound_Throws() {
|
||||
assertThrows(RuntimeException.class,
|
||||
() -> friendshipService.requestFriendshipByFriendcode(sender, "INVALID_CODE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestFriendshipByFriendcode_Self_Throws() {
|
||||
assertThrows(RuntimeException.class,
|
||||
() -> friendshipService.requestFriendshipByFriendcode(sender, sender.getFriendCode()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user