|
1 | 1 | extern crate diesel;
|
| 2 | +extern crate conduit; |
2 | 3 |
|
3 | 4 | use std::collections::HashMap;
|
4 | 5 | use std::io::prelude::*;
|
@@ -1853,6 +1854,7 @@ fn yanked_versions_not_included_in_reverse_dependencies() {
|
1853 | 1854 | assert_eq!(deps.dependencies[0].crate_id, "c1");
|
1854 | 1855 |
|
1855 | 1856 | // TODO: have this test call `version.yank()` once the yank method is converted to diesel
|
| 1857 | + |
1856 | 1858 | diesel::update(versions::table.filter(versions::num.eq("2.0.0")))
|
1857 | 1859 | .set(versions::yanked.eq(true))
|
1858 | 1860 | .execute(&*app.diesel_database.get().unwrap())
|
@@ -2146,6 +2148,117 @@ fn test_default_sort_recent() {
|
2146 | 2148 | assert_eq!(json.crates[1].downloads, 20);
|
2147 | 2149 | }
|
2148 | 2150 |
|
| 2151 | +/* Given two crates, one with all versions yanked and another |
| 2152 | + with a good version only the one that doesn't have all versions |
| 2153 | + yanked is returned if a user_id or team_id is provided. |
| 2154 | + */ |
| 2155 | +#[test] |
| 2156 | +fn test_hides_yanked_crate() { |
| 2157 | + let (_b, app, middle) = ::app(); |
| 2158 | + |
| 2159 | + let (user, team) = { |
| 2160 | + let conn = app.diesel_database.get().unwrap(); |
| 2161 | + let user = ::new_user("Oskar").create_or_update(&conn).unwrap(); |
| 2162 | + let team = ::new_team("github:test_org:team_sloth") |
| 2163 | + .create_or_update(&conn) |
| 2164 | + .unwrap(); |
| 2165 | + |
| 2166 | + let green_ball = ::CrateBuilder::new("green_ball", user.id) |
| 2167 | + .description("For fetching") |
| 2168 | + .downloads(0) |
| 2169 | + .recent_downloads(0) |
| 2170 | + .expect_build(&conn); |
| 2171 | + |
| 2172 | + ::add_team_to_crate(&team, &green_ball, &user, &conn).unwrap(); |
| 2173 | + |
| 2174 | + let yanked_crate = ::CrateBuilder::new("fully_yanked", user.id) |
| 2175 | + .description("Not here anymore") |
| 2176 | + .expect_build(&conn); |
| 2177 | + |
| 2178 | + ::add_team_to_crate(&team, &yanked_crate, &user, &conn).unwrap(); |
| 2179 | + |
| 2180 | + diesel::update(versions::table.filter( |
| 2181 | + versions::crate_id.eq(yanked_crate.id), |
| 2182 | + )).set(versions::yanked.eq(true)) |
| 2183 | + .execute(&*conn) |
| 2184 | + .unwrap(); |
| 2185 | + |
| 2186 | + (user, team) |
| 2187 | + }; |
| 2188 | + |
| 2189 | + { |
| 2190 | + let mut req = ::req(app.clone(), Method::Get, "/api/v1/crates"); |
| 2191 | + let mut response = ok_resp!(middle.call(req.with_query( |
| 2192 | + format!("sort=recent-downloads&user_id={}", user.id).as_str(), |
| 2193 | + ))); |
| 2194 | + assert_crate_yanked(&mut response); |
| 2195 | + } |
| 2196 | + |
| 2197 | + { |
| 2198 | + let mut req = ::req(app.clone(), Method::Get, "/api/v1/crates"); |
| 2199 | + let mut response = ok_resp!(middle.call(req.with_query( |
| 2200 | + format!("sort=recent-downloads&team_id={}", team.id).as_str(), |
| 2201 | + ))); |
| 2202 | + assert_crate_yanked(&mut response); |
| 2203 | + } |
| 2204 | +} |
| 2205 | + |
| 2206 | +fn assert_crate_yanked(response: &mut conduit::Response) { |
| 2207 | + let json: CrateList = ::json(response); |
| 2208 | + |
| 2209 | + assert_eq!(json.meta.total, 1); |
| 2210 | + |
| 2211 | + assert_eq!(json.crates[0].name, "green_ball"); |
| 2212 | + assert_eq!(json.crates[0].recent_downloads, Some(0)); |
| 2213 | + assert_eq!(json.crates[0].downloads, 0); |
| 2214 | +} |
| 2215 | + |
| 2216 | +/* Given two crates, one with all versions yanked and another |
| 2217 | + with a good version, both crates are returned if there is |
| 2218 | + no user_id or team_id provided. |
| 2219 | + */ |
| 2220 | +#[test] |
| 2221 | +fn test_shows_yanked_crate_without_user_or_team() { |
| 2222 | + let (_b, app, middle) = ::app(); |
| 2223 | + |
| 2224 | + { |
| 2225 | + let conn = app.diesel_database.get().unwrap(); |
| 2226 | + let user = ::new_user("Oskar").create_or_update(&conn).unwrap(); |
| 2227 | + |
| 2228 | + ::CrateBuilder::new("green_ball", user.id) |
| 2229 | + .description("For fetching") |
| 2230 | + .downloads(0) |
| 2231 | + .recent_downloads(0) |
| 2232 | + .expect_build(&conn); |
| 2233 | + |
| 2234 | + let yanked_crate = ::CrateBuilder::new("fully_yanked", user.id) |
| 2235 | + .description("Not here anymore") |
| 2236 | + .expect_build(&conn); |
| 2237 | + |
| 2238 | + diesel::update(versions::table.filter( |
| 2239 | + versions::crate_id.eq(yanked_crate.id), |
| 2240 | + )).set(versions::yanked.eq(true)) |
| 2241 | + .execute(&*conn) |
| 2242 | + .unwrap(); |
| 2243 | + } |
| 2244 | + |
| 2245 | + |
| 2246 | + let mut req = ::req(app.clone(), Method::Get, "/api/v1/crates"); |
| 2247 | + let mut response = ok_resp!(middle.call(req.with_query("sort=recent-downloads"))); |
| 2248 | + |
| 2249 | + let json: CrateList = ::json(&mut response); |
| 2250 | + |
| 2251 | + assert_eq!(json.meta.total, 2); |
| 2252 | + |
| 2253 | + assert_eq!(json.crates[0].name, "green_ball"); |
| 2254 | + assert_eq!(json.crates[0].recent_downloads, Some(0)); |
| 2255 | + assert_eq!(json.crates[0].downloads, 0); |
| 2256 | + |
| 2257 | + assert_eq!(json.crates[1].name, "fully_yanked"); |
| 2258 | + assert_eq!(json.crates[1].recent_downloads, Some(0)); |
| 2259 | + assert_eq!(json.crates[1].downloads, 0); |
| 2260 | +} |
| 2261 | + |
2149 | 2262 | #[test]
|
2150 | 2263 | fn block_blacklisted_documentation_url() {
|
2151 | 2264 | let (_b, app, middle) = ::app();
|
|
0 commit comments