@@ -1815,6 +1815,7 @@ fn yanked_versions_not_included_in_reverse_dependencies() {
1815
1815
assert_eq ! ( deps. dependencies[ 0 ] . crate_id, "c1" ) ;
1816
1816
1817
1817
// TODO: have this test call `version.yank()` once the yank method is converted to diesel
1818
+
1818
1819
diesel:: update ( versions:: table. filter ( versions:: num. eq ( "2.0.0" ) ) )
1819
1820
. set ( versions:: yanked. eq ( true ) )
1820
1821
. execute ( & * app. diesel_database . get ( ) . unwrap ( ) )
@@ -2108,6 +2109,46 @@ fn test_default_sort_recent() {
2108
2109
assert_eq ! ( json. crates[ 1 ] . downloads, 20 ) ;
2109
2110
}
2110
2111
2112
+ /* Given two crates, one with all versions yanked and another
2113
+ with a good version only the one that doesn't have all versions
2114
+ yanked is returned.
2115
+ */
2116
+ #[ test]
2117
+ fn test_hides_yanked_crate ( ) {
2118
+ let ( _b, app, middle) = :: app ( ) ;
2119
+
2120
+ {
2121
+ let conn = app. diesel_database . get ( ) . unwrap ( ) ;
2122
+ let user = :: new_user ( "Oskar" ) . create_or_update ( & conn) . unwrap ( ) ;
2123
+
2124
+ :: CrateBuilder :: new ( "green_ball" , user. id )
2125
+ . description ( "For fetching" )
2126
+ . downloads ( 0 )
2127
+ . recent_downloads ( 0 )
2128
+ . expect_build ( & conn) ;
2129
+
2130
+ let yanked_crate = :: CrateBuilder :: new ( "fully_yanked" , user. id )
2131
+ . description ( "Not here anymore" )
2132
+ . expect_build ( & conn) ;
2133
+
2134
+ diesel:: update ( versions:: table. filter (
2135
+ versions:: crate_id. eq ( yanked_crate. id ) ,
2136
+ ) ) . set ( versions:: yanked. eq ( true ) )
2137
+ . execute ( & * conn)
2138
+ . unwrap ( ) ;
2139
+ }
2140
+
2141
+ let mut req = :: req ( app, Method :: Get , "/api/v1/crates" ) ;
2142
+ let mut response = ok_resp ! ( middle. call( req. with_query( "sort=recent-downloads" ) ) ) ;
2143
+ let json: CrateList = :: json ( & mut response) ;
2144
+
2145
+ assert_eq ! ( json. meta. total, 1 ) ;
2146
+
2147
+ assert_eq ! ( json. crates[ 0 ] . name, "green_ball" ) ;
2148
+ assert_eq ! ( json. crates[ 0 ] . recent_downloads, Some ( 0 ) ) ;
2149
+ assert_eq ! ( json. crates[ 0 ] . downloads, 0 ) ;
2150
+ }
2151
+
2111
2152
#[ test]
2112
2153
fn block_blacklisted_documentation_url ( ) {
2113
2154
let ( _b, app, middle) = :: app ( ) ;
0 commit comments