feat: add test case

This commit is contained in:
Tim
2025-06-30 18:49:46 +08:00
parent 0d3eb99fd2
commit 17d4af229d
4 changed files with 56 additions and 13 deletions

View File

@@ -20,8 +20,19 @@ curl -X POST http://localhost:8080/api/auth/register \
"password": "password"
}'
curl -X POST http://localhost:8080/api/auth/verify \
-H "Content-Type: application/json" \
-d '{
"username": "test_user",
"code": "361332"
}'
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "test_user",
"password": "password"
}'
*/
@RestController
@@ -54,7 +65,7 @@ public class AuthController {
if (user.isPresent()) {
return ResponseEntity.ok(Map.of("token", jwtService.generateToken(user.get().getUsername())));
} else {
return ResponseEntity.badRequest().body(Map.of("error", "\"Invalid credentials or user not verified"));
return ResponseEntity.badRequest().body(Map.of("error", "Invalid credentials or user not verified"));
}
}

View File

@@ -4,12 +4,13 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
/*
curl http://localhost:8080/api/hello \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0ZXN0X3VzZXIiLCJpYXQiOjE3NTEyODAzMjksImV4cCI6MTc1MTM2NjcyOX0.XNDGTQd1H9u3ZOYtnJaU5fL5zhtwyZZm5aX3vL_my1c"
*/
@RestController
public class HelloController {
/**
* curl http://localhost:8080/api/hello \
* -H "Authorization: Bearer <jwt-token>"
*/
@GetMapping("/api/hello")
public Map<String, String> hello() {
return Map.of("message", "Hello, Authenticated User");