@@ -42,9 +42,103 @@ pub use krate::EncodableCrate;
4242pub use owner:: { EncodableOwner , EncodableTeam } ;
4343pub use token:: EncodableApiTokenWithToken ;
4444pub use user:: { EncodablePrivateUser , EncodablePublicUser } ;
45- pub use version:: EncodableVersion ;
45+ pub use version:: { EncodableVersion , EncodableVersionLinks } ;
4646
4747// TODO: Prefix many of these with `Encodable` then clean up the reexports
4848pub mod krate_publish;
4949pub use self :: krate_publish:: CrateDependency as EncodableCrateDependency ;
5050pub use self :: krate_publish:: NewCrate as EncodableCrateUpload ;
51+
52+ #[ cfg( test) ]
53+ mod tests {
54+ use std:: collections:: HashMap ;
55+ use super :: * ;
56+ use chrono:: NaiveDate ;
57+ use serde_json;
58+
59+ #[ test]
60+ fn category_dates_serializes_to_rfc3339 ( ) {
61+ let cat = EncodableCategory {
62+ id : "" . to_string ( ) ,
63+ category : "" . to_string ( ) ,
64+ slug : "" . to_string ( ) ,
65+ description : "" . to_string ( ) ,
66+ crates_cnt : 1 ,
67+ created_at : NaiveDate :: from_ymd ( 2017 , 1 , 6 ) . and_hms ( 14 , 23 , 11 ) ,
68+ } ;
69+ let json = serde_json:: to_string ( & cat) . unwrap ( ) ;
70+ assert ! (
71+ json. as_str( )
72+ . find( r#""created_at":"2017-01-06T14:23:11+00:00""# )
73+ . is_some( )
74+ ) ;
75+ }
76+
77+ #[ test]
78+ fn category_with_sub_dates_serializes_to_rfc3339 ( ) {
79+ let cat = EncodableCategoryWithSubcategories {
80+ id : "" . to_string ( ) ,
81+ category : "" . to_string ( ) ,
82+ slug : "" . to_string ( ) ,
83+ description : "" . to_string ( ) ,
84+ crates_cnt : 1 ,
85+ created_at : NaiveDate :: from_ymd ( 2017 , 1 , 6 ) . and_hms ( 14 , 23 , 11 ) ,
86+ subcategories : vec ! [ ] ,
87+ } ;
88+ let json = serde_json:: to_string ( & cat) . unwrap ( ) ;
89+ assert ! (
90+ json. as_str( )
91+ . find( r#""created_at":"2017-01-06T14:23:11+00:00""# )
92+ . is_some( )
93+ ) ;
94+ }
95+
96+ #[ test]
97+ fn keyword_serializes_to_rfc3339 ( ) {
98+ let key = EncodableKeyword {
99+ id : "" . to_string ( ) ,
100+ keyword : "" . to_string ( ) ,
101+ created_at : NaiveDate :: from_ymd ( 2017 , 1 , 6 ) . and_hms ( 14 , 23 , 11 ) ,
102+ crates_cnt : 0 ,
103+ } ;
104+ let json = serde_json:: to_string ( & key) . unwrap ( ) ;
105+ assert ! (
106+ json. as_str( )
107+ . find( r#""created_at":"2017-01-06T14:23:11+00:00""# )
108+ . is_some( )
109+ ) ;
110+ }
111+
112+ #[ test]
113+ fn version_serializes_to_rfc3339 ( ) {
114+ let ver = EncodableVersion {
115+ id : 1 ,
116+ krate : "" . to_string ( ) ,
117+ num : "" . to_string ( ) ,
118+ dl_path : "" . to_string ( ) ,
119+ readme_path : "" . to_string ( ) ,
120+ updated_at : NaiveDate :: from_ymd ( 2017 , 1 , 6 ) . and_hms ( 14 , 23 , 11 ) ,
121+ created_at : NaiveDate :: from_ymd ( 2017 , 1 , 6 ) . and_hms ( 14 , 23 , 12 ) ,
122+ downloads : 0 ,
123+ features : HashMap :: new ( ) ,
124+ yanked : false ,
125+ license : None ,
126+ links : EncodableVersionLinks {
127+ dependencies : "" . to_string ( ) ,
128+ version_downloads : "" . to_string ( ) ,
129+ authors : "" . to_string ( ) ,
130+ } ,
131+ } ;
132+ let json = serde_json:: to_string ( & ver) . unwrap ( ) ;
133+ assert ! (
134+ json. as_str( )
135+ . find( r#""updated_at":"2017-01-06T14:23:11+00:00""# )
136+ . is_some( )
137+ ) ;
138+ assert ! (
139+ json. as_str( )
140+ . find( r#""created_at":"2017-01-06T14:23:12+00:00""# )
141+ . is_some( )
142+ ) ;
143+ }
144+ }
0 commit comments