Skip to content

Commit 6194d89

Browse files
committed
tests/routes/crates/owners/remove: Add uppercase test cases
1 parent aea4d4a commit 6194d89

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/tests/routes/crates/owners/remove.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::tests::builders::CrateBuilder;
22
use crate::tests::util::{RequestHelper, TestApp};
3+
use crates_io_github::{GitHubOrganization, GitHubTeam, GitHubTeamMembership, MockGitHubClient};
34
use http::StatusCode;
45
use insta::assert_snapshot;
56

@@ -71,3 +72,73 @@ async fn test_unknown_team() {
7172
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
7273
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"could not find team with login `github:unknown:unknown`"}]}"#);
7374
}
75+
76+
#[tokio::test(flavor = "multi_thread")]
77+
async fn test_remove_uppercase_user() {
78+
let (app, _, cookie) = TestApp::full().with_user();
79+
app.db_new_user("user2");
80+
let mut conn = app.db_conn();
81+
82+
CrateBuilder::new("foo", cookie.as_model().id).expect_build(&mut conn);
83+
84+
let response = cookie.add_named_owner("foo", "user2").await;
85+
assert_eq!(response.status(), StatusCode::OK);
86+
87+
let response = cookie.remove_named_owner("foo", "USER2").await;
88+
assert_eq!(response.status(), StatusCode::OK);
89+
assert_snapshot!(response.text(), @r#"{"msg":"owners successfully removed","ok":true}"#);
90+
}
91+
92+
#[tokio::test(flavor = "multi_thread")]
93+
async fn test_remove_uppercase_team() {
94+
use mockall::predicate::*;
95+
96+
let mut github_mock = MockGitHubClient::new();
97+
98+
github_mock
99+
.expect_team_by_name()
100+
.with(eq("org"), eq("team"), always())
101+
.returning(|_, _, _| {
102+
Ok(GitHubTeam {
103+
id: 2,
104+
name: Some("team".to_string()),
105+
organization: GitHubOrganization {
106+
id: 1,
107+
avatar_url: None,
108+
},
109+
})
110+
});
111+
112+
github_mock
113+
.expect_org_by_name()
114+
.with(eq("org"), always())
115+
.returning(|_, _| {
116+
Ok(GitHubOrganization {
117+
id: 1,
118+
avatar_url: None,
119+
})
120+
});
121+
122+
github_mock
123+
.expect_team_membership()
124+
.with(eq(1), eq(2), eq("foo"), always())
125+
.returning(|_, _, _, _| {
126+
Ok(GitHubTeamMembership {
127+
state: "active".to_string(),
128+
})
129+
});
130+
131+
let (app, _, cookie) = TestApp::full().with_github(github_mock).with_user();
132+
let mut conn = app.db_conn();
133+
134+
CrateBuilder::new("crate42", cookie.as_model().id).expect_build(&mut conn);
135+
136+
let response = cookie.add_named_owner("crate42", "github:org:team").await;
137+
assert_eq!(response.status(), StatusCode::OK);
138+
139+
let response = cookie
140+
.remove_named_owner("crate42", "github:ORG:TEAM")
141+
.await;
142+
assert_eq!(response.status(), StatusCode::OK);
143+
assert_snapshot!(response.text(), @r#"{"msg":"owners successfully removed","ok":true}"#);
144+
}

0 commit comments

Comments
 (0)