Skip to content

Commit b492daa

Browse files
committed
test_utils: Add helpers module with add_team_to_crate()
1 parent 9072f3c commit b492daa

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crates_io_database::models::{Crate, CrateOwner, Team, User};
2+
use diesel::prelude::*;
3+
use diesel_async::AsyncPgConnection;
4+
5+
pub async fn add_team_to_crate(
6+
t: &Team,
7+
krate: &Crate,
8+
u: &User,
9+
conn: &mut AsyncPgConnection,
10+
) -> QueryResult<()> {
11+
CrateOwner::builder()
12+
.crate_id(krate.id)
13+
.team_id(t.id)
14+
.created_by(u.id)
15+
.build()
16+
.insert(conn)
17+
.await
18+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod builders;
22
pub mod github;
3+
pub mod helpers;

src/tests/mod.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::models::{Crate, CrateOwner, NewCategory, NewTeam, NewUser, Team, User};
1+
use crate::models::{NewCategory, NewTeam, NewUser};
22
use crate::tests::util::{RequestHelper, TestApp};
33
use crate::views::{
44
EncodableCategory, EncodableCrate, EncodableKeyword, EncodableOwner, EncodableVersion,
@@ -7,8 +7,6 @@ use crate::views::{
77

88
use crate::tests::util::github::next_gh_id;
99
use crate::util::gh_token_encryption::GitHubTokenEncryption;
10-
use diesel::prelude::*;
11-
use diesel_async::AsyncPgConnection;
1210
use serde::{Deserialize, Serialize};
1311
use std::sync::LazyLock;
1412

@@ -116,20 +114,7 @@ fn new_team(login: &str) -> NewTeam<'_> {
116114
.build()
117115
}
118116

119-
pub async fn add_team_to_crate(
120-
t: &Team,
121-
krate: &Crate,
122-
u: &User,
123-
conn: &mut AsyncPgConnection,
124-
) -> QueryResult<()> {
125-
CrateOwner::builder()
126-
.crate_id(krate.id)
127-
.team_id(t.id)
128-
.created_by(u.id)
129-
.build()
130-
.insert(conn)
131-
.await
132-
}
117+
pub use crates_io_test_utils::helpers::add_team_to_crate;
133118

134119
fn new_category<'a>(category: &'a str, slug: &'a str, description: &'a str) -> NewCategory<'a> {
135120
NewCategory {

src/typosquat/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ impl From<crate::models::Owner> for Owner {
170170
#[cfg(test)]
171171
mod tests {
172172
use super::*;
173-
use crate::tests::add_team_to_crate;
174173
use crate::typosquat::test_util::faker;
175174
use crates_io_test_db::TestDatabase;
175+
use crates_io_test_utils::helpers::add_team_to_crate;
176176
use thiserror::Error;
177177

178178
#[tokio::test]

0 commit comments

Comments
 (0)