Skip to content

Commit 7f64742

Browse files
authored
Fix remove_nonexistent_team() test (#10576)
This test was supposed to check what happens when a user removes a team owner that no longer exists on GitHub. But the test never added the team as a crate owner in the first place, which resulted in it not actually testing the relevant removal process. This commit fixes the issue by adding the corresponding row in the `crate_owners` database table.
1 parent 45f8cd7 commit 7f64742

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/tests/team.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::models::{Crate, NewTeam};
2-
use crate::schema::teams;
1+
use crate::models::{Crate, CrateOwner, NewTeam};
32
use crate::tests::builders::{CrateBuilder, PublishBuilder};
43
use crate::tests::{add_team_to_crate, new_team, OwnerTeamsResponse, RequestHelper, TestApp};
54

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

287-
CrateBuilder::new("foo_remove_nonexistent", user.as_model().id)
286+
let krate = CrateBuilder::new("foo_remove_nonexistent", user.as_model().id)
288287
.expect_build(&mut conn)
289288
.await;
290-
insert_into(teams::table)
291-
.values((
292-
teams::login.eq("github:test-org:this-does-not-exist"),
293-
teams::github_id.eq(5678),
294-
))
295-
.execute(&mut conn)
289+
290+
let team = NewTeam::builder()
291+
.login("github:test-org:this-does-not-exist")
292+
.github_id(5678)
293+
.org_id(1234)
294+
.build()
295+
.create_or_update(&mut conn)
296296
.await
297297
.expect("couldn't insert nonexistent team");
298298

299+
CrateOwner::builder()
300+
.crate_id(krate.id)
301+
.team_id(team.id)
302+
.created_by(user.as_model().id)
303+
.build()
304+
.insert(&mut conn)
305+
.await
306+
.unwrap();
307+
299308
let response = token
300309
.remove_named_owner(
301310
"foo_remove_nonexistent",
302311
"github:test-org:this-does-not-exist",
303312
)
304313
.await;
305-
assert_eq!(response.status(), StatusCode::BAD_REQUEST);
306-
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"could not find owner with login `github:test-org:this-does-not-exist`"}]}"#);
314+
assert_eq!(response.status(), StatusCode::OK);
315+
assert_snapshot!(response.text(), @r#"{"msg":"owners successfully removed","ok":true}"#);
307316
}
308317

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

0 commit comments

Comments
 (0)