Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
fmt; clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
thesuzerain committed Dec 4, 2023
1 parent 40ef0f5 commit d9d82f4
Show file tree
Hide file tree
Showing 25 changed files with 637 additions and 285 deletions.
8 changes: 4 additions & 4 deletions src/routes/v2/versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::models::projects::{Dependency, FileType, Version, VersionStatus, Vers
use crate::models::v2::projects::LegacyVersion;
use crate::queue::session::AuthQueue;
use crate::routes::{v2_reroute, v3};
use actix_web::{delete, get, patch, web, HttpRequest, HttpResponse, post};
use actix_web::{delete, get, patch, post, web, HttpRequest, HttpResponse};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
Expand Down Expand Up @@ -275,8 +275,8 @@ pub async fn version_delete(

#[derive(Deserialize)]
pub struct SchedulingData {
pub time : DateTime<Utc>,
pub requested_status : VersionStatus,
pub time: DateTime<Utc>,
pub requested_status: VersionStatus,
}

#[post("{id}/schedule")]
Expand All @@ -303,4 +303,4 @@ pub async fn version_schedule(
)
.await
.or_else(v2_reroute::flatten_404_error)
}
}
25 changes: 21 additions & 4 deletions tests/analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,15 @@ pub async fn permissions_analytics_revenue() {
let req_gen = |ctx: PermissionsTestContext| async move {
let project_id = ctx.project_id.unwrap();
let ids_or_slugs = vec![project_id.as_str()];
api.get_analytics_revenue(ids_or_slugs, false, None, None, Some(5), ctx.test_pat.as_deref()).await
api.get_analytics_revenue(
ids_or_slugs,
false,
None,
None,
Some(5),
ctx.test_pat.as_deref(),
)
.await
};

PermissionsTest::new(&test_env)
Expand All @@ -199,9 +207,18 @@ pub async fn permissions_analytics_revenue() {
let req_gen = |ctx: PermissionsTestContext| {
let alpha_version_id = alpha_version_id.clone();
async move {
let ids_or_slugs = vec![alpha_version_id.as_str()];
api.get_analytics_revenue(ids_or_slugs, true, None, None, Some(5), ctx.test_pat.as_deref()).await
}};
let ids_or_slugs = vec![alpha_version_id.as_str()];
api.get_analytics_revenue(
ids_or_slugs,
true,
None,
None,
Some(5),
ctx.test_pat.as_deref(),
)
.await
}
};

PermissionsTest::new(&test_env)
.with_failure_codes(vec![200, 401])
Expand Down
2 changes: 1 addition & 1 deletion tests/common/api_common/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::common::{api_v2::ApiV2, api_v3::ApiV3, dummy_data::TestFile};

use super::{
models::{CommonProject, CommonVersion},
request_data::{ProjectCreationRequestData, ImageData},
request_data::{ImageData, ProjectCreationRequestData},
Api, ApiProject, ApiTags, ApiTeams, ApiVersion,
};

Expand Down
57 changes: 41 additions & 16 deletions tests/common/api_common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::HashMap;

