Remove duplicate register request notifications

This commit is contained in:
Tim
2025-07-15 12:50:11 +08:00
parent 5b886420c5
commit 4036bd25a5
4 changed files with 38 additions and 12 deletions

View File

@@ -1,7 +1,6 @@
package com.openisle.service;
import com.openisle.model.Notification;
import com.openisle.model.User;
import com.openisle.model.*;
import com.openisle.repository.NotificationRepository;
import com.openisle.repository.UserRepository;
import org.junit.jupiter.api.Test;
@@ -78,4 +77,23 @@ class NotificationServiceTest {
assertEquals(5L, count);
verify(nRepo).countByUserAndRead(user, false);
}
@Test
void createRegisterRequestNotificationsDeletesOldOnes() {
NotificationRepository nRepo = mock(NotificationRepository.class);
UserRepository uRepo = mock(UserRepository.class);
NotificationService service = new NotificationService(nRepo, uRepo);
User admin = new User();
admin.setId(10L);
User applicant = new User();
applicant.setId(20L);
when(uRepo.findByRole(Role.ADMIN)).thenReturn(List.of(admin));
service.createRegisterRequestNotifications(applicant, "reason");
verify(nRepo).deleteByTypeAndFromUser(NotificationType.REGISTER_REQUEST, applicant);
verify(nRepo).save(any(Notification.class));
}
}