Skip to content

Fix remove_nonexistent_team() test #10576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/tests/team.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::models::{Crate, NewTeam};
use crate::schema::teams;
use crate::models::{Crate, CrateOwner, NewTeam};
use crate::tests::builders::{CrateBuilder, PublishBuilder};
use crate::tests::{add_team_to_crate, new_team, OwnerTeamsResponse, RequestHelper, TestApp};

Expand Down Expand Up @@ -284,26 +283,36 @@ async fn remove_nonexistent_team() {
let (app, _, user, token) = TestApp::init().with_token().await;
let mut conn = app.db_conn().await;

CrateBuilder::new("foo_remove_nonexistent", user.as_model().id)
let krate = CrateBuilder::new("foo_remove_nonexistent", user.as_model().id)
.expect_build(&mut conn)
.await;
insert_into(teams::table)
.values((
teams::login.eq("github:test-org:this-does-not-exist"),
teams::github_id.eq(5678),
))
.execute(&mut conn)

let team = NewTeam::builder()
.login("github:test-org:this-does-not-exist")
.github_id(5678)
.org_id(1234)
.build()
.create_or_update(&mut conn)
.await
.expect("couldn't insert nonexistent team");

CrateOwner::builder()
.crate_id(krate.id)
.team_id(team.id)
.created_by(user.as_model().id)
.build()
.insert(&mut conn)
.await
.unwrap();

let response = token
.remove_named_owner(
"foo_remove_nonexistent",
"github:test-org:this-does-not-exist",
)
.await;
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"could not find owner with login `github:test-org:this-does-not-exist`"}]}"#);
assert_eq!(response.status(), StatusCode::OK);
assert_snapshot!(response.text(), @r#"{"msg":"owners successfully removed","ok":true}"#);
}

/// Test trying to publish a crate we don't own
Expand Down