@@ -1853,6 +1853,7 @@ fn yanked_versions_not_included_in_reverse_dependencies() {
1853
1853
assert_eq ! ( deps. dependencies[ 0 ] . crate_id, "c1" ) ;
1854
1854
1855
1855
// TODO: have this test call `version.yank()` once the yank method is converted to diesel
1856
+
1856
1857
diesel:: update ( versions:: table. filter ( versions:: num. eq ( "2.0.0" ) ) )
1857
1858
. set ( versions:: yanked. eq ( true ) )
1858
1859
. execute ( & * app. diesel_database . get ( ) . unwrap ( ) )
@@ -2146,6 +2147,46 @@ fn test_default_sort_recent() {
2146
2147
assert_eq ! ( json. crates[ 1 ] . downloads, 20 ) ;
2147
2148
}
2148
2149
2150
+ /* Given two crates, one with all versions yanked and another
2151
+ with a good version only the one that doesn't have all versions
2152
+ yanked is returned.
2153
+ */
2154
+ #[ test]
2155
+ fn test_hides_yanked_crate ( ) {
2156
+ let ( _b, app, middle) = :: app ( ) ;
2157
+
2158
+ {
2159
+ let conn = app. diesel_database . get ( ) . unwrap ( ) ;
2160
+ let user = :: new_user ( "Oskar" ) . create_or_update ( & conn) . unwrap ( ) ;
2161
+
2162
+ :: CrateBuilder :: new ( "green_ball" , user. id )
2163
+ . description ( "For fetching" )
2164
+ . downloads ( 0 )
2165
+ . recent_downloads ( 0 )
2166
+ . expect_build ( & conn) ;
2167
+
2168
+ let yanked_crate = :: CrateBuilder :: new ( "fully_yanked" , user. id )
2169
+ . description ( "Not here anymore" )
2170
+ . expect_build ( & conn) ;
2171
+
2172
+ diesel:: update ( versions:: table. filter (
2173
+ versions:: crate_id. eq ( yanked_crate. id ) ,
2174
+ ) ) . set ( versions:: yanked. eq ( true ) )
2175
+ . execute ( & * conn)
2176
+ . unwrap ( ) ;
2177
+ }
2178
+
2179
+ let mut req = :: req ( app, Method :: Get , "/api/v1/crates" ) ;
2180
+ let mut response = ok_resp ! ( middle. call( req. with_query( "sort=recent-downloads" ) ) ) ;
2181
+ let json: CrateList = :: json ( & mut response) ;
2182
+
2183
+ assert_eq ! ( json. meta. total, 1 ) ;
2184
+
2185
+ assert_eq ! ( json. crates[ 0 ] . name, "green_ball" ) ;
2186
+ assert_eq ! ( json. crates[ 0 ] . recent_downloads, Some ( 0 ) ) ;
2187
+ assert_eq ! ( json. crates[ 0 ] . downloads, 0 ) ;
2188
+ }
2189
+
2149
2190
#[ test]
2150
2191
fn block_blacklisted_documentation_url ( ) {
2151
2192
let ( _b, app, middle) = :: app ( ) ;
0 commit comments