|
| 1 | +use crate::models::{CrateOwner, OwnerKind}; |
1 | 2 | use crate::tests::builders::CrateBuilder;
|
2 | 3 | use crate::tests::util::{RequestHelper, TestApp};
|
| 4 | +use crates_io_database::schema::crate_owners; |
| 5 | +use crates_io_github::{GitHubOrganization, GitHubTeam, GitHubTeamMembership, MockGitHubClient}; |
3 | 6 | use http::StatusCode;
|
4 | 7 | use insta::assert_snapshot;
|
5 | 8 |
|
@@ -71,3 +74,83 @@ async fn test_unknown_team() {
|
71 | 74 | assert_eq!(response.status(), StatusCode::BAD_REQUEST);
|
72 | 75 | assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"could not find team with login `github:unknown:unknown`"}]}"#);
|
73 | 76 | }
|
| 77 | + |
| 78 | +#[tokio::test(flavor = "multi_thread")] |
| 79 | +async fn test_remove_uppercase_user() { |
| 80 | + use diesel::RunQueryDsl; |
| 81 | + |
| 82 | + let (app, _, cookie) = TestApp::full().with_user(); |
| 83 | + let user2 = app.db_new_user("user2"); |
| 84 | + let mut conn = app.db_conn(); |
| 85 | + |
| 86 | + let krate = CrateBuilder::new("foo", cookie.as_model().id).expect_build(&mut conn); |
| 87 | + |
| 88 | + diesel::insert_into(crate_owners::table) |
| 89 | + .values(CrateOwner { |
| 90 | + crate_id: krate.id, |
| 91 | + owner_id: user2.as_model().id, |
| 92 | + created_by: cookie.as_model().id, |
| 93 | + owner_kind: OwnerKind::User, |
| 94 | + email_notifications: true, |
| 95 | + }) |
| 96 | + .execute(&mut conn) |
| 97 | + .unwrap(); |
| 98 | + |
| 99 | + let response = cookie.remove_named_owner("foo", "USER2").await; |
| 100 | + assert_eq!(response.status(), StatusCode::OK); |
| 101 | + assert_snapshot!(response.text(), @r#"{"msg":"owners successfully removed","ok":true}"#); |
| 102 | +} |
| 103 | + |
| 104 | +#[tokio::test(flavor = "multi_thread")] |
| 105 | +async fn test_remove_uppercase_team() { |
| 106 | + use mockall::predicate::*; |
| 107 | + |
| 108 | + let mut github_mock = MockGitHubClient::new(); |
| 109 | + |
| 110 | + github_mock |
| 111 | + .expect_team_by_name() |
| 112 | + .with(eq("org"), eq("team"), always()) |
| 113 | + .returning(|_, _, _| { |
| 114 | + Ok(GitHubTeam { |
| 115 | + id: 2, |
| 116 | + name: Some("team".to_string()), |
| 117 | + organization: GitHubOrganization { |
| 118 | + id: 1, |
| 119 | + avatar_url: None, |
| 120 | + }, |
| 121 | + }) |
| 122 | + }); |
| 123 | + |
| 124 | + github_mock |
| 125 | + .expect_org_by_name() |
| 126 | + .with(eq("org"), always()) |
| 127 | + .returning(|_, _| { |
| 128 | + Ok(GitHubOrganization { |
| 129 | + id: 1, |
| 130 | + avatar_url: None, |
| 131 | + }) |
| 132 | + }); |
| 133 | + |
| 134 | + github_mock |
| 135 | + .expect_team_membership() |
| 136 | + .with(eq(1), eq(2), eq("foo"), always()) |
| 137 | + .returning(|_, _, _, _| { |
| 138 | + Ok(GitHubTeamMembership { |
| 139 | + state: "active".to_string(), |
| 140 | + }) |
| 141 | + }); |
| 142 | + |
| 143 | + let (app, _, cookie) = TestApp::full().with_github(github_mock).with_user(); |
| 144 | + let mut conn = app.db_conn(); |
| 145 | + |
| 146 | + CrateBuilder::new("crate42", cookie.as_model().id).expect_build(&mut conn); |
| 147 | + |
| 148 | + let response = cookie.add_named_owner("crate42", "github:org:team").await; |
| 149 | + assert_eq!(response.status(), StatusCode::OK); |
| 150 | + |
| 151 | + let response = cookie |
| 152 | + .remove_named_owner("crate42", "github:ORG:TEAM") |
| 153 | + .await; |
| 154 | + assert_eq!(response.status(), StatusCode::OK); |
| 155 | + assert_snapshot!(response.text(), @r#"{"msg":"owners successfully removed","ok":true}"#); |
| 156 | +} |
0 commit comments