@@ -4,11 +4,13 @@ use std::collections::HashMap;
44use std:: io:: prelude:: * ;
55use std:: fs:: { self , File } ;
66
7+ use chrono:: Utc ;
78use conduit:: { Handler , Method } ;
8- use git2 ;
9+ use diesel :: update ;
910use self :: diesel:: prelude:: * ;
10- use serde_json ;
11+ use git2 ;
1112use semver;
13+ use serde_json;
1214
1315use cargo_registry:: dependency:: EncodableDependency ;
1416use cargo_registry:: download:: EncodableVersionDownload ;
@@ -17,7 +19,7 @@ use cargo_registry::keyword::EncodableKeyword;
1719use cargo_registry:: krate:: { Crate , EncodableCrate , MAX_NAME_LENGTH } ;
1820
1921use cargo_registry:: token:: ApiToken ;
20- use cargo_registry:: schema:: { crates, versions} ;
22+ use cargo_registry:: schema:: { crates, metadata , versions} ;
2123
2224use cargo_registry:: upload as u;
2325use cargo_registry:: version:: EncodableVersion ;
@@ -82,7 +84,6 @@ fn new_crate(name: &str) -> u::NewCrate {
8284 }
8385}
8486
85-
8687#[ test]
8788fn index ( ) {
8889 let ( _b, app, middle) = :: app ( ) ;
@@ -1000,6 +1001,7 @@ fn summary_new_crates() {
10001001 let u;
10011002 let krate;
10021003 let krate2;
1004+ let krate3;
10031005 {
10041006 let conn = app. diesel_database . get ( ) . unwrap ( ) ;
10051007 u = :: new_user ( "foo" ) . create_or_update ( & conn) . unwrap ( ) ;
@@ -1019,36 +1021,51 @@ fn summary_new_crates() {
10191021 . recent_downloads ( 50 )
10201022 . expect_build ( & conn) ;
10211023
1024+ krate3 = :: CrateBuilder :: new ( "just_updated" , u. id )
1025+ . version ( :: VersionBuilder :: new ( "0.1.0" ) )
1026+ . expect_build ( & conn) ;
1027+
10221028 :: CrateBuilder :: new ( "with_downloads" , u. id )
10231029 . version ( :: VersionBuilder :: new ( "0.3.0" ) )
10241030 . keyword ( "popular" )
10251031 . downloads ( 1000 )
10261032 . expect_build ( & conn) ;
1027- :: CrateBuilder :: new ( "just_updated" , u. id )
1028- . version ( :: VersionBuilder :: new ( "0.4.0" ) )
1029- . expect_build ( & conn) ;
10301033
10311034 :: new_category ( "Category 1" , "cat1" )
10321035 . create_or_update ( & conn)
10331036 . unwrap ( ) ;
10341037 Category :: update_crate ( & conn, & krate, & [ "cat1" ] ) . unwrap ( ) ;
10351038 Category :: update_crate ( & conn, & krate2, & [ "cat1" ] ) . unwrap ( ) ;
1039+
1040+ // set total_downloads global value for `num_downloads` prop
1041+ update ( metadata:: table)
1042+ . set ( metadata:: total_downloads. eq ( 6000 ) )
1043+ . execute ( & * conn)
1044+ . unwrap ( ) ;
1045+
1046+ // update 'just_updated' krate. Others won't appear because updated_at == created_at.
1047+ let updated = Utc :: now ( ) . naive_utc ( ) ;
1048+ update ( & krate3)
1049+ . set ( crates:: updated_at. eq ( updated) )
1050+ . execute ( & * conn)
1051+ . unwrap ( ) ;
10361052 }
10371053
10381054 let mut req = :: req ( app. clone ( ) , Method :: Get , "/api/v1/summary" ) ;
10391055 let mut response = ok_resp ! ( middle. call( & mut req) ) ;
10401056 let json: SummaryResponse = :: json ( & mut response) ;
10411057
10421058 assert_eq ! ( json. num_crates, 4 ) ;
1043- assert_eq ! ( json. num_downloads, 0 ) ; // need to add a record to metadata
1059+ assert_eq ! ( json. num_downloads, 6000 ) ;
10441060 assert_eq ! ( json. most_downloaded[ 0 ] . name, "most_recent_downloads" ) ;
10451061 assert_eq ! (
10461062 json. most_recently_downloaded[ 0 ] . name,
10471063 "most_recent_downloads"
10481064 ) ;
10491065 assert_eq ! ( json. popular_keywords[ 0 ] . keyword, "popular" ) ;
10501066 assert_eq ! ( json. popular_categories[ 0 ] . category, "Category 1" ) ;
1051- assert_eq ! ( json. just_updated. len( ) , 0 ) ; // update a couple before running this request...
1067+ assert_eq ! ( json. just_updated. len( ) , 1 ) ;
1068+ assert_eq ! ( json. just_updated[ 0 ] . name, "just_updated" ) ;
10521069 assert_eq ! ( json. new_crates. len( ) , 4 ) ;
10531070}
10541071
0 commit comments