@@ -4,11 +4,13 @@ use std::collections::HashMap;
4
4
use std:: io:: prelude:: * ;
5
5
use std:: fs:: { self , File } ;
6
6
7
+ use chrono:: Utc ;
7
8
use conduit:: { Handler , Method } ;
8
- use git2 ;
9
+ use diesel :: update ;
9
10
use self :: diesel:: prelude:: * ;
10
- use serde_json ;
11
+ use git2 ;
11
12
use semver;
13
+ use serde_json;
12
14
13
15
use cargo_registry:: dependency:: EncodableDependency ;
14
16
use cargo_registry:: download:: EncodableVersionDownload ;
@@ -17,7 +19,7 @@ use cargo_registry::keyword::EncodableKeyword;
17
19
use cargo_registry:: krate:: { Crate , EncodableCrate , MAX_NAME_LENGTH } ;
18
20
19
21
use cargo_registry:: token:: ApiToken ;
20
- use cargo_registry:: schema:: { crates, versions} ;
22
+ use cargo_registry:: schema:: { crates, metadata , versions} ;
21
23
22
24
use cargo_registry:: upload as u;
23
25
use cargo_registry:: version:: EncodableVersion ;
@@ -82,7 +84,6 @@ fn new_crate(name: &str) -> u::NewCrate {
82
84
}
83
85
}
84
86
85
-
86
87
#[ test]
87
88
fn index ( ) {
88
89
let ( _b, app, middle) = :: app ( ) ;
@@ -1000,6 +1001,7 @@ fn summary_new_crates() {
1000
1001
let u;
1001
1002
let krate;
1002
1003
let krate2;
1004
+ let krate3;
1003
1005
{
1004
1006
let conn = app. diesel_database . get ( ) . unwrap ( ) ;
1005
1007
u = :: new_user ( "foo" ) . create_or_update ( & conn) . unwrap ( ) ;
@@ -1019,36 +1021,51 @@ fn summary_new_crates() {
1019
1021
. recent_downloads ( 50 )
1020
1022
. expect_build ( & conn) ;
1021
1023
1024
+ krate3 = :: CrateBuilder :: new ( "just_updated" , u. id )
1025
+ . version ( :: VersionBuilder :: new ( "0.1.0" ) )
1026
+ . expect_build ( & conn) ;
1027
+
1022
1028
:: CrateBuilder :: new ( "with_downloads" , u. id )
1023
1029
. version ( :: VersionBuilder :: new ( "0.3.0" ) )
1024
1030
. keyword ( "popular" )
1025
1031
. downloads ( 1000 )
1026
1032
. expect_build ( & conn) ;
1027
- :: CrateBuilder :: new ( "just_updated" , u. id )
1028
- . version ( :: VersionBuilder :: new ( "0.4.0" ) )
1029
- . expect_build ( & conn) ;
1030
1033
1031
1034
:: new_category ( "Category 1" , "cat1" )
1032
1035
. create_or_update ( & conn)
1033
1036
. unwrap ( ) ;
1034
1037
Category :: update_crate ( & conn, & krate, & [ "cat1" ] ) . unwrap ( ) ;
1035
1038
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 ( ) ;
1036
1052
}
1037
1053
1038
1054
let mut req = :: req ( app. clone ( ) , Method :: Get , "/api/v1/summary" ) ;
1039
1055
let mut response = ok_resp ! ( middle. call( & mut req) ) ;
1040
1056
let json: SummaryResponse = :: json ( & mut response) ;
1041
1057
1042
1058
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 ) ;
1044
1060
assert_eq ! ( json. most_downloaded[ 0 ] . name, "most_recent_downloads" ) ;
1045
1061
assert_eq ! (
1046
1062
json. most_recently_downloaded[ 0 ] . name,
1047
1063
"most_recent_downloads"
1048
1064
) ;
1049
1065
assert_eq ! ( json. popular_keywords[ 0 ] . keyword, "popular" ) ;
1050
1066
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" ) ;
1052
1069
assert_eq ! ( json. new_crates. len( ) , 4 ) ;
1053
1070
}
1054
1071
0 commit comments