Fix clippy errors + lint, use turbo CI

This commit is contained in:
Jai A
2024-10-18 16:07:35 -07:00
parent 663ab83b08
commit 8dd955563e
186 changed files with 10615 additions and 6433 deletions

View File

@@ -34,7 +34,11 @@ impl ApiV3 {
self.call(req).await
}
pub async fn get_collection(&self, id: &str, pat: Option<&str>) -> ServiceResponse {
pub async fn get_collection(
&self,
id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = TestRequest::get()
.uri(&format!("/v3/collection/{id}"))
.append_pat(pat)
@@ -42,13 +46,21 @@ impl ApiV3 {
self.call(req).await
}
pub async fn get_collection_deserialized(&self, id: &str, pat: Option<&str>) -> Collection {
pub async fn get_collection_deserialized(
&self,
id: &str,
pat: Option<&str>,
) -> Collection {
let resp = self.get_collection(id, pat).await;
assert_status!(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
pub async fn get_collections(&self, ids: &[&str], pat: Option<&str>) -> ServiceResponse {
pub async fn get_collections(
&self,
ids: &[&str],
pat: Option<&str>,
) -> ServiceResponse {
let ids = serde_json::to_string(ids).unwrap();
let req = test::TestRequest::get()
.uri(&format!(
@@ -60,7 +72,11 @@ impl ApiV3 {
self.call(req).await
}
pub async fn get_collection_projects(&self, id: &str, pat: Option<&str>) -> ServiceResponse {
pub async fn get_collection_projects(
&self,
id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::get()
.uri(&format!("/v3/collection/{id}/projects"))
.append_pat(pat)
@@ -122,7 +138,11 @@ impl ApiV3 {
}
}
pub async fn delete_collection(&self, id: &str, pat: Option<&str>) -> ServiceResponse {
pub async fn delete_collection(
&self,
id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::delete()
.uri(&format!("/v3/collection/{id}"))
.append_pat(pat)

View File

@@ -28,8 +28,11 @@ pub struct ApiV3 {
#[async_trait(?Send)]
impl ApiBuildable for ApiV3 {
async fn build(labrinth_config: LabrinthConfig) -> Self {
let app = App::new().configure(|cfg| labrinth::app_config(cfg, labrinth_config.clone()));
let test_app: Rc<dyn LocalService> = Rc::new(test::init_service(app).await);
let app = App::new().configure(|cfg| {
labrinth::app_config(cfg, labrinth_config.clone())
});
let test_app: Rc<dyn LocalService> =
Rc::new(test::init_service(app).await);
Self { test_app }
}

View File

@@ -6,7 +6,8 @@ use actix_web::{
test::{self, TestRequest},
};
use labrinth::auth::oauth::{
OAuthClientAccessRequest, RespondToOAuthClientScopes, TokenRequest, TokenResponse,
OAuthClientAccessRequest, RespondToOAuthClientScopes, TokenRequest,
TokenResponse,
};
use reqwest::header::{AUTHORIZATION, LOCATION};
@@ -32,7 +33,8 @@ impl ApiV3 {
.await;
let flow_id = get_authorize_accept_flow_id(auth_resp).await;
let redirect_resp = self.oauth_accept(&flow_id, user_pat).await;
let auth_code = get_auth_code_from_redirect_params(&redirect_resp).await;
let auth_code =
get_auth_code_from_redirect_params(&redirect_resp).await;
let token_resp = self
.oauth_token(auth_code, None, client_id.to_string(), client_secret)
.await;
@@ -52,7 +54,11 @@ impl ApiV3 {
self.call(req).await
}
pub async fn oauth_accept(&self, flow: &str, pat: Option<&str>) -> ServiceResponse {
pub async fn oauth_accept(
&self,
flow: &str,
pat: Option<&str>,
) -> ServiceResponse {
self.call(
TestRequest::post()
.uri("/_internal/oauth/accept")
@@ -65,7 +71,11 @@ impl ApiV3 {
.await
}
pub async fn oauth_reject(&self, flow: &str, pat: Option<&str>) -> ServiceResponse {
pub async fn oauth_reject(
&self,
flow: &str,
pat: Option<&str>,
) -> ServiceResponse {
self.call(
TestRequest::post()
.uri("/_internal/oauth/reject")
@@ -93,7 +103,11 @@ impl ApiV3 {
grant_type: "authorization_code".to_string(),
code: auth_code,
redirect_uri: original_redirect_uri,
client_id: serde_json::from_str(&format!("\"{}\"", client_id)).unwrap(),
client_id: serde_json::from_str(&format!(
"\"{}\"",
client_id
))
.unwrap(),
})
.to_request(),
)
@@ -123,7 +137,9 @@ pub async fn get_authorize_accept_flow_id(response: ServiceResponse) -> String {
.flow_id
}
pub async fn get_auth_code_from_redirect_params(response: &ServiceResponse) -> String {
pub async fn get_auth_code_from_redirect_params(
response: &ServiceResponse,
) -> String {
assert_status!(response, StatusCode::OK);
let query_params = get_redirect_location_query_params(response);
query_params.get("code").unwrap().to_string()

View File

@@ -56,7 +56,11 @@ impl ApiV3 {
test::read_body_json(resp).await
}
pub async fn get_oauth_client(&self, client_id: String, pat: Option<&str>) -> ServiceResponse {
pub async fn get_oauth_client(
&self,
client_id: String,
pat: Option<&str>,
) -> ServiceResponse {
let req = TestRequest::get()
.uri(&format!("/_internal/oauth/app/{}", client_id))
.append_pat(pat)
@@ -83,7 +87,11 @@ impl ApiV3 {
self.call(req).await
}
pub async fn delete_oauth_client(&self, client_id: &str, pat: Option<&str>) -> ServiceResponse {
pub async fn delete_oauth_client(
&self,
client_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = TestRequest::delete()
.uri(&format!("/_internal/oauth/app/{}", client_id))
.append_pat(pat)

View File

@@ -4,7 +4,9 @@ use actix_web::{
test::{self, TestRequest},
};
use bytes::Bytes;
use labrinth::models::{organizations::Organization, users::UserId, v3::projects::Project};
use labrinth::models::{
organizations::Organization, users::UserId, v3::projects::Project,
};
use serde_json::json;
use crate::{
@@ -34,7 +36,11 @@ impl ApiV3 {
self.call(req).await
}
pub async fn get_organization(&self, id_or_title: &str, pat: Option<&str>) -> ServiceResponse {
pub async fn get_organization(
&self,
id_or_title: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = TestRequest::get()
.uri(&format!("/v3/organization/{id_or_title}"))
.append_pat(pat)

View File

@@ -43,7 +43,8 @@ impl ApiProject for ApiV3 {
modify_json: Option<json_patch::Patch>,
pat: Option<&str>,
) -> (CommonProject, Vec<CommonVersion>) {
let creation_data = get_public_project_creation_data(slug, version_jar, modify_json);
let creation_data =
get_public_project_creation_data(slug, version_jar, modify_json);
// Add a project.
let slug = creation_data.slug.clone();
@@ -98,7 +99,11 @@ impl ApiProject for ApiV3 {
self.call(req).await
}
async fn remove_project(&self, project_slug_or_id: &str, pat: Option<&str>) -> ServiceResponse {
async fn remove_project(
&self,
project_slug_or_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::delete()
.uri(&format!("/v3/project/{project_slug_or_id}"))
.append_pat(pat)
@@ -107,7 +112,11 @@ impl ApiProject for ApiV3 {
self.call(req).await
}
async fn get_project(&self, id_or_slug: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_project(
&self,
id_or_slug: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = TestRequest::get()
.uri(&format!("/v3/project/{id_or_slug}"))
.append_pat(pat)
@@ -129,7 +138,11 @@ impl ApiProject for ApiV3 {
serde_json::from_value(value).unwrap()
}
async fn get_projects(&self, ids_or_slugs: &[&str], pat: Option<&str>) -> ServiceResponse {
async fn get_projects(
&self,
ids_or_slugs: &[&str],
pat: Option<&str>,
) -> ServiceResponse {
let ids_or_slugs = serde_json::to_string(ids_or_slugs).unwrap();
let req = test::TestRequest::get()
.uri(&format!(
@@ -279,7 +292,11 @@ impl ApiProject for ApiV3 {
self.call(req).await
}
async fn get_reports(&self, ids: &[&str], pat: Option<&str>) -> ServiceResponse {
async fn get_reports(
&self,
ids: &[&str],
pat: Option<&str>,
) -> ServiceResponse {
let ids_str = serde_json::to_string(ids).unwrap();
let req = test::TestRequest::get()
.uri(&format!(
@@ -316,7 +333,11 @@ impl ApiProject for ApiV3 {
self.call(req).await
}
async fn delete_report(&self, id: &str, pat: Option<&str>) -> ServiceResponse {
async fn delete_report(
&self,
id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::delete()
.uri(&format!("/v3/report/{id}"))
.append_pat(pat)
@@ -414,7 +435,11 @@ impl ApiProject for ApiV3 {
self.call(req).await
}
async fn get_threads(&self, ids: &[&str], pat: Option<&str>) -> ServiceResponse {
async fn get_threads(
&self,
ids: &[&str],
pat: Option<&str>,
) -> ServiceResponse {
let ids_str = serde_json::to_string(ids).unwrap();
let req = test::TestRequest::get()
.uri(&format!(
@@ -457,7 +482,11 @@ impl ApiProject for ApiV3 {
self.call(req).await
}
async fn read_thread(&self, id: &str, pat: Option<&str>) -> ServiceResponse {
async fn read_thread(
&self,
id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::post()
.uri(&format!("/v3/thread/{id}/read"))
.append_pat(pat)
@@ -466,7 +495,11 @@ impl ApiProject for ApiV3 {
self.call(req).await
}
async fn delete_thread_message(&self, id: &str, pat: Option<&str>) -> ServiceResponse {
async fn delete_thread_message(
&self,
id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::delete()
.uri(&format!("/v3/message/{id}"))
.append_pat(pat)
@@ -477,7 +510,11 @@ impl ApiProject for ApiV3 {
}
impl ApiV3 {
pub async fn get_project_deserialized(&self, id_or_slug: &str, pat: Option<&str>) -> Project {
pub async fn get_project_deserialized(
&self,
id_or_slug: &str,
pat: Option<&str>,
) -> Project {
let resp = self.get_project(id_or_slug, pat).await;
assert_status!(&resp, StatusCode::OK);
test::read_body_json(resp).await
@@ -543,11 +580,13 @@ impl ApiV3 {
pat: Option<&str>,
) -> ServiceResponse {
let pv_string = if ids_are_version_ids {
let version_string: String = serde_json::to_string(&id_or_slugs).unwrap();
let version_string: String =
serde_json::to_string(&id_or_slugs).unwrap();
let version_string = urlencoding::encode(&version_string);
format!("version_ids={}", version_string)
} else {
let projects_string: String = serde_json::to_string(&id_or_slugs).unwrap();
let projects_string: String =
serde_json::to_string(&id_or_slugs).unwrap();
let projects_string = urlencoding::encode(&projects_string);
format!("project_ids={}", projects_string)
};
@@ -566,7 +605,10 @@ impl ApiV3 {
extra_args.push_str(&format!("&end_date={end_date}"));
}
if let Some(resolution_minutes) = resolution_minutes {
extra_args.push_str(&format!("&resolution_minutes={}", resolution_minutes));
extra_args.push_str(&format!(
"&resolution_minutes={}",
resolution_minutes
));
}
let req = test::TestRequest::get()

View File

@@ -2,7 +2,9 @@
use serde_json::json;
use crate::common::{
api_common::request_data::{ProjectCreationRequestData, VersionCreationRequestData},
api_common::request_data::{
ProjectCreationRequestData, VersionCreationRequestData,
},
dummy_data::TestFile,
};
use labrinth::{
@@ -15,11 +17,13 @@ pub fn get_public_project_creation_data(
version_jar: Option<TestFile>,
modify_json: Option<json_patch::Patch>,
) -> ProjectCreationRequestData {
let mut json_data = get_public_project_creation_data_json(slug, version_jar.as_ref());
let mut json_data =
get_public_project_creation_data_json(slug, version_jar.as_ref());
if let Some(modify_json) = modify_json {
json_patch::patch(&mut json_data, &modify_json).unwrap();
}
let multipart_data = get_public_creation_data_multipart(&json_data, version_jar.as_ref());
let multipart_data =
get_public_creation_data_multipart(&json_data, version_jar.as_ref());
ProjectCreationRequestData {
slug: slug.to_string(),
jar: version_jar,
@@ -36,14 +40,18 @@ pub fn get_public_version_creation_data(
// and modifies it before it is serialized and sent
modify_json: Option<json_patch::Patch>,
) -> VersionCreationRequestData {
let mut json_data =
get_public_version_creation_data_json(version_number, ordering, &version_jar);
let mut json_data = get_public_version_creation_data_json(
version_number,
ordering,
&version_jar,
);
json_data["project_id"] = json!(project_id);
if let Some(modify_json) = modify_json {
json_patch::patch(&mut json_data, &modify_json).unwrap();
}
let multipart_data = get_public_creation_data_multipart(&json_data, Some(&version_jar));
let multipart_data =
get_public_creation_data_multipart(&json_data, Some(&version_jar));
VersionCreationRequestData {
version: version_number.to_string(),
jar: Some(version_jar),
@@ -116,7 +124,9 @@ pub fn get_public_creation_data_multipart(
name: "data".to_string(),
filename: None,
content_type: Some("application/json".to_string()),
data: MultipartSegmentData::Text(serde_json::to_string(json_data).unwrap()),
data: MultipartSegmentData::Text(
serde_json::to_string(json_data).unwrap(),
),
};
if let Some(jar) = version_jar {

View File

@@ -6,7 +6,8 @@ use actix_web::{
use async_trait::async_trait;
use labrinth::routes::v3::tags::{GameData, LoaderData};
use labrinth::{
database::models::loader_fields::LoaderFieldEnumValue, routes::v3::tags::CategoryData,
database::models::loader_fields::LoaderFieldEnumValue,
routes::v3::tags::CategoryData,
};
use crate::{
@@ -50,7 +51,9 @@ impl ApiTags for ApiV3 {
self.call(req).await
}
async fn get_categories_deserialized_common(&self) -> Vec<CommonCategoryData> {
async fn get_categories_deserialized_common(
&self,
) -> Vec<CommonCategoryData> {
let resp = self.get_categories().await;
assert_status!(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
@@ -68,7 +71,10 @@ impl ApiV3 {
test::read_body_json(resp).await
}
pub async fn get_loader_field_variants(&self, loader_field: &str) -> ServiceResponse {
pub async fn get_loader_field_variants(
&self,
loader_field: &str,
) -> ServiceResponse {
let req = TestRequest::get()
.uri(&format!("/v3/loader_field?loader_field={}", loader_field))
.append_pat(ADMIN_USER_PAT)

View File

@@ -51,7 +51,11 @@ impl ApiV3 {
#[async_trait(?Send)]
impl ApiTeams for ApiV3 {
async fn get_team_members(&self, id_or_title: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_team_members(
&self,
id_or_title: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::get()
.uri(&format!("/v3/team/{id_or_title}/members"))
.append_pat(pat)
@@ -89,7 +93,11 @@ impl ApiTeams for ApiV3 {
self.call(req).await
}
async fn get_project_members(&self, id_or_title: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_project_members(
&self,
id_or_title: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::get()
.uri(&format!("/v3/project/{id_or_title}/members"))
.append_pat(pat)
@@ -137,7 +145,11 @@ impl ApiTeams for ApiV3 {
serde_json::from_value(value).unwrap()
}
async fn join_team(&self, team_id: &str, pat: Option<&str>) -> ServiceResponse {
async fn join_team(
&self,
team_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::post()
.uri(&format!("/v3/team/{team_id}/join"))
.append_pat(pat)
@@ -189,7 +201,11 @@ impl ApiTeams for ApiV3 {
self.call(req).await
}
async fn get_user_notifications(&self, user_id: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_user_notifications(
&self,
user_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::get()
.uri(&format!("/v3/user/{user_id}/notifications"))
.append_pat(pat)
@@ -211,7 +227,11 @@ impl ApiTeams for ApiV3 {
serde_json::from_value(value).unwrap()
}
async fn get_notification(&self, notification_id: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_notification(
&self,
notification_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::get()
.uri(&format!("/v3/notification/{notification_id}"))
.append_pat(pat)

View File

@@ -7,7 +7,11 @@ use super::ApiV3;
#[async_trait(?Send)]
impl ApiUser for ApiV3 {
async fn get_user(&self, user_id_or_username: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_user(
&self,
user_id_or_username: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::get()
.uri(&format!("/v3/user/{}", user_id_or_username))
.append_pat(pat)
@@ -38,7 +42,11 @@ impl ApiUser for ApiV3 {
self.call(req).await
}
async fn delete_user(&self, user_id_or_username: &str, pat: Option<&str>) -> ServiceResponse {
async fn delete_user(
&self,
user_id_or_username: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::delete()
.uri(&format!("/v3/user/{}", user_id_or_username))
.append_pat(pat)

View File

@@ -7,7 +7,9 @@ use super::{
use crate::{
assert_status,
common::{
api_common::{models::CommonVersion, Api, ApiVersion, AppendsOptionalPat},
api_common::{
models::CommonVersion, Api, ApiVersion, AppendsOptionalPat,
},
dummy_data::TestFile,
},
};
@@ -60,7 +62,11 @@ impl ApiV3 {
test::read_body_json(version).await
}
pub async fn get_version_deserialized(&self, id: &str, pat: Option<&str>) -> Version {
pub async fn get_version_deserialized(
&self,
id: &str,
pat: Option<&str>,
) -> Version {
let resp = self.get_version(id, pat).await;
assert_status!(&resp, StatusCode::OK);
test::read_body_json(resp).await
@@ -160,7 +166,11 @@ impl ApiVersion for ApiV3 {
serde_json::from_value(value).unwrap()
}
async fn get_version(&self, id: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_version(
&self,
id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = TestRequest::get()
.uri(&format!("/v3/version/{id}"))
.append_pat(pat)
@@ -168,7 +178,11 @@ impl ApiVersion for ApiV3 {
self.call(req).await
}
async fn get_version_deserialized_common(&self, id: &str, pat: Option<&str>) -> CommonVersion {
async fn get_version_deserialized_common(
&self,
id: &str,
pat: Option<&str>,
) -> CommonVersion {
let resp = self.get_version(id, pat).await;
assert_status!(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
@@ -288,7 +302,8 @@ impl ApiVersion for ApiV3 {
});
}
if let Some(version_types) = version_types {
json["version_types"] = serde_json::to_value(version_types).unwrap();
json["version_types"] =
serde_json::to_value(version_types).unwrap();
}
let req = test::TestRequest::post()
@@ -311,7 +326,14 @@ impl ApiVersion for ApiV3 {
pat: Option<&str>,
) -> CommonVersion {
let resp = self
.get_update_from_hash(hash, algorithm, loaders, game_versions, version_types, pat)
.get_update_from_hash(
hash,
algorithm,
loaders,
game_versions,
version_types,
pat,
)
.await;
assert_status!(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
@@ -338,10 +360,12 @@ impl ApiVersion for ApiV3 {
json["loaders"] = serde_json::to_value(loaders).unwrap();
}
if let Some(game_versions) = game_versions {
json["game_versions"] = serde_json::to_value(game_versions).unwrap();
json["game_versions"] =
serde_json::to_value(game_versions).unwrap();
}
if let Some(version_types) = version_types {
json["version_types"] = serde_json::to_value(version_types).unwrap();
json["version_types"] =
serde_json::to_value(version_types).unwrap();
}
let req = test::TestRequest::post()
@@ -396,7 +420,9 @@ impl ApiVersion for ApiV3 {
if let Some(game_versions) = game_versions {
query_string.push_str(&format!(
"&game_versions={}",
urlencoding::encode(&serde_json::to_string(&game_versions).unwrap())
urlencoding::encode(
&serde_json::to_string(&game_versions).unwrap()
)
));
}
if let Some(loaders) = loaders {
@@ -480,7 +506,11 @@ impl ApiVersion for ApiV3 {
self.call(request).await
}
async fn get_versions(&self, version_ids: Vec<String>, pat: Option<&str>) -> ServiceResponse {
async fn get_versions(
&self,
version_ids: Vec<String>,
pat: Option<&str>,
) -> ServiceResponse {
let ids = url_encode_json_serialized_vec(&version_ids);
let request = test::TestRequest::get()
.uri(&format!("/v3/versions?ids={}", ids))
@@ -526,7 +556,11 @@ impl ApiVersion for ApiV3 {
self.call(request).await
}
async fn remove_version(&self, version_id: &str, pat: Option<&str>) -> ServiceResponse {
async fn remove_version(
&self,
version_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let request = test::TestRequest::delete()
.uri(&format!(
"/v3/version/{version_id}",
@@ -537,7 +571,11 @@ impl ApiVersion for ApiV3 {
self.call(request).await
}
async fn remove_version_file(&self, hash: &str, pat: Option<&str>) -> ServiceResponse {
async fn remove_version_file(
&self,
hash: &str,
pat: Option<&str>,
) -> ServiceResponse {
let request = test::TestRequest::delete()
.uri(&format!("/v3/version_file/{hash}"))
.append_pat(pat)