|
|
@@ -14,7 +14,7 @@ import static org.mockito.ArgumentMatchers.*;
|
|
|
class UserCancellationServiceTest {
|
|
|
private final InfoUserMapper users = mock(InfoUserMapper.class);
|
|
|
private final RedisCache redis = mock(RedisCache.class);
|
|
|
- private final UserCancellationService service = new UserCancellationService(users, redis, 7);
|
|
|
+ private final UserCancellationService service = new UserCancellationService(users, redis);
|
|
|
private InfoUser user(String deleted, Date deadline) {
|
|
|
InfoUser u = new InfoUser(); u.setUserId(1L); u.setUserType("0");
|
|
|
u.setStatus("0"); u.setDelFlag(deleted); u.setCancellationDeadlineAt(deadline);
|
|
|
@@ -67,4 +67,54 @@ class UserCancellationServiceTest {
|
|
|
verify(users, never()).restoreCancelledUser(anyLong(), any());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private com.ruoyi.common.core.domain.entity.SysDictData days(String value) {
|
|
|
+ var row = new com.ruoyi.common.core.domain.entity.SysDictData();
|
|
|
+ row.setDictValue(value); row.setStatus("0"); return row;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test void dictionaryChangesApplyToSubsequentRequestsWithoutRecreatingService() {
|
|
|
+ user("0", null); when(users.requestUserCancellation(eq(1L), any())).thenReturn(1);
|
|
|
+ try (var dict = mockStatic(com.ruoyi.common.utils.DictUtils.class)) {
|
|
|
+ dict.when(() -> com.ruoyi.common.utils.DictUtils.getDictCache("user_cancellation_grace_days"))
|
|
|
+ .thenReturn(java.util.List.of(days("14")), java.util.List.of(days("30")));
|
|
|
+ var first = service.request(1L);
|
|
|
+ var second = service.request(1L);
|
|
|
+ assertEquals(14, first.graceDays()); assertEquals(30, second.graceDays());
|
|
|
+ long difference = second.cancellationDeadlineAt().getTime() - first.cancellationDeadlineAt().getTime();
|
|
|
+ assertTrue(difference >= 16L * 86400000 && difference < 16L * 86400000 + 10000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @org.junit.jupiter.params.ParameterizedTest
|
|
|
+ @org.junit.jupiter.params.provider.NullAndEmptySource
|
|
|
+ @org.junit.jupiter.params.provider.ValueSource(strings = {"abc", "0", "-1", "366", "1.5", "999999999999"})
|
|
|
+ void invalidDictionaryValueDefaultsToSevenDays(String value) {
|
|
|
+ user("0", null); when(users.requestUserCancellation(eq(1L), any())).thenReturn(1);
|
|
|
+ try (var dict = mockStatic(com.ruoyi.common.utils.DictUtils.class)) {
|
|
|
+ dict.when(() -> com.ruoyi.common.utils.DictUtils.getDictCache("user_cancellation_grace_days"))
|
|
|
+ .thenReturn(java.util.List.of(days(value)));
|
|
|
+ assertEquals(7, service.request(1L).graceDays());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test void missingDisabledOrUnavailableDictionaryDefaultsToSevenDays() {
|
|
|
+ user("0", null); when(users.requestUserCancellation(eq(1L), any())).thenReturn(1);
|
|
|
+ var disabled = days("14"); disabled.setStatus("1");
|
|
|
+ try (var dict = mockStatic(com.ruoyi.common.utils.DictUtils.class)) {
|
|
|
+ dict.when(() -> com.ruoyi.common.utils.DictUtils.getDictCache("user_cancellation_grace_days"))
|
|
|
+ .thenReturn(null, java.util.List.of(), java.util.List.of(disabled))
|
|
|
+ .thenThrow(new IllegalStateException("cache unavailable"));
|
|
|
+ for (int i=0; i<4; i++) assertEquals(7, service.request(1L).graceDays());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test void dictionaryChangeDoesNotChangeExistingRecoveryDeadline() {
|
|
|
+ var deadline = new Date(System.currentTimeMillis() + 60000);
|
|
|
+ var u = user("1", deadline); when(users.restoreCancelledUser(eq(1L), any())).thenReturn(1);
|
|
|
+ try (var dict = mockStatic(com.ruoyi.common.utils.DictUtils.class)) {
|
|
|
+ assertSame(u, service.authenticatedLogin(1L));
|
|
|
+ dict.verifyNoInteractions();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|