@@ -91,12 +91,22 @@ async fn test_choose_endpoint_with_valid_request() {
9191
9292 // Verificamos que el bot ha puesto una ficha (hay una celda vacía menos)
9393 let body = response. into_body ( ) . collect ( ) . await . unwrap ( ) . to_bytes ( ) ;
94- let play_response: PlayResponse = serde_json:: from_slice ( & body) . expect ( "Fallo al parsear PlayResponse" ) ;
95-
96- let celdas_vacias_despues = play_response. position . layout ( ) . chars ( ) . filter ( |c| * c == '.' ) . count ( ) ;
97- assert_eq ! ( celdas_vacias_despues, celdas_vacias_antes - 1 , "El bot debería haber colocado exactamente una ficha" ) ;
94+ let play_response: PlayResponse =
95+ serde_json:: from_slice ( & body) . expect ( "Fallo al parsear PlayResponse" ) ;
96+
97+ let celdas_vacias_despues = play_response
98+ . position
99+ . layout ( )
100+ . chars ( )
101+ . filter ( |c| * c == '.' )
102+ . count ( ) ;
103+ assert_eq ! (
104+ celdas_vacias_despues,
105+ celdas_vacias_antes - 1 ,
106+ "El bot debería haber colocado exactamente una ficha"
107+ ) ;
98108}
99-
109+
100110#[ tokio:: test]
101111async fn test_choose_endpoint_with_partially_filled_board ( ) {
102112 let app = test_app ( ) . await ;
@@ -127,9 +137,18 @@ async fn test_choose_endpoint_with_partially_filled_board() {
127137
128138 let body = response. into_body ( ) . collect ( ) . await . unwrap ( ) . to_bytes ( ) ;
129139 let play_response: PlayResponse = serde_json:: from_slice ( & body) . unwrap ( ) ;
130-
131- let celdas_vacias_despues = play_response. position . layout ( ) . chars ( ) . filter ( |c| * c == '.' ) . count ( ) ;
132- assert_eq ! ( celdas_vacias_despues, celdas_vacias_antes - 1 , "El bot debe elegir una de las celdas vacías restantes" ) ;
140+
141+ let celdas_vacias_despues = play_response
142+ . position
143+ . layout ( )
144+ . chars ( )
145+ . filter ( |c| * c == '.' )
146+ . count ( ) ;
147+ assert_eq ! (
148+ celdas_vacias_despues,
149+ celdas_vacias_antes - 1 ,
150+ "El bot debe elegir una de las celdas vacías restantes"
151+ ) ;
133152}
134153// ============================================================================
135154// Choose endpoint tests - Error cases
@@ -151,7 +170,7 @@ async fn test_choose_endpoint_with_invalid_api_version() {
151170 .oneshot(
152171 Request::builder()
153172 .method("POST")
154- .uri("/v2/play")
173+ .uri("/v2/play")
155174 .header("content-type", "application/json")
156175 .body(Body::from(serde_json::to_string(&payload).unwrap()))
157176 .unwrap(),
@@ -172,7 +191,6 @@ async fn test_choose_endpoint_with_invalid_api_version() {
172191}
173192 */
174193
175-
176194#[ tokio:: test]
177195async fn test_choose_endpoint_with_unknown_bot ( ) {
178196 let app = test_app ( ) . await ;
@@ -247,15 +265,15 @@ async fn test_choose_endpoint_with_missing_content_type() {
247265
248266 // Missing content-type should return an error
249267 assert ! ( response. status( ) . is_client_error( ) ) ;
250- }
268+ }
251269// ============================================================================
252270// Custom state tests
253271// ============================================================================
254272#[ tokio:: test]
255273async fn test_choose_with_custom_bot_registry ( ) {
256274 // 1. Setup: Registro que SOLO tiene el RandomBot
257275 let bots = YBotRegistry :: new ( ) . with_bot ( Arc :: new ( RandomBot ) ) ;
258- let db = get_test_db ( ) . await ;
276+ let db = get_test_db ( ) . await ;
259277 let state = AppState :: new ( bots, db) ;
260278 let app = test_app_with_state ( state) ;
261279
@@ -362,7 +380,7 @@ async fn test_get_on_play_endpoint_returns_method_not_allowed() {
362380 . oneshot (
363381 Request :: builder ( )
364382 . method ( "GET" ) // El endpoint /api/play solo acepta POST
365- . uri ( "/api/play" )
383+ . uri ( "/api/play" )
366384 . body ( Body :: empty ( ) )
367385 . unwrap ( ) ,
368386 )
@@ -372,7 +390,6 @@ async fn test_get_on_play_endpoint_returns_method_not_allowed() {
372390 // Ahora sí estamos testeando que el método GET está bloqueado en una ruta real
373391 assert_eq ! ( response. status( ) , StatusCode :: METHOD_NOT_ALLOWED ) ;
374392}
375- * /
376393
377394// ============================================================================
378395// Board size edge cases
@@ -686,11 +703,9 @@ async fn test_status_endpoint_multiple_requests() {
686703 let body = response. into_body ( ) . collect ( ) . await . unwrap ( ) . to_bytes ( ) ;
687704 assert_eq ! ( & body[ ..] , b"OK" ) ;
688705 }
689-
690706}
691-
692707
693- // ============================================================================
708+ // ============================================================================
694709// NUEVOS TESTS: Historial y Rendición
695710// ============================================================================
696711
@@ -716,7 +731,7 @@ async fn test_history_endpoint_filters_correctly() {
716731 // Verificamos que devuelve el JSON con la estructura paginada esperada
717732 let body = response. into_body ( ) . collect ( ) . await . unwrap ( ) . to_bytes ( ) ;
718733 let json: serde_json:: Value = serde_json:: from_slice ( & body) . unwrap ( ) ;
719-
734+
720735 assert ! ( json. get( "data" ) . is_some( ) ) ;
721736 assert ! ( json. get( "page" ) . is_some( ) ) ;
722737 assert ! ( json. get( "total_pages" ) . is_some( ) ) ;
@@ -747,4 +762,4 @@ async fn test_surrender_endpoint_saves_defeat() {
747762
748763 // Verificamos que el registro se guardó correctamente en MongoDB
749764 assert_eq ! ( response. status( ) , StatusCode :: OK ) ;
750- }
765+ }
0 commit comments