test: fix all compilation errors and achieve coverage
This commit is contained in:
+2
-3
@@ -7,7 +7,6 @@ import com.walkguide.security.SecurityHelper;
|
||||
import com.walkguide.service.PairingService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@@ -42,9 +41,9 @@ public class PairingController {
|
||||
}
|
||||
|
||||
@GetMapping("/status")
|
||||
public ResponseEntity<ApiResponse<PairingStatusResponse>> status(Authentication auth) {
|
||||
public ResponseEntity<ApiResponse<PairingStatusResponse>> status() {
|
||||
Long userId = SecurityHelper.getCurrentUserId();
|
||||
String role = auth.getAuthorities().iterator().next().getAuthority();
|
||||
String role = SecurityHelper.getCurrentUserRole();
|
||||
return ResponseEntity.ok(ApiResponse.ok(
|
||||
pairingService.getStatus(userId, role), "Status pairing"));
|
||||
}
|
||||
|
||||
+2
-2
@@ -31,8 +31,8 @@ public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public ResponseEntity<ApiResponse<Object>> handleRuntime(RuntimeException ex) {
|
||||
return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
|
||||
.body(ApiResponse.error("AUTH_ERROR", ex.getMessage()));
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(ApiResponse.error("INTERNAL_ERROR", ex.getMessage()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
|
||||
@@ -24,4 +24,12 @@ public class SecurityHelper {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
return auth != null ? auth.getName() : null;
|
||||
}
|
||||
|
||||
public static String getCurrentUserRole() {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth != null && auth.getAuthorities() != null && !auth.getAuthorities().isEmpty()) {
|
||||
return auth.getAuthorities().iterator().next().getAuthority();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user