|
1 |
| -use crate::builders::{CrateBuilder, PublishBuilder}; |
| 1 | +use crate::builders::PublishBuilder; |
| 2 | +use crate::routes::crates::versions::yank_unyank::YankRequestHelper; |
2 | 3 | use crate::util::{RequestHelper, TestApp};
|
3 |
| -use crate::OkBool; |
4 |
| -use http::StatusCode; |
5 |
| - |
6 |
| -trait YankRequestHelper { |
7 |
| - /// Yank the specified version of the specified crate and run all pending background jobs |
8 |
| - fn yank(&self, krate_name: &str, version: &str) -> crate::util::Response<OkBool>; |
9 |
| - |
10 |
| - /// Unyank the specified version of the specified crate and run all pending background jobs |
11 |
| - fn unyank(&self, krate_name: &str, version: &str) -> crate::util::Response<OkBool>; |
12 |
| -} |
13 |
| - |
14 |
| -impl<T: RequestHelper> YankRequestHelper for T { |
15 |
| - fn yank(&self, krate_name: &str, version: &str) -> crate::util::Response<OkBool> { |
16 |
| - let url = format!("/api/v1/crates/{krate_name}/{version}/yank"); |
17 |
| - let response = self.delete(&url); |
18 |
| - self.app().run_pending_background_jobs(); |
19 |
| - response |
20 |
| - } |
21 |
| - |
22 |
| - fn unyank(&self, krate_name: &str, version: &str) -> crate::util::Response<OkBool> { |
23 |
| - let url = format!("/api/v1/crates/{krate_name}/{version}/unyank"); |
24 |
| - let response = self.put(&url, &[]); |
25 |
| - self.app().run_pending_background_jobs(); |
26 |
| - response |
27 |
| - } |
28 |
| -} |
29 | 4 |
|
30 | 5 | #[test]
|
31 | 6 | #[allow(unknown_lints, clippy::bool_assert_comparison)] // for claim::assert_some_eq! with bool
|
@@ -85,26 +60,6 @@ fn yank_works_as_intended() {
|
85 | 60 | assert!(!json.version.yanked);
|
86 | 61 | }
|
87 | 62 |
|
88 |
| -#[test] |
89 |
| -fn yank_by_a_non_owner_fails() { |
90 |
| - let (app, _, _, token) = TestApp::full().with_token(); |
91 |
| - |
92 |
| - let another_user = app.db_new_user("bar"); |
93 |
| - let another_user = another_user.as_model(); |
94 |
| - app.db(|conn| { |
95 |
| - CrateBuilder::new("foo_not", another_user.id) |
96 |
| - .version("1.0.0") |
97 |
| - .expect_build(conn); |
98 |
| - }); |
99 |
| - |
100 |
| - let response = token.yank("foo_not", "1.0.0"); |
101 |
| - assert_eq!(response.status(), StatusCode::OK); |
102 |
| - assert_eq!( |
103 |
| - response.into_json(), |
104 |
| - json!({ "errors": [{ "detail": "must already be an owner to yank or unyank" }] }) |
105 |
| - ); |
106 |
| -} |
107 |
| - |
108 | 63 | #[test]
|
109 | 64 | fn yank_max_version() {
|
110 | 65 | let (_, anon, _, token) = TestApp::full().with_token();
|
@@ -188,48 +143,3 @@ fn publish_after_yank_max_version() {
|
188 | 143 | let json = anon.show_crate("fyk_max");
|
189 | 144 | assert_eq!(json.krate.max_version, "2.0.0");
|
190 | 145 | }
|
191 |
| - |
192 |
| -#[test] |
193 |
| -fn yank_records_an_audit_action() { |
194 |
| - let (_, anon, _, token) = TestApp::full().with_token(); |
195 |
| - |
196 |
| - // Upload a new crate, putting it in the git index |
197 |
| - let crate_to_publish = PublishBuilder::new("fyk"); |
198 |
| - token.publish_crate(crate_to_publish).good(); |
199 |
| - |
200 |
| - // Yank it |
201 |
| - token.yank("fyk", "1.0.0").good(); |
202 |
| - |
203 |
| - // Make sure it has one publish and one yank audit action |
204 |
| - let json = anon.show_version("fyk", "1.0.0"); |
205 |
| - let actions = json.version.audit_actions; |
206 |
| - |
207 |
| - assert_eq!(actions.len(), 2); |
208 |
| - let action = &actions[1]; |
209 |
| - assert_eq!(action.action, "yank"); |
210 |
| - assert_eq!(action.user.id, token.as_model().user_id); |
211 |
| -} |
212 |
| - |
213 |
| -#[test] |
214 |
| -fn unyank_records_an_audit_action() { |
215 |
| - let (_, anon, _, token) = TestApp::full().with_token(); |
216 |
| - |
217 |
| - // Upload a new crate |
218 |
| - let crate_to_publish = PublishBuilder::new("fyk"); |
219 |
| - token.publish_crate(crate_to_publish).good(); |
220 |
| - |
221 |
| - // Yank version 1.0.0 |
222 |
| - token.yank("fyk", "1.0.0").good(); |
223 |
| - |
224 |
| - // Unyank version 1.0.0 |
225 |
| - token.unyank("fyk", "1.0.0").good(); |
226 |
| - |
227 |
| - // Make sure it has one publish, one yank, and one unyank audit action |
228 |
| - let json = anon.show_version("fyk", "1.0.0"); |
229 |
| - let actions = json.version.audit_actions; |
230 |
| - |
231 |
| - assert_eq!(actions.len(), 3); |
232 |
| - let action = &actions[2]; |
233 |
| - assert_eq!(action.action, "unyank"); |
234 |
| - assert_eq!(action.user.id, token.as_model().user_id); |
235 |
| -} |
0 commit comments