Skip to content

Commit ae8682f

Browse files
committed
Test yanking with cookie
1 parent 2861c8d commit ae8682f

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/tests/krate.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ impl crate::util::MockTokenUser {
7979
}
8080
}
8181

82+
impl crate::util::MockCookieUser {
83+
/// Yank the specified version of the specified crate and run all pending background jobs
84+
fn yank(&self, krate_name: &str, version: &str) -> crate::util::Response<OkBool> {
85+
let url = format!("/api/v1/crates/{}/{}/yank", krate_name, version);
86+
let response = self.delete(&url);
87+
self.app().run_pending_background_jobs();
88+
response
89+
}
90+
91+
/// Unyank the specified version of the specified crate and run all pending background jobs
92+
fn unyank(&self, krate_name: &str, version: &str) -> crate::util::Response<OkBool> {
93+
let url = format!("/api/v1/crates/{}/{}/unyank", krate_name, version);
94+
let response = self.put(&url, &[]);
95+
self.app().run_pending_background_jobs();
96+
response
97+
}
98+
}
99+
82100
#[test]
83101
fn index() {
84102
let (app, anon) = TestApp::init().empty();
@@ -1574,7 +1592,7 @@ fn following() {
15741592

15751593
#[test]
15761594
fn yank_works_as_intended() {
1577-
let (app, anon, _, token) = TestApp::full().with_token();
1595+
let (app, anon, cookie, token) = TestApp::full().with_token();
15781596

15791597
// Upload a new crate, putting it in the git index
15801598
let crate_to_publish = PublishBuilder::new("fyk");
@@ -1608,6 +1626,26 @@ fn yank_works_as_intended() {
16081626

16091627
let json = anon.show_version("fyk", "1.0.0");
16101628
assert!(!json.version.yanked);
1629+
1630+
// yank it
1631+
cookie.yank("fyk", "1.0.0").good();
1632+
1633+
let crates = app.crates_from_index_head("3/f/fyk");
1634+
assert!(crates.len() == 1);
1635+
assert!(crates[0].yanked.unwrap());
1636+
1637+
let json = anon.show_version("fyk", "1.0.0");
1638+
assert!(json.version.yanked);
1639+
1640+
// un-yank it
1641+
cookie.unyank("fyk", "1.0.0").good();
1642+
1643+
let crates = app.crates_from_index_head("3/f/fyk");
1644+
assert!(crates.len() == 1);
1645+
assert!(!crates[0].yanked.unwrap());
1646+
1647+
let json = anon.show_version("fyk", "1.0.0");
1648+
assert!(!json.version.yanked);
16111649
}
16121650

16131651
#[test]

0 commit comments

Comments
 (0)