Skip to content

Commit d16e61e

Browse files
committed
Add regression test for #1205
1 parent efe5438 commit d16e61e

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

src/tests/issues/issue1205.rs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
use crate::tests::builders::CrateBuilder;
2+
use crate::tests::util::TestApp;
3+
use crates_io_github::{GitHubOrganization, GitHubTeam, GitHubTeamMembership, MockGitHubClient};
4+
use http::StatusCode;
5+
use insta::assert_snapshot;
6+
7+
const CRATE_NAME: &str = "deepspeech-sys";
8+
9+
/// See <https://github.com/rust-lang/crates.io/issues/1205>.
10+
#[tokio::test(flavor = "multi_thread")]
11+
async fn test_issue_1205_remove() -> anyhow::Result<()> {
12+
let (app, _, _, user) = TestApp::full().with_github(github_mock()).with_token();
13+
14+
let mut conn = app.db_conn();
15+
16+
let krate = CrateBuilder::new(CRATE_NAME, user.as_model().id).expect_build(&mut conn);
17+
18+
let response = user
19+
.add_named_owner(CRATE_NAME, "github:rustaudio:owners")
20+
.await;
21+
assert_eq!(response.status(), StatusCode::OK);
22+
assert_snapshot!(response.text(), @r#"{"msg":"team github:rustaudio:owners has been added as an owner of crate deepspeech-sys","ok":true}"#);
23+
24+
let owners = krate.owners(&mut conn)?;
25+
assert_eq!(owners.len(), 2);
26+
assert_eq!(owners[0].login(), "foo");
27+
assert_eq!(owners[1].login(), "github:rustaudio:owners");
28+
29+
let response = user
30+
.add_named_owner(CRATE_NAME, "github:rustaudio:cratesio-push")
31+
.await;
32+
assert_eq!(response.status(), StatusCode::OK);
33+
assert_snapshot!(response.text(), @r#"{"msg":"team github:rustaudio:cratesio-push has been added as an owner of crate deepspeech-sys","ok":true}"#);
34+
35+
let owners = krate.owners(&mut conn)?;
36+
assert_eq!(owners.len(), 2);
37+
assert_eq!(owners[0].login(), "foo");
38+
assert_eq!(owners[1].login(), "github:rustaudio:cratesio-push");
39+
40+
let response = user
41+
.remove_named_owner(CRATE_NAME, "github:rustaudio:owners")
42+
.await;
43+
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
44+
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"could not find team with login `github:rustaudio:owners`"}]}"#);
45+
46+
Ok(())
47+
}
48+
49+
fn github_mock() -> MockGitHubClient {
50+
use mockall::predicate::*;
51+
52+
let mut github_mock = MockGitHubClient::new();
53+
54+
github_mock
55+
.expect_org_by_name()
56+
.with(eq("rustaudio"), always())
57+
.returning(|_, _| Ok(org()));
58+
59+
github_mock
60+
.expect_team_by_name()
61+
.with(eq("rustaudio"), eq("owners"), always())
62+
.returning(|_, name, _| Ok(team(name)));
63+
64+
github_mock
65+
.expect_team_by_name()
66+
.with(eq("rustaudio"), eq("cratesio-push"), always())
67+
.returning(|_, name, _| Ok(team(name)));
68+
69+
github_mock
70+
.expect_team_membership()
71+
.with(eq(1), eq(2), eq("foo"), always())
72+
.returning(|_, _, _, _| Ok(active_membership()));
73+
74+
github_mock
75+
}
76+
77+
fn org() -> GitHubOrganization {
78+
GitHubOrganization {
79+
id: 1,
80+
avatar_url: None,
81+
}
82+
}
83+
84+
fn team(name: &str) -> GitHubTeam {
85+
GitHubTeam {
86+
id: 2,
87+
name: Some(name.to_string()),
88+
organization: org(),
89+
}
90+
}
91+
92+
fn active_membership() -> GitHubTeamMembership {
93+
let state = "active".to_string();
94+
GitHubTeamMembership { state }
95+
}

src/tests/issues/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod issue1205;

src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mod categories;
1919
mod cors;
2020
mod dump_db;
2121
mod github_secret_scanning;
22+
mod issues;
2223
mod krate;
2324
mod middleware;
2425
mod not_found_error;

0 commit comments

Comments
 (0)