File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,3 +95,45 @@ impl ValidationErrorType {
9595 }
9696 }
9797}
98+
99+ #[ cfg( test) ]
100+ mod tests {
101+ use super :: * ;
102+ use serde_json;
103+
104+ #[ test]
105+ fn test_serialize_validation_error_info ( ) {
106+ let error_info = ValidationErrorInfo {
107+ error_type : ValidationErrorType :: HttpError ,
108+ status_code : 400 ,
109+ message : "Invalid token" . to_string ( ) ,
110+ } ;
111+
112+ let expected = serde_json:: json!( {
113+ "type" : "HttpError" ,
114+ "statusCode" : 400 ,
115+ "message" : "Invalid token"
116+ } ) ;
117+
118+ let actual = serde_json:: to_value ( & error_info) . unwrap ( ) ;
119+ assert_eq ! ( actual, expected) ;
120+ }
121+
122+ #[ test]
123+ fn test_deserialize_validation_error_info ( ) {
124+ let json = serde_json:: json!( {
125+ "type" : "HttpError" ,
126+ "statusCode" : 401 ,
127+ "message" : "Unauthorized access"
128+ } ) ;
129+
130+ let expected = ValidationErrorInfo {
131+ error_type : ValidationErrorType :: HttpError ,
132+ status_code : 401 ,
133+ message : "Unauthorized access" . to_string ( ) ,
134+ } ;
135+
136+ let actual: ValidationErrorInfo = serde_json:: from_value ( json) . unwrap ( ) ;
137+ assert_eq ! ( actual, expected) ;
138+ }
139+ }
You can’t perform that action at this time.
0 commit comments