@@ -1831,3 +1831,40 @@ async fn test_multipart_error_malformed_body_stream() {
18311831 "Expected InvalidRequestBody Display output, got: {body}"
18321832 ) ;
18331833}
1834+
1835+ #[ tokio:: test]
1836+ async fn test_missing_required_field ( ) {
1837+ // Send only "name" but omit required "age" → MissingField error from post-loop check
1838+ let server = TestServer :: new ( create_coverage_test_app ( ) ) ;
1839+
1840+ let form = MultipartForm :: new ( ) . add_text ( "name" , "Alice" ) ;
1841+ let response = server. post ( "/strict-test" ) . multipart ( form) . await ;
1842+
1843+ response. assert_status ( axum:: http:: StatusCode :: BAD_REQUEST ) ;
1844+ let body = response. text ( ) ;
1845+ assert ! (
1846+ body. contains( "Missing field" ) ,
1847+ "Expected MissingField error, got: {body}"
1848+ ) ;
1849+ assert ! (
1850+ body. contains( "age" ) ,
1851+ "Should name the missing field 'age', got: {body}"
1852+ ) ;
1853+ }
1854+
1855+ #[ tokio:: test]
1856+ async fn test_missing_multiple_required_fields ( ) {
1857+ // Send only "name" to numeric-char-test which requires name, count, score, initial.
1858+ // Non-strict endpoint: the unmatched fields simply stay None → MissingField in post-loop.
1859+ let server = TestServer :: new ( create_coverage_test_app ( ) ) ;
1860+
1861+ let form = MultipartForm :: new ( ) . add_text ( "name" , "Alice" ) ;
1862+ let response = server. post ( "/numeric-char-test" ) . multipart ( form) . await ;
1863+
1864+ response. assert_status ( axum:: http:: StatusCode :: BAD_REQUEST ) ;
1865+ let body = response. text ( ) ;
1866+ assert ! (
1867+ body. contains( "Missing field" ) ,
1868+ "Expected MissingField error, got: {body}"
1869+ ) ;
1870+ }
0 commit comments