feat(iam): add GET /api/admin/users endpoint for all-users overview
This commit is contained in:
parent
41e489a2dd
commit
cf59de80bc
@ -31,6 +31,23 @@ public class AdminIamController {
|
|||||||
private final AdminIamService adminIamService;
|
private final AdminIamService adminIamService;
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
@Operation(summary = "Lädt alle User",
|
||||||
|
description = "Zeigt alle registrierten Benutzer sortiert nach Erstellungsdatum (neueste zuerst).")
|
||||||
|
@ApiResponse(
|
||||||
|
responseCode = "200",
|
||||||
|
description = "Liste aller Benutzer erfolgreich geladen",
|
||||||
|
content = @Content(
|
||||||
|
mediaType = MediaType.APPLICATION_JSON_VALUE,
|
||||||
|
array = @ArraySchema(
|
||||||
|
schema = @Schema(implementation = UserProfileResponse.class)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
public ResponseEntity<List<UserProfileResponse>> getAllUsers() {
|
||||||
|
return ResponseEntity.ok(userMapper.mapToDto(adminIamService.getAllUsers()));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/pending")
|
@GetMapping("/pending")
|
||||||
@Operation(summary = "Lädt alle wartenden User",
|
@Operation(summary = "Lädt alle wartenden User",
|
||||||
description = "Zeigt User im Status PENDING inkl. der Ergebnisse des EDA-Netz-Checks.")
|
description = "Zeigt User im Status PENDING inkl. der Ergebnisse des EDA-Netz-Checks.")
|
||||||
|
|||||||
@ -0,0 +1,73 @@
|
|||||||
|
package at.mueller.eeg.backend.iam.api;
|
||||||
|
|
||||||
|
import at.mueller.eeg.backend.iam.api.dto.IamDtos.UserProfileResponse;
|
||||||
|
import at.mueller.eeg.backend.iam.domain.User;
|
||||||
|
import at.mueller.eeg.backend.iam.mapper.UserMapper;
|
||||||
|
import at.mueller.eeg.backend.iam.service.AdminIamService;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.InjectMocks;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
|
class AdminIamControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AdminIamService adminIamService;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
@InjectMocks
|
||||||
|
private AdminIamController adminIamController;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getAllUsers() {
|
||||||
|
User user1 = new User();
|
||||||
|
user1.setId(UUID.randomUUID());
|
||||||
|
user1.setEmail("alice@example.com");
|
||||||
|
|
||||||
|
User user2 = new User();
|
||||||
|
user2.setId(UUID.randomUUID());
|
||||||
|
user2.setEmail("bob@example.com");
|
||||||
|
|
||||||
|
when(adminIamService.getAllUsers()).thenReturn(List.of(user1, user2));
|
||||||
|
|
||||||
|
UserProfileResponse dto1 = new UserProfileResponse(
|
||||||
|
user1.getId(), null, "Alice", "Test",
|
||||||
|
null, "alice@example.com", "APPROVED");
|
||||||
|
UserProfileResponse dto2 = new UserProfileResponse(
|
||||||
|
user2.getId(), null, "Bob", "Test",
|
||||||
|
null, "bob@example.com", "PENDING");
|
||||||
|
|
||||||
|
when(userMapper.mapToDto(List.of(user1, user2))).thenReturn(List.of(dto1, dto2));
|
||||||
|
|
||||||
|
ResponseEntity<List<UserProfileResponse>> result = adminIamController.getAllUsers();
|
||||||
|
|
||||||
|
assertEquals(200, result.getStatusCode().value());
|
||||||
|
assertEquals(2, result.getBody().size());
|
||||||
|
assertEquals("alice@example.com", result.getBody().get(0).email());
|
||||||
|
assertEquals("bob@example.com", result.getBody().get(1).email());
|
||||||
|
verify(adminIamService).getAllUsers();
|
||||||
|
verify(userMapper).mapToDto(List.of(user1, user2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getAllUsers_empty() {
|
||||||
|
when(adminIamService.getAllUsers()).thenReturn(List.of());
|
||||||
|
when(userMapper.mapToDto(List.of())).thenReturn(List.of());
|
||||||
|
|
||||||
|
ResponseEntity<List<UserProfileResponse>> result = adminIamController.getAllUsers();
|
||||||
|
|
||||||
|
assertEquals(200, result.getStatusCode().value());
|
||||||
|
assertTrue(result.getBody().isEmpty());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user