Skip to content

Commit 4249672

Browse files
committed
tests: Move PUT /crates/:name/owners tests to krate::owners module
1 parent aef0830 commit 4249672

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

src/tests/krate/mod.rs

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use diesel::{dsl::*, prelude::*, update};
1010
mod dependencies;
1111
mod downloads;
1212
mod following;
13+
mod owners;
1314
mod publish;
1415
mod reverse_dependencies;
1516
mod show;
@@ -652,48 +653,6 @@ fn test_default_sort_recent() {
652653
assert_eq!(json.crates[1].downloads, 20);
653654
}
654655

655-
// This is testing Cargo functionality! ! !
656-
// specifically functions modify_owners and add_owners
657-
// which call the `PUT /crates/:crate_id/owners` route
658-
#[test]
659-
fn test_cargo_invite_owners() {
660-
let (app, _, owner) = TestApp::init().with_user();
661-
662-
let new_user = app.db_new_user("cilantro");
663-
app.db(|conn| {
664-
CrateBuilder::new("guacamole", owner.as_model().id).expect_build(conn);
665-
});
666-
667-
#[derive(Serialize)]
668-
struct OwnerReq {
669-
owners: Option<Vec<String>>,
670-
}
671-
#[derive(Deserialize, Debug)]
672-
struct OwnerResp {
673-
// server must include `ok: true` to support old cargo clients
674-
ok: bool,
675-
msg: String,
676-
}
677-
678-
let body = serde_json::to_string(&OwnerReq {
679-
owners: Some(vec![new_user.as_model().gh_login.clone()]),
680-
});
681-
let json: OwnerResp = owner
682-
.put("/api/v1/crates/guacamole/owners", body.unwrap().as_bytes())
683-
.good();
684-
685-
// this ok:true field is what old versions of Cargo
686-
// need - do not remove unless you're cool with
687-
// dropping support for old versions
688-
assert!(json.ok);
689-
// msg field is what is sent and used in updated
690-
// version of cargo
691-
assert_eq!(
692-
json.msg,
693-
"user cilantro has been invited to be an owner of crate guacamole"
694-
)
695-
}
696-
697656
#[test]
698657
fn pagination_links_included_if_applicable() {
699658
let (app, anon, user) = TestApp::init().with_user();

src/tests/krate/owners.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use crate::builders::CrateBuilder;
2+
use crate::util::{RequestHelper, TestApp};
3+
4+
// This is testing Cargo functionality! ! !
5+
// specifically functions modify_owners and add_owners
6+
// which call the `PUT /crates/:crate_id/owners` route
7+
#[test]
8+
fn test_cargo_invite_owners() {
9+
let (app, _, owner) = TestApp::init().with_user();
10+
11+
let new_user = app.db_new_user("cilantro");
12+
app.db(|conn| {
13+
CrateBuilder::new("guacamole", owner.as_model().id).expect_build(conn);
14+
});
15+
16+
#[derive(Serialize)]
17+
struct OwnerReq {
18+
owners: Option<Vec<String>>,
19+
}
20+
#[derive(Deserialize, Debug)]
21+
struct OwnerResp {
22+
// server must include `ok: true` to support old cargo clients
23+
ok: bool,
24+
msg: String,
25+
}
26+
27+
let body = serde_json::to_string(&OwnerReq {
28+
owners: Some(vec![new_user.as_model().gh_login.clone()]),
29+
});
30+
let json: OwnerResp = owner
31+
.put("/api/v1/crates/guacamole/owners", body.unwrap().as_bytes())
32+
.good();
33+
34+
// this ok:true field is what old versions of Cargo
35+
// need - do not remove unless you're cool with
36+
// dropping support for old versions
37+
assert!(json.ok);
38+
// msg field is what is sent and used in updated
39+
// version of cargo
40+
assert_eq!(
41+
json.msg,
42+
"user cilantro has been invited to be an owner of crate guacamole"
43+
)
44+
}

0 commit comments

Comments
 (0)