Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion apps/labrinth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ path = "src/main.rs"
[dependencies]
actix-cors = { workspace = true }
actix-files = { workspace = true }
actix-http = { workspace = true, optional = true }
actix-multipart = { workspace = true }
actix-rt = { workspace = true }
actix-web = { workspace = true }
Expand Down Expand Up @@ -132,7 +133,7 @@ zip = { workspace = true }
zxcvbn = { workspace = true }

[dev-dependencies]
actix-http = { workspace = true }
labrinth = { path = ".", features = ["test"] }

[build-dependencies]
chrono = { workspace = true }
Expand All @@ -147,5 +148,8 @@ tikv-jemallocator = { workspace = true, features = [
"unprefixed_malloc_on_supported_platforms",
] }

[features]
test = ["dep:actix-http"]

[lints]
workspace = true
2 changes: 1 addition & 1 deletion apps/labrinth/src/database/models/notification_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl NotificationBuilder {
Ok(())
}

async fn insert_many_deliveries(
pub async fn insert_many_deliveries(
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
redis: &RedisPool,
notification_ids: &[i64],
Expand Down
4 changes: 3 additions & 1 deletion apps/labrinth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ pub mod routes;
pub mod scheduler;
pub mod search;
pub mod sync;
pub mod test;
pub mod util;
pub mod validate;

#[cfg(feature = "test")]
pub mod test;

#[derive(Clone)]
pub struct Pepper {
pub pepper: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::collections::HashMap;

use crate::common::{api_v2::ApiV2, api_v3::ApiV3, dummy_data::TestFile};
use actix_web::dev::ServiceResponse;
use async_trait::async_trait;
use labrinth::models::ids::ProjectId;
use labrinth::models::{
use crate::models::ids::ProjectId;
use crate::models::{
projects::VersionType,
teams::{OrganizationPermissions, ProjectPermissions},
};
use crate::test::{api_v2::ApiV2, api_v3::ApiV3, dummy_data::TestFile};
use actix_web::dev::ServiceResponse;
use async_trait::async_trait;

use super::{
Api, ApiProject, ApiTags, ApiTeams, ApiUser, ApiVersion,
Expand Down Expand Up @@ -81,7 +81,7 @@ delegate_api_variant!(
[add_gallery_item, ServiceResponse, id_or_slug: &str, image: ImageData, featured: bool, title: Option<String>, description: Option<String>, ordering: Option<i32>, pat: Option<&str>],
[remove_gallery_item, ServiceResponse, id_or_slug: &str, image_url: &str, pat: Option<&str>],
[edit_gallery_item, ServiceResponse, id_or_slug: &str, image_url: &str, patch: HashMap<String, String>, pat: Option<&str>],
[create_report, ServiceResponse, report_type: &str, id: &str, item_type: crate::common::api_common::models::CommonItemType, body: &str, pat: Option<&str>],
[create_report, ServiceResponse, report_type: &str, id: &str, item_type: crate::test::api_common::models::CommonItemType, body: &str, pat: Option<&str>],
[get_report, ServiceResponse, id: &str, pat: Option<&str>],
[get_reports, ServiceResponse, ids: &[&str], pat: Option<&str>],
[get_user_reports, ServiceResponse, pat: Option<&str>],
Expand All @@ -100,28 +100,28 @@ delegate_api_variant!(
#[async_trait(?Send)]
impl ApiTags for GenericApi {
[get_loaders, ServiceResponse,],
[get_loaders_deserialized_common, Vec<crate::common::api_common::models::CommonLoaderData>,],
[get_loaders_deserialized_common, Vec<crate::test::api_common::models::CommonLoaderData>,],
[get_categories, ServiceResponse,],
[get_categories_deserialized_common, Vec<crate::common::api_common::models::CommonCategoryData>,],
[get_categories_deserialized_common, Vec<crate::test::api_common::models::CommonCategoryData>,],
}
);

delegate_api_variant!(
#[async_trait(?Send)]
impl ApiTeams for GenericApi {
[get_team_members, ServiceResponse, team_id: &str, pat: Option<&str>],
[get_team_members_deserialized_common, Vec<crate::common::api_common::models::CommonTeamMember>, team_id: &str, pat: Option<&str>],
[get_team_members_deserialized_common, Vec<crate::test::api_common::models::CommonTeamMember>, team_id: &str, pat: Option<&str>],
[get_teams_members, ServiceResponse, ids: &[&str], pat: Option<&str>],
[get_project_members, ServiceResponse, id_or_slug: &str, pat: Option<&str>],
[get_project_members_deserialized_common, Vec<crate::common::api_common::models::CommonTeamMember>, id_or_slug: &str, pat: Option<&str>],
[get_project_members_deserialized_common, Vec<crate::test::api_common::models::CommonTeamMember>, id_or_slug: &str, pat: Option<&str>],
[get_organization_members, ServiceResponse, id_or_title: &str, pat: Option<&str>],
[get_organization_members_deserialized_common, Vec<crate::common::api_common::models::CommonTeamMember>, id_or_title: &str, pat: Option<&str>],
[get_organization_members_deserialized_common, Vec<crate::test::api_common::models::CommonTeamMember>, id_or_title: &str, pat: Option<&str>],
[join_team, ServiceResponse, team_id: &str, pat: Option<&str>],
[remove_from_team, ServiceResponse, team_id: &str, user_id: &str, pat: Option<&str>],
[edit_team_member, ServiceResponse, team_id: &str, user_id: &str, patch: serde_json::Value, pat: Option<&str>],
[transfer_team_ownership, ServiceResponse, team_id: &str, user_id: &str, pat: Option<&str>],
[get_user_notifications, ServiceResponse, user_id: &str, pat: Option<&str>],
[get_user_notifications_deserialized_common, Vec<crate::common::api_common::models::CommonNotification>, user_id: &str, pat: Option<&str>],
[get_user_notifications_deserialized_common, Vec<crate::test::api_common::models::CommonNotification>, user_id: &str, pat: Option<&str>],
[get_notification, ServiceResponse, notification_id: &str, pat: Option<&str>],
[get_notifications, ServiceResponse, ids: &[&str], pat: Option<&str>],
[mark_notification_read, ServiceResponse, notification_id: &str, pat: Option<&str>],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use self::models::{
};
use self::request_data::{ImageData, ProjectCreationRequestData};
use super::dummy_data::TestFile;
use actix_web::dev::ServiceResponse;
use async_trait::async_trait;
use labrinth::models::ids::ProjectId;
use labrinth::{
use crate::models::ids::ProjectId;
use crate::{
LabrinthConfig,
models::{
projects::VersionType,
teams::{OrganizationPermissions, ProjectPermissions},
},
};
use actix_web::dev::ServiceResponse;
use async_trait::async_trait;

pub mod generic;
pub mod models;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use ariadne::ids::UserId;
use chrono::{DateTime, Utc};
use labrinth::models::ids::{
use crate::models::ids::{
ImageId, NotificationId, OrganizationId, ProjectId, ReportId, TeamId,
ThreadId, ThreadMessageId, VersionId,
};
use labrinth::{
use crate::{
auth::AuthProvider,
models::{
projects::{
Expand All @@ -16,6 +14,8 @@ use labrinth::{
users::{Badges, Role, User, UserPayoutData},
},
};
use ariadne::ids::UserId;
use chrono::{DateTime, Utc};
use rust_decimal::Decimal;
use serde::Deserialize;
// Fields shared by every version of the API.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// The structures for project/version creation.
// These are created differently, but are essentially the same between versions.

use labrinth::util::actix::MultipartSegment;
use crate::util::actix::MultipartSegment;

use crate::common::dummy_data::TestFile;
use crate::test::dummy_data::TestFile;

pub struct ProjectCreationRequestData {
pub slug: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use super::{
api_common::{Api, ApiBuildable},
environment::LocalService,
};
use crate::LabrinthConfig;
use actix_web::{App, dev::ServiceResponse, test};
use async_trait::async_trait;
use labrinth::LabrinthConfig;
use std::rc::Rc;
use utoipa_actix_web::AppExt;

Expand All @@ -26,12 +26,10 @@ impl ApiBuildable for ApiV2 {
let app = App::new()
.into_utoipa_app()
.configure(|cfg| {
labrinth::utoipa_app_config(cfg, labrinth_config.clone())
crate::utoipa_app_config(cfg, labrinth_config.clone())
})
.into_app()
.configure(|cfg| {
labrinth::app_config(cfg, labrinth_config.clone())
});
.configure(|cfg| crate::app_config(cfg, labrinth_config.clone()));
let test_app: Rc<dyn LocalService> =
Rc::new(test::init_service(app).await);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::{collections::HashMap, fmt::Write};

use crate::{
assert_status,
common::{
api_common::{
Api, ApiProject, AppendsOptionalPat,
models::{CommonItemType, CommonProject, CommonVersion},
request_data::{ImageData, ProjectCreationRequestData},
},
dummy_data::TestFile,
use crate::test::asserts::assert_status;
use crate::test::{
api_common::{
Api, ApiProject, AppendsOptionalPat,
models::{CommonItemType, CommonProject, CommonVersion},
request_data::{ImageData, ProjectCreationRequestData},
},
dummy_data::TestFile,
};
use crate::{
models::v2::{projects::LegacyProject, search::LegacySearchResults},
util::actix::AppendsMultipart,
};
use actix_http::StatusCode;
use actix_web::{
Expand All @@ -18,13 +20,9 @@ use actix_web::{
};
use async_trait::async_trait;
use bytes::Bytes;
use labrinth::{
models::v2::{projects::LegacyProject, search::LegacySearchResults},
util::actix::AppendsMultipart,
};
use serde_json::json;

use crate::common::database::MOD_USER_PAT;
use crate::test::database::MOD_USER_PAT;

use super::{
ApiV2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use serde_json::json;

use crate::common::{
use crate::models::ids::ProjectId;
use crate::test::{
api_common::request_data::{
ProjectCreationRequestData, VersionCreationRequestData,
},
dummy_data::TestFile,
};
use labrinth::models::ids::ProjectId;
use labrinth::util::actix::{MultipartSegment, MultipartSegmentData};
use crate::util::actix::{MultipartSegment, MultipartSegmentData};

pub fn get_public_project_creation_data(
slug: &str,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
use crate::routes::v2::tags::{
CategoryData, DonationPlatformQueryData, GameVersionQueryData, LoaderData,
};
use actix_http::StatusCode;
use actix_web::{
dev::ServiceResponse,
test::{self, TestRequest},
};
use async_trait::async_trait;
use labrinth::routes::v2::tags::{
CategoryData, DonationPlatformQueryData, GameVersionQueryData, LoaderData,
};

use crate::{
assert_status,
common::{
api_common::{
Api, ApiTags, AppendsOptionalPat,
models::{CommonCategoryData, CommonLoaderData},
},
database::ADMIN_USER_PAT,
use crate::test::asserts::assert_status;
use crate::test::{
api_common::{
Api, ApiTags, AppendsOptionalPat,
models::{CommonCategoryData, CommonLoaderData},
},
database::ADMIN_USER_PAT,
};

use super::ApiV2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use actix_http::StatusCode;
use actix_web::{dev::ServiceResponse, test};
use async_trait::async_trait;
use labrinth::models::{
use crate::models::{
teams::{OrganizationPermissions, ProjectPermissions},
v2::{notifications::LegacyNotification, teams::LegacyTeamMember},
};
use actix_http::StatusCode;
use actix_web::{dev::ServiceResponse, test};
use async_trait::async_trait;
use serde_json::json;

use crate::{
assert_status,
common::api_common::{
Api, ApiTeams, AppendsOptionalPat,
models::{CommonNotification, CommonTeamMember},
},
use crate::test::api_common::{
Api, ApiTeams, AppendsOptionalPat,
models::{CommonNotification, CommonTeamMember},
};
use crate::test::asserts::assert_status;

use super::ApiV2;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::ApiV2;
use crate::common::api_common::{Api, ApiUser, AppendsOptionalPat};
use crate::test::api_common::{Api, ApiUser, AppendsOptionalPat};
use actix_web::{dev::ServiceResponse, test};
use async_trait::async_trait;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@ use super::{
ApiV2,
request_data::{self, get_public_version_creation_data},
};
use crate::models::ids::ProjectId;
use crate::test::asserts::assert_status;
use crate::test::{
api_common::{Api, ApiVersion, AppendsOptionalPat, models::CommonVersion},
dummy_data::TestFile,
};
use crate::{
assert_status,
common::{
api_common::{
Api, ApiVersion, AppendsOptionalPat, models::CommonVersion,
},
dummy_data::TestFile,
},
models::{projects::VersionType, v2::projects::LegacyVersion},
routes::v2::version_file::FileUpdateData,
util::actix::AppendsMultipart,
};
use actix_http::StatusCode;
use actix_web::{
dev::ServiceResponse,
test::{self, TestRequest},
};
use async_trait::async_trait;
use labrinth::models::ids::ProjectId;
use labrinth::{
models::{projects::VersionType, v2::projects::LegacyVersion},
routes::v2::version_file::FileUpdateData,
util::actix::AppendsMultipart,
};
use serde_json::json;

pub fn url_encode_json_serialized_vec(elements: &[String]) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use crate::models::{collections::Collection, v3::projects::Project};
use actix_http::StatusCode;
use actix_web::{
dev::ServiceResponse,
test::{self, TestRequest},
};
use bytes::Bytes;
use labrinth::models::{collections::Collection, v3::projects::Project};
use serde_json::json;

use crate::{
assert_status,
common::api_common::{Api, AppendsOptionalPat, request_data::ImageData},
use crate::test::api_common::{
Api, AppendsOptionalPat, request_data::ImageData,
};
use crate::test::asserts::assert_status;

use super::ApiV3;

Expand Down
Loading
Loading