feat: admin change-password endpoint with lockout on wrong current password

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-30 13:51:57 +08:00
1 parent 39708224ad
commit 6c6734baa3
7 files changed
+277 -1

No files matched your search

@@ -0,0 +1,43 @@
package com.solvway.mobile.api.service;
import com.solvway.mobile.api.util.RestTemplateCustomUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class AdminAuthenticationServiceChangePasswordTest {
private RestTemplateCustomUtil rest;
private AdminAuthenticationService service;
@BeforeEach
void setUp() {
rest = mock(RestTemplateCustomUtil.class);
service = new AdminAuthenticationService(rest);
when(rest.getURLforApiService("/user/changeAdminPassword")).thenReturn("http://sys/user/changeAdminPassword");
}
@Test
void postsIdCurrentAndNewPassword_returnsBody() {
Map<String, Object> body = Map.of("id", 9L, "currentPassword", "old", "newPassword", "new");
when(rest.postForEntity(eq("http://sys/user/changeAdminPassword"), eq(String.class), eq(body)))
.thenReturn(ResponseEntity.ok("OK"));
assertThat(service.changeAdminPassword(9L, "old", "new")).isEqualTo("OK");
}
@Test
void nullBody_isNotFound() {
when(rest.postForEntity(any(String.class), eq(String.class), any(Object.class)))
.thenReturn(new ResponseEntity<>(HttpStatus.OK));
assertThat(service.changeAdminPassword(9L, "old", "new")).isEqualTo("NOT_FOUND");
}
}