Skip to content

Commit 24ecfa8

Browse files
committed
tests/util: Move add/remove_owner() fns into RequestHelper trait
1 parent 9e7c0ce commit 24ecfa8

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/tests/issues/issue1205.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::tests::builders::CrateBuilder;
2-
use crate::tests::util::TestApp;
2+
use crate::tests::util::{RequestHelper, TestApp};
33
use crates_io_github::{GitHubOrganization, GitHubTeam, GitHubTeamMembership, MockGitHubClient};
44
use http::StatusCode;
55
use insta::assert_snapshot;

src/tests/util.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,33 @@ pub trait RequestHelper {
221221
let url = "/api/v1/categories";
222222
self.get(url).await.good()
223223
}
224+
225+
/// Add to the specified crate the specified owners.
226+
async fn add_named_owners<T>(&self, krate_name: &str, owners: &[T]) -> Response<OkBool>
227+
where
228+
T: serde::Serialize,
229+
{
230+
let url = format!("/api/v1/crates/{krate_name}/owners");
231+
let body = json!({ "owners": owners }).to_string();
232+
self.put(&url, body).await
233+
}
234+
235+
/// Add a single owner to the specified crate.
236+
async fn add_named_owner(&self, krate_name: &str, owner: &str) -> Response<OkBool> {
237+
self.add_named_owners(krate_name, &[owner]).await
238+
}
239+
240+
/// Remove from the specified crate the specified owners.
241+
async fn remove_named_owners(&self, krate_name: &str, owners: &[&str]) -> Response<OkBool> {
242+
let url = format!("/api/v1/crates/{krate_name}/owners");
243+
let body = json!({ "owners": owners }).to_string();
244+
self.delete_with_body(&url, body).await
245+
}
246+
247+
/// Remove a single owner to the specified crate.
248+
async fn remove_named_owner(&self, krate_name: &str, owner: &str) -> Response<OkBool> {
249+
self.remove_named_owners(krate_name, &[owner]).await
250+
}
224251
}
225252

226253
fn req(method: Method, path: &str) -> MockRequest {
@@ -345,31 +372,4 @@ impl MockTokenUser {
345372
pub fn plaintext(&self) -> &PlainToken {
346373
&self.token.plaintext
347374
}
348-
349-
/// Add to the specified crate the specified owners.
350-
pub async fn add_named_owners<T>(&self, krate_name: &str, owners: &[T]) -> Response<OkBool>
351-
where
352-
T: serde::Serialize,
353-
{
354-
let url = format!("/api/v1/crates/{krate_name}/owners");
355-
let body = json!({ "owners": owners }).to_string();
356-
self.put(&url, body).await
357-
}
358-
359-
/// Add a single owner to the specified crate.
360-
pub async fn add_named_owner(&self, krate_name: &str, owner: &str) -> Response<OkBool> {
361-
self.add_named_owners(krate_name, &[owner]).await
362-
}
363-
364-
/// Remove from the specified crate the specified owners.
365-
pub async fn remove_named_owners(&self, krate_name: &str, owners: &[&str]) -> Response<OkBool> {
366-
let url = format!("/api/v1/crates/{krate_name}/owners");
367-
let body = json!({ "owners": owners }).to_string();
368-
self.delete_with_body(&url, body).await
369-
}
370-
371-
/// Remove a single owner to the specified crate.
372-
pub async fn remove_named_owner(&self, krate_name: &str, owner: &str) -> Response<OkBool> {
373-
self.remove_named_owners(krate_name, &[owner]).await
374-
}
375375
}

0 commit comments

Comments
 (0)