use self::models::{
CommonCategoryData, CommonLoaderData, CommonNotification, CommonProject,
CommonTeamMember, CommonVersion,
CommonCategoryData, CommonLoaderData, CommonNotification, CommonProject, CommonTeamMember,
CommonVersion,
};
use self::request_data::{ProjectCreationRequestData, ImageData};
use self::request_data::{ImageData, ProjectCreationRequestData};
use actix_web::dev::ServiceResponse;
use async_trait::async_trait;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -54,8 +54,16 @@ pub trait ApiProject {

async fn remove_project(&self, id_or_slug: &str, pat: Option<&str>) -> ServiceResponse;
async fn get_project(&self, id_or_slug: &str, pat: Option<&str>) -> ServiceResponse;
async fn get_project_deserialized_common(&self, id_or_slug: &str, pat: Option<&str>) -> CommonProject;
async fn get_user_projects(&self, user_id_or_username: &str, pat: Option<&str>) -> ServiceResponse;
async fn get_project_deserialized_common(
&self,
id_or_slug: &str,
pat: Option<&str>,
) -> CommonProject;
async fn get_user_projects(
&self,
user_id_or_username: &str,
pat: Option<&str>,
) -> ServiceResponse;
async fn get_user_projects_deserialized_common(
&self,
user_id_or_username: &str,
Expand Down Expand Up @@ -86,6 +94,7 @@ pub trait ApiProject {
date: DateTime<Utc>,
pat: Option<&str>,
) -> ServiceResponse;
#[allow(clippy::too_many_arguments)]
async fn add_gallery_item(
&self,
id_or_slug: &str,
Expand Down Expand Up @@ -133,14 +142,23 @@ pub trait ApiTeams {
id_or_slug: &str,
pat: Option<&str>,
) -> Vec<CommonTeamMember>;
async fn get_organization_members(&self, id_or_title: &str, pat: Option<&str>) -> ServiceResponse;
async fn get_organization_members(
&self,
id_or_title: &str,
pat: Option<&str>,
) -> ServiceResponse;
async fn get_organization_members_deserialized_common(
&self,
id_or_title: &str,
pat: Option<&str>,
) -> Vec<CommonTeamMember>;
async fn join_team(&self, team_id: &str, pat: Option<&str>) -> ServiceResponse;
async fn remove_from_team(&self, team_id: &str, user_id: &str, pat: Option<&str>) -> ServiceResponse;
async fn remove_from_team(
&self,
team_id: &str,
user_id: &str,
pat: Option<&str>,
) -> ServiceResponse;
async fn edit_team_member(
&self,
team_id: &str,
Expand All @@ -160,7 +178,11 @@ pub trait ApiTeams {
user_id: &str,
pat: Option<&str>,
) -> Vec<CommonNotification>;
async fn mark_notification_read(&self, notification_id: &str, pat: Option<&str>) -> ServiceResponse;
async fn mark_notification_read(
&self,
notification_id: &str,
pat: Option<&str>,
) -> ServiceResponse;
async fn add_user_to_team(
&self,
team_id: &str,
Expand All @@ -169,7 +191,11 @@ pub trait ApiTeams {
organization_permissions: Option<OrganizationPermissions>,
pat: Option<&str>,
) -> ServiceResponse;
async fn delete_notification(&self, notification_id: &str, pat: Option<&str>) -> ServiceResponse;
async fn delete_notification(
&self,
notification_id: &str,
pat: Option<&str>,
) -> ServiceResponse;
}

#[async_trait(?Send)]
Expand All @@ -193,7 +219,11 @@ pub trait ApiVersion {
pat: Option<&str>,
) -> CommonVersion;
async fn get_version(&self, id_or_slug: &str, pat: Option<&str>) -> ServiceResponse;
async fn get_version_deserialized_common(&self, id_or_slug: &str, pat: Option<&str>) -> CommonVersion;
async fn get_version_deserialized_common(
&self,
id_or_slug: &str,
pat: Option<&str>,
) -> CommonVersion;
async fn get_versions(&self, ids_or_slugs: Vec<String>, pat: Option<&str>) -> ServiceResponse;
async fn get_versions_deserialized_common(
&self,
Expand Down Expand Up @@ -303,14 +333,9 @@ pub trait ApiVersion {
pat: Option<&str>,
) -> ServiceResponse;
async fn remove_version(&self, id_or_slug: &str, pat: Option<&str>) -> ServiceResponse;
async fn remove_version_file(
&self,
hash: &str,
pat: Option<&str>,
) -> ServiceResponse;
async fn remove_version_file(&self, hash: &str, pat: Option<&str>) -> ServiceResponse;
}


pub trait AppendsOptionalPat {
fn append_pat(self, pat: Option<&str>) -> Self;
}
Expand Down
53 changes: 35 additions & 18 deletions tests/common/api_v2/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use crate::common::{
api_common::{
models::{CommonProject, CommonVersion},
request_data::{ProjectCreationRequestData, ImageData},
request_data::{ImageData, ProjectCreationRequestData},
Api, ApiProject, AppendsOptionalPat,
},
dummy_data::TestFile,
Expand All @@ -30,7 +30,11 @@ use super::{
};

impl ApiV2 {
pub async fn get_project_deserialized(&self, id_or_slug: &str, pat: Option<&str>) -> LegacyProject {
pub async fn get_project_deserialized(
&self,
id_or_slug: &str,
pat: Option<&str>,
) -> LegacyProject {
let resp = self.get_project(id_or_slug, pat).await;
assert_eq!(resp.status(), 200);
test::read_body_json(resp).await
Expand Down Expand Up @@ -143,8 +147,8 @@ impl ApiProject for ApiV2 {
.uri(&format!("/v2/project/{project_slug_or_id}"))
.append_pat(pat)
.to_request();
let resp = self.call(req).await;
resp

self.call(req).await
}

async fn get_project(&self, id_or_slug: &str, pat: Option<&str>) -> ServiceResponse {
Expand All @@ -155,7 +159,11 @@ impl ApiProject for ApiV2 {
self.call(req).await
}

async fn get_project_deserialized_common(&self, id_or_slug: &str, pat: Option<&str>) -> CommonProject {
async fn get_project_deserialized_common(
&self,
id_or_slug: &str,
pat: Option<&str>,
) -> CommonProject {
let resp = self.get_project(id_or_slug, pat).await;
assert_eq!(resp.status(), 200);
// First, deserialize to the non-common format (to test the response is valid for this api version)
Expand All @@ -165,7 +173,11 @@ impl ApiProject for ApiV2 {
serde_json::from_value(value).unwrap()
}

async fn get_user_projects(&self, user_id_or_username: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_user_projects(
&self,
user_id_or_username: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::get()
.uri(&format!("/v2/user/{}/projects", user_id_or_username))
.append_pat(pat)
Expand Down Expand Up @@ -261,20 +273,21 @@ impl ApiProject for ApiV2 {
date: DateTime<Utc>,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::post()
.uri(&format!("/v2/version/{id_or_slug}/schedule"))
.set_json(json!(
{
"requested_status": requested_status,
"time": date,
}
))
.append_pat(pat)
let req = test::TestRequest::post()
.uri(&format!("/v2/version/{id_or_slug}/schedule"))
.set_json(json!(
{
"requested_status": requested_status,
"time": date,
}
))
.append_pat(pat)
.to_request();

self.call(req).await
}

#[allow(clippy::too_many_arguments)]
async fn add_gallery_item(
&self,
id_or_slug: &str,
Expand Down Expand Up @@ -320,9 +333,13 @@ impl ApiProject for ApiV2 {
"/v2/project/{id_or_slug}/gallery?url={image_url}",
image_url = urlencoding::encode(image_url)
);

for (key, value) in patch {
url.push_str(&format!("&{key}={value}", key = key, value = urlencoding::encode(&value)));
url.push_str(&format!(
"&{key}={value}",
key = key,
value = urlencoding::encode(&value)
));
}

let req = test::TestRequest::patch()
Expand All @@ -331,7 +348,7 @@ impl ApiProject for ApiV2 {
.to_request();
self.call(req).await
}

async fn remove_gallery_item(
&self,
id_or_slug: &str,
Expand Down
2 changes: 1 addition & 1 deletion tests/common/api_v2/request_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ pub fn get_public_creation_data_multipart(
} else {
vec![json_segment]
}
}
}
25 changes: 21 additions & 4 deletions tests/common/api_v2/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ impl ApiTeams for ApiV2 {
test::read_body_json(resp).await
}

async fn get_organization_members(&self, id_or_title: &str, pat: Option<&str>) -> ServiceResponse {
async fn get_organization_members(
&self,
id_or_title: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::get()
.uri(&format!("/v2/organization/{id_or_title}/members"))
.append_pat(pat)
Expand Down Expand Up @@ -122,7 +126,12 @@ impl ApiTeams for ApiV2 {
self.call(req).await
}

async fn remove_from_team(&self, team_id: &str, user_id: &str, pat: Option<&str>) -> ServiceResponse {
async fn remove_from_team(
&self,
team_id: &str,
user_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::delete()
.uri(&format!("/v2/team/{team_id}/members/{user_id}"))
.append_pat(pat)
Expand Down Expand Up @@ -183,7 +192,11 @@ impl ApiTeams for ApiV2 {
serde_json::from_value(value).unwrap()
}

async fn mark_notification_read(&self, notification_id: &str, pat: Option<&str>) -> ServiceResponse {
async fn mark_notification_read(
&self,
notification_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::patch()
.uri(&format!("/v2/notification/{notification_id}"))
.append_pat(pat)
Expand Down Expand Up @@ -211,7 +224,11 @@ impl ApiTeams for ApiV2 {
self.call(req).await
}

async fn delete_notification(&self, notification_id: &str, pat: Option<&str>) -> ServiceResponse {
async fn delete_notification(
&self,
notification_id: &str,
pat: Option<&str>,
) -> ServiceResponse {
let req = test::TestRequest::delete()
.uri(&format!("/v2/notification/{notification_id}"))
.append_pat(pat)
Expand Down
Loading

0 comments on commit d9d82f4

Please sign in to comment.