mirror of
https://github.com/Arcadia-Solutions/arcadia.git
synced 2025-12-16 15:04:22 -06:00
feat(backend): add global download/upload factors to arcadia settings
instead of env
This commit is contained in:
@@ -19,8 +19,6 @@ SQLX_OFFLINE=true
|
||||
ARCADIA_TRACKER_NAME=Arcadia
|
||||
ARCADIA_FRONTEND_URL=https://site.com
|
||||
ARCADIA_TRACKER_URL=https://site.com
|
||||
ARCADIA_GLOBAL_UPLOAD_FACTOR=100
|
||||
ARCADIA_GLOBAL_DOWNLOAD_FACTOR=100
|
||||
ARCADIA_USER_CLASS_NAME_ON_SIGNUP=newbie
|
||||
|
||||
|
||||
|
||||
@@ -39,10 +39,6 @@ ARCADIA_TRACKER_NAME=Arcadia
|
||||
ARCADIA_FRONTEND_URL=https://site.com
|
||||
# URL for the tracker.
|
||||
ARCADIA_TRACKER_URL=https://site.com
|
||||
# Global upload factor.
|
||||
ARCADIA_GLOBAL_UPLOAD_FACTOR=100
|
||||
# Global download factor.
|
||||
ARCADIA_GLOBAL_DOWNLOAD_FACTOR=100
|
||||
# Default user class name when a user registers an account
|
||||
ARCADIA_USER_CLASS_NAME_ON_SIGNUP=newbie
|
||||
|
||||
|
||||
@@ -13,10 +13,6 @@ pub struct Env {
|
||||
pub user_class_name_on_signup: String,
|
||||
#[envconfig(from = "ARCADIA_FRONTEND_URL")]
|
||||
pub frontend_url: Url,
|
||||
#[envconfig(from = "ARCADIA_GLOBAL_UPLOAD_FACTOR")]
|
||||
pub global_upload_factor: i16,
|
||||
#[envconfig(from = "ARCADIA_GLOBAL_DOWNLOAD_FACTOR")]
|
||||
pub global_download_factor: i16,
|
||||
#[envconfig(nested)]
|
||||
pub tracker: TrackerConfig,
|
||||
#[envconfig(nested)]
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
use crate::{handlers::tracker::binary_response, Arcadia};
|
||||
use actix_web::{web::Data, HttpResponse};
|
||||
use arcadia_common::error::Result;
|
||||
use arcadia_shared::tracker::models::env::Env;
|
||||
use arcadia_shared::tracker::models::env::ArcadiaSettingsForTracker;
|
||||
use arcadia_storage::redis::RedisPoolInterface;
|
||||
|
||||
pub async fn exec<R: RedisPoolInterface + 'static>(arc: Data<Arcadia<R>>) -> Result<HttpResponse> {
|
||||
let env = Env {
|
||||
global_download_factor: arc.env.global_download_factor,
|
||||
global_upload_factor: arc.env.global_upload_factor,
|
||||
let settings = arc.pool.get_arcadia_settings().await?;
|
||||
|
||||
let settings = ArcadiaSettingsForTracker {
|
||||
global_download_factor: settings.global_download_factor,
|
||||
global_upload_factor: settings.global_upload_factor,
|
||||
};
|
||||
|
||||
binary_response(&env)
|
||||
binary_response(&settings)
|
||||
}
|
||||
|
||||
@@ -27,12 +27,8 @@ pub struct Profile {
|
||||
pub async fn create_test_app<R: RedisPoolInterface + 'static>(
|
||||
pool: Arc<ConnectionPool>,
|
||||
redis_pool: R,
|
||||
global_upload_factor: i16,
|
||||
global_download_factor: i16,
|
||||
) -> impl Service<Request, Response = ServiceResponse, Error = Error> {
|
||||
let mut env = Env::init_from_env().unwrap();
|
||||
env.global_upload_factor = global_upload_factor;
|
||||
env.global_download_factor = global_download_factor;
|
||||
let env = Env::init_from_env().unwrap();
|
||||
|
||||
// Load settings from database for tests
|
||||
let settings = pool
|
||||
@@ -116,20 +112,12 @@ impl TestUser {
|
||||
pub async fn create_test_app_and_login<R: RedisPoolInterface + 'static>(
|
||||
pool: Arc<ConnectionPool>,
|
||||
redis_pool: R,
|
||||
global_upload_factor: i16,
|
||||
global_download_factor: i16,
|
||||
test_user: TestUser,
|
||||
) -> (
|
||||
impl Service<Request, Response = ServiceResponse, Error = Error>,
|
||||
LoginResponse,
|
||||
) {
|
||||
let service = create_test_app(
|
||||
pool,
|
||||
redis_pool,
|
||||
global_upload_factor,
|
||||
global_download_factor,
|
||||
)
|
||||
.await;
|
||||
let service = create_test_app(pool, redis_pool).await;
|
||||
|
||||
// Login first
|
||||
let req = test::TestRequest::post()
|
||||
|
||||
@@ -16,8 +16,6 @@ async fn test_staff_can_get_arcadia_settings(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditArcadiaSettings,
|
||||
)
|
||||
.await;
|
||||
@@ -39,8 +37,7 @@ async fn test_staff_can_get_arcadia_settings(pool: PgPool) {
|
||||
async fn test_regular_user_cannot_get_arcadia_settings(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -55,7 +52,7 @@ async fn test_regular_user_cannot_get_arcadia_settings(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_get_arcadia_settings_requires_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -72,8 +69,6 @@ async fn test_staff_can_update_arcadia_settings(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool.clone(),
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditArcadiaSettings,
|
||||
)
|
||||
.await;
|
||||
@@ -82,6 +77,8 @@ async fn test_staff_can_update_arcadia_settings(pool: PgPool) {
|
||||
user_class_name_on_signup: "newbie".to_string(),
|
||||
default_css_sheet_name: "arcadia".to_string(),
|
||||
open_signups: false,
|
||||
global_upload_factor: 100,
|
||||
global_download_factor: 100,
|
||||
};
|
||||
|
||||
let req = test::TestRequest::put()
|
||||
@@ -108,13 +105,14 @@ async fn test_staff_can_update_arcadia_settings(pool: PgPool) {
|
||||
async fn test_regular_user_cannot_update_arcadia_settings(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let updated_settings = ArcadiaSettings {
|
||||
user_class_name_on_signup: "newbie".to_string(),
|
||||
default_css_sheet_name: "arcadia".to_string(),
|
||||
open_signups: true,
|
||||
global_upload_factor: 100,
|
||||
global_download_factor: 100,
|
||||
};
|
||||
|
||||
let req = test::TestRequest::put()
|
||||
@@ -131,12 +129,14 @@ async fn test_regular_user_cannot_update_arcadia_settings(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_update_arcadia_settings_requires_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let updated_settings = ArcadiaSettings {
|
||||
user_class_name_on_signup: "newbie".to_string(),
|
||||
default_css_sheet_name: "arcadia".to_string(),
|
||||
open_signups: true,
|
||||
global_upload_factor: 100,
|
||||
global_download_factor: 100,
|
||||
};
|
||||
|
||||
let req = test::TestRequest::put()
|
||||
@@ -155,8 +155,6 @@ async fn test_update_arcadia_settings_updates_in_memory_cache(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditArcadiaSettings,
|
||||
)
|
||||
.await;
|
||||
@@ -176,6 +174,8 @@ async fn test_update_arcadia_settings_updates_in_memory_cache(pool: PgPool) {
|
||||
user_class_name_on_signup: "newbie".to_string(),
|
||||
default_css_sheet_name: "arcadia".to_string(),
|
||||
open_signups: false,
|
||||
global_upload_factor: 100,
|
||||
global_download_factor: 100,
|
||||
};
|
||||
|
||||
let update_req = test::TestRequest::put()
|
||||
|
||||
@@ -19,14 +19,8 @@ use std::sync::Arc;
|
||||
)]
|
||||
async fn test_staff_can_edit_artist(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditArtist,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditArtist).await;
|
||||
|
||||
let req_body = EditedArtist{
|
||||
id: 1,
|
||||
@@ -61,8 +55,7 @@ async fn test_staff_can_edit_artist(pool: PgPool) {
|
||||
async fn test_search_artists_returns_paginated_results(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/search/artists?page=1&page_size=10")
|
||||
@@ -85,8 +78,7 @@ async fn test_search_artists_returns_paginated_results(pool: PgPool) {
|
||||
async fn test_search_artists_filters_by_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/search/artists?name=Beatles&page=1&page_size=10")
|
||||
@@ -108,8 +100,7 @@ async fn test_search_artists_filters_by_name(pool: PgPool) {
|
||||
async fn test_search_artists_pagination(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/search/artists?page=1&page_size=2")
|
||||
|
||||
@@ -41,7 +41,7 @@ struct RegisterResponse {
|
||||
#[sqlx::test(migrations = "../storage/migrations")]
|
||||
async fn test_open_registration(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = TestRequest::post()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -78,7 +78,7 @@ async fn test_open_registration(pool: PgPool) {
|
||||
#[sqlx::test(migrations = "../storage/migrations")]
|
||||
async fn test_duplicate_username_registration(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
// Register first user
|
||||
let req = TestRequest::post()
|
||||
@@ -124,7 +124,7 @@ async fn test_duplicate_username_registration(pool: PgPool) {
|
||||
)]
|
||||
async fn test_closed_registration_failures(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
// No key specified. Should fail.
|
||||
let req = TestRequest::post()
|
||||
@@ -175,7 +175,7 @@ async fn test_closed_registration_failures(pool: PgPool) {
|
||||
)]
|
||||
async fn test_closed_registration_success(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = TestRequest::post()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -232,7 +232,7 @@ async fn test_closed_registration_success(pool: PgPool) {
|
||||
)]
|
||||
async fn test_closed_registration_expired_failure(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = TestRequest::post()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -259,8 +259,7 @@ async fn test_closed_registration_expired_failure(pool: PgPool) {
|
||||
async fn test_authorized_endpoint_after_login(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -290,8 +289,6 @@ async fn test_login_with_banned_user(pool: PgPool) {
|
||||
let service = create_test_app(
|
||||
Arc::new(ConnectionPool::with_pg_pool(pool)),
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -316,8 +313,6 @@ async fn test_refresh_with_invalidated_token(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
Arc::clone(&pool),
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
@@ -344,8 +339,6 @@ async fn test_refresh_with_invalidated_token(pool: PgPool) {
|
||||
let (service, _) = create_test_app_and_login(
|
||||
Arc::clone(&pool),
|
||||
MockRedisPool::with_conn(redis_conn),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -17,14 +17,8 @@ use std::sync::Arc;
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_staff_can_create_css_sheet(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::CreateCssSheet,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::CreateCssSheet).await;
|
||||
|
||||
let css_sheet = UserCreatedCssSheet {
|
||||
name: "test_sheet".into(),
|
||||
@@ -52,8 +46,7 @@ async fn test_staff_can_create_css_sheet(pool: PgPool) {
|
||||
async fn test_regular_user_cannot_create_css_sheet(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let css_sheet = UserCreatedCssSheet {
|
||||
name: "test_sheet".into(),
|
||||
@@ -79,8 +72,7 @@ async fn test_regular_user_cannot_create_css_sheet(pool: PgPool) {
|
||||
async fn test_get_css_sheets(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -103,8 +95,7 @@ async fn test_get_css_sheets(pool: PgPool) {
|
||||
async fn test_get_css_sheet_by_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -122,8 +113,7 @@ async fn test_get_css_sheet_by_name(pool: PgPool) {
|
||||
async fn test_get_nonexistent_css_sheet(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -141,14 +131,8 @@ async fn test_get_nonexistent_css_sheet(pool: PgPool) {
|
||||
)]
|
||||
async fn test_staff_can_edit_css_sheet(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditCssSheet,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditCssSheet).await;
|
||||
|
||||
let edited = EditedCssSheet {
|
||||
old_name: "test_sheet_1".into(),
|
||||
@@ -181,8 +165,7 @@ async fn test_staff_can_edit_css_sheet(pool: PgPool) {
|
||||
async fn test_regular_user_cannot_edit_css_sheet(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edited = EditedCssSheet {
|
||||
old_name: "test_sheet_1".into(),
|
||||
@@ -208,7 +191,7 @@ async fn test_regular_user_cannot_edit_css_sheet(pool: PgPool) {
|
||||
)]
|
||||
async fn test_get_css_sheet_content_public(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
// Get CSS content (public endpoint, no auth required)
|
||||
let req = test::TestRequest::get()
|
||||
@@ -227,7 +210,7 @@ async fn test_get_css_sheet_content_public(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_get_nonexistent_css_sheet_content(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -241,7 +224,7 @@ async fn test_get_nonexistent_css_sheet_content(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_css_sheet_endpoints_require_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
// Test GET /api/css-sheets requires auth
|
||||
let req = test::TestRequest::get()
|
||||
@@ -268,14 +251,8 @@ async fn test_css_sheet_endpoints_require_auth(pool: PgPool) {
|
||||
)]
|
||||
async fn test_edit_default_css_sheet_name_updates_default(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditCssSheet,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditCssSheet).await;
|
||||
|
||||
// Edit the default CSS sheet name (arcadia is the default from migration)
|
||||
let edited = EditedCssSheet {
|
||||
|
||||
@@ -22,8 +22,6 @@ async fn test_staff_can_create_category(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::CreateForumCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -50,8 +48,7 @@ async fn test_staff_can_create_category(pool: PgPool) {
|
||||
async fn test_non_staff_cannot_create_category(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let create_body = UserCreatedForumCategory {
|
||||
name: "New Category".into(),
|
||||
@@ -71,7 +68,7 @@ async fn test_non_staff_cannot_create_category(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_create_category_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let create_body = UserCreatedForumCategory {
|
||||
name: "New Category".into(),
|
||||
@@ -93,8 +90,6 @@ async fn test_create_category_with_empty_name(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::CreateForumCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -118,8 +113,6 @@ async fn test_create_category_with_whitespace_only_name(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::CreateForumCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -147,14 +140,9 @@ async fn test_create_category_with_whitespace_only_name(pool: PgPool) {
|
||||
)]
|
||||
async fn test_staff_can_edit_category(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::EditForumCategory,
|
||||
)
|
||||
.await;
|
||||
let (service, staff) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditForumCategory)
|
||||
.await;
|
||||
|
||||
let edit_body = EditedForumCategory {
|
||||
id: 100,
|
||||
@@ -182,8 +170,7 @@ async fn test_staff_can_edit_category(pool: PgPool) {
|
||||
async fn test_non_staff_cannot_edit_category(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumCategory {
|
||||
id: 100,
|
||||
@@ -207,7 +194,7 @@ async fn test_non_staff_cannot_edit_category(pool: PgPool) {
|
||||
)]
|
||||
async fn test_edit_category_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let edit_body = EditedForumCategory {
|
||||
id: 100,
|
||||
@@ -227,14 +214,9 @@ async fn test_edit_category_without_auth(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_edit_nonexistent_category(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::EditForumCategory,
|
||||
)
|
||||
.await;
|
||||
let (service, staff) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditForumCategory)
|
||||
.await;
|
||||
|
||||
let edit_body = EditedForumCategory {
|
||||
id: 999,
|
||||
@@ -258,14 +240,9 @@ async fn test_edit_nonexistent_category(pool: PgPool) {
|
||||
)]
|
||||
async fn test_edit_category_with_empty_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::EditForumCategory,
|
||||
)
|
||||
.await;
|
||||
let (service, staff) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditForumCategory)
|
||||
.await;
|
||||
|
||||
let edit_body = EditedForumCategory {
|
||||
id: 100,
|
||||
@@ -289,14 +266,9 @@ async fn test_edit_category_with_empty_name(pool: PgPool) {
|
||||
)]
|
||||
async fn test_edit_category_with_whitespace_only_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::EditForumCategory,
|
||||
)
|
||||
.await;
|
||||
let (service, staff) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditForumCategory)
|
||||
.await;
|
||||
|
||||
let edit_body = EditedForumCategory {
|
||||
id: 100,
|
||||
@@ -321,14 +293,9 @@ async fn test_edit_category_with_whitespace_only_name(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_create_and_edit_category_flow(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::ForumCategoryFlow,
|
||||
)
|
||||
.await;
|
||||
let (service, staff) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::ForumCategoryFlow)
|
||||
.await;
|
||||
|
||||
// Create a category
|
||||
let create_body = UserCreatedForumCategory {
|
||||
|
||||
@@ -25,8 +25,6 @@ async fn test_staff_can_create_sub_category(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::CreateForumSubCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -58,8 +56,7 @@ async fn test_staff_can_create_sub_category(pool: PgPool) {
|
||||
async fn test_non_staff_cannot_create_sub_category(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let create_body = UserCreatedForumSubCategory {
|
||||
forum_category_id: 100,
|
||||
@@ -83,7 +80,7 @@ async fn test_non_staff_cannot_create_sub_category(pool: PgPool) {
|
||||
)]
|
||||
async fn test_create_sub_category_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let create_body = UserCreatedForumSubCategory {
|
||||
forum_category_id: 100,
|
||||
@@ -109,8 +106,6 @@ async fn test_create_sub_category_with_empty_name(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::CreateForumSubCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -140,8 +135,6 @@ async fn test_create_sub_category_with_whitespace_only_name(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::CreateForumSubCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -179,8 +172,6 @@ async fn test_staff_can_edit_sub_category(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::EditForumSubCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -215,8 +206,7 @@ async fn test_staff_can_edit_sub_category(pool: PgPool) {
|
||||
async fn test_non_staff_cannot_edit_sub_category(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumSubCategory {
|
||||
id: 100,
|
||||
@@ -244,7 +234,7 @@ async fn test_non_staff_cannot_edit_sub_category(pool: PgPool) {
|
||||
)]
|
||||
async fn test_edit_sub_category_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let edit_body = EditedForumSubCategory {
|
||||
id: 100,
|
||||
@@ -270,8 +260,6 @@ async fn test_edit_nonexistent_sub_category(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::EditForumSubCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -305,8 +293,6 @@ async fn test_edit_sub_category_with_empty_name(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::EditForumSubCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -340,8 +326,6 @@ async fn test_edit_sub_category_with_whitespace_only_name(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::EditForumSubCategory,
|
||||
)
|
||||
.await;
|
||||
@@ -375,8 +359,6 @@ async fn test_create_and_edit_sub_category_flow(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
101,
|
||||
TestUser::ForumSubCategoryFlow,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -29,8 +29,7 @@ use std::sync::Arc;
|
||||
async fn test_create_thread_success(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let create_body = UserCreatedForumThread {
|
||||
forum_sub_category_id: 100,
|
||||
@@ -69,7 +68,7 @@ async fn test_create_thread_success(pool: PgPool) {
|
||||
)]
|
||||
async fn test_create_thread_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let create_body = UserCreatedForumThread {
|
||||
forum_sub_category_id: 100,
|
||||
@@ -101,8 +100,7 @@ async fn test_create_thread_without_auth(pool: PgPool) {
|
||||
async fn test_create_thread_with_empty_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let create_body = UserCreatedForumThread {
|
||||
forum_sub_category_id: 100,
|
||||
@@ -135,8 +133,7 @@ async fn test_create_thread_with_empty_name(pool: PgPool) {
|
||||
async fn test_create_thread_with_empty_post(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let create_body = UserCreatedForumThread {
|
||||
forum_sub_category_id: 100,
|
||||
@@ -162,8 +159,7 @@ async fn test_create_thread_with_empty_post(pool: PgPool) {
|
||||
async fn test_create_thread_with_invalid_sub_category(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let create_body = UserCreatedForumThread {
|
||||
forum_sub_category_id: 999, // Non-existent sub-category
|
||||
@@ -206,8 +202,7 @@ async fn test_create_thread_with_invalid_sub_category(pool: PgPool) {
|
||||
async fn test_get_thread_success(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/thread?id=100")
|
||||
@@ -240,7 +235,7 @@ async fn test_get_thread_success(pool: PgPool) {
|
||||
)]
|
||||
async fn test_get_thread_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/thread?id=100")
|
||||
@@ -255,8 +250,7 @@ async fn test_get_thread_without_auth(pool: PgPool) {
|
||||
async fn test_get_nonexistent_thread(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/thread?id=999")
|
||||
@@ -285,8 +279,7 @@ async fn test_get_nonexistent_thread(pool: PgPool) {
|
||||
async fn test_owner_can_edit_thread_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: 100,
|
||||
@@ -323,8 +316,7 @@ async fn test_owner_can_edit_thread_name(pool: PgPool) {
|
||||
async fn test_owner_can_toggle_sticky(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: 100,
|
||||
@@ -360,8 +352,7 @@ async fn test_owner_can_toggle_sticky(pool: PgPool) {
|
||||
async fn test_owner_can_toggle_locked(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: 100,
|
||||
@@ -397,8 +388,7 @@ async fn test_owner_can_toggle_locked(pool: PgPool) {
|
||||
async fn test_owner_can_move_thread_to_different_sub_category(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: 100,
|
||||
@@ -436,14 +426,9 @@ async fn test_non_owner_cannot_edit_thread(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
|
||||
// First, login as staff user (101) and create a thread owned by them
|
||||
let (service, staff_user) = create_test_app_and_login(
|
||||
pool.clone(),
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditArtist,
|
||||
)
|
||||
.await;
|
||||
let (service, staff_user) =
|
||||
create_test_app_and_login(pool.clone(), MockRedisPool::default(), TestUser::EditArtist)
|
||||
.await;
|
||||
|
||||
let create_body = UserCreatedForumThread {
|
||||
forum_sub_category_id: 100,
|
||||
@@ -466,8 +451,7 @@ async fn test_non_owner_cannot_edit_thread(pool: PgPool) {
|
||||
|
||||
// Now login as a different non-staff user (100) and try to edit the staff user's thread
|
||||
let (service2, standard_user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: thread.id, // Thread owned by user 101 (staff)
|
||||
@@ -504,14 +488,8 @@ async fn test_staff_can_edit_any_thread(pool: PgPool) {
|
||||
|
||||
// Thread 100 is owned by user 100 (standard user)
|
||||
// Login as staff user
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditForumThread,
|
||||
)
|
||||
.await;
|
||||
let (service, staff) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditForumThread).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: 100, // Thread owned by user 100
|
||||
@@ -548,7 +526,7 @@ async fn test_staff_can_edit_any_thread(pool: PgPool) {
|
||||
)]
|
||||
async fn test_edit_thread_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: 100,
|
||||
@@ -572,8 +550,7 @@ async fn test_edit_thread_without_auth(pool: PgPool) {
|
||||
async fn test_edit_nonexistent_thread(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: 999, // Non-existent thread
|
||||
@@ -607,8 +584,7 @@ async fn test_edit_nonexistent_thread(pool: PgPool) {
|
||||
async fn test_edit_thread_with_empty_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let edit_body = EditedForumThread {
|
||||
id: 100,
|
||||
@@ -646,8 +622,7 @@ async fn test_edit_thread_with_empty_name(pool: PgPool) {
|
||||
async fn test_cannot_post_in_locked_thread(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
// Thread 101 is locked
|
||||
let post_body = UserCreatedForumPost {
|
||||
@@ -679,8 +654,7 @@ async fn test_cannot_post_in_locked_thread(pool: PgPool) {
|
||||
async fn test_can_unlock_and_post(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
// First unlock the locked thread (101)
|
||||
let edit_body = EditedForumThread {
|
||||
@@ -735,8 +709,7 @@ async fn test_can_unlock_and_post(pool: PgPool) {
|
||||
async fn test_create_thread_add_posts_edit_thread_flow(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
// Create thread
|
||||
let create_body = UserCreatedForumThread {
|
||||
@@ -824,8 +797,7 @@ async fn test_create_thread_add_posts_edit_thread_flow(pool: PgPool) {
|
||||
async fn test_move_thread_with_posts_between_sub_categories(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
// Create thread in sub-category 100
|
||||
let create_body = UserCreatedForumThread {
|
||||
@@ -905,8 +877,7 @@ async fn test_move_thread_with_posts_between_sub_categories(pool: PgPool) {
|
||||
async fn test_get_thread_posts_success(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/thread/posts?thread_id=100&page_size=10")
|
||||
@@ -932,8 +903,7 @@ async fn test_get_thread_posts_success(pool: PgPool) {
|
||||
async fn test_get_thread_posts_with_multiple_posts_pagination(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
// Create a thread
|
||||
let create_body = UserCreatedForumThread {
|
||||
@@ -1022,7 +992,7 @@ async fn test_get_thread_posts_with_multiple_posts_pagination(pool: PgPool) {
|
||||
)]
|
||||
async fn test_get_thread_posts_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/thread/posts?thread_id=100&page_size=10")
|
||||
@@ -1037,8 +1007,7 @@ async fn test_get_thread_posts_without_auth(pool: PgPool) {
|
||||
async fn test_get_posts_for_nonexistent_thread(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/thread/posts?thread_id=999&page_size=10")
|
||||
@@ -1068,8 +1037,7 @@ async fn test_get_posts_for_nonexistent_thread(pool: PgPool) {
|
||||
async fn test_get_sub_category_threads_success(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/sub-category?id=100")
|
||||
@@ -1102,8 +1070,7 @@ async fn test_get_sub_category_threads_success(pool: PgPool) {
|
||||
async fn test_sub_category_threads_show_sticky_threads(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/sub-category?id=100")
|
||||
@@ -1135,8 +1102,7 @@ async fn test_sub_category_threads_show_sticky_threads(pool: PgPool) {
|
||||
async fn test_sub_category_threads_show_locked_threads(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/sub-category?id=100")
|
||||
@@ -1167,7 +1133,7 @@ async fn test_sub_category_threads_show_locked_threads(pool: PgPool) {
|
||||
)]
|
||||
async fn test_get_sub_category_threads_without_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = common::create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = common::create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/sub-category?id=100")
|
||||
@@ -1182,8 +1148,7 @@ async fn test_get_sub_category_threads_without_auth(pool: PgPool) {
|
||||
async fn test_get_nonexistent_sub_category_threads(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.uri("/api/forum/sub-category?id=999")
|
||||
|
||||
@@ -27,14 +27,8 @@ use crate::common::{
|
||||
)]
|
||||
async fn test_edit_series(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditSeries,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditSeries).await;
|
||||
|
||||
let payload = EditedSeries {
|
||||
id: 1,
|
||||
@@ -67,8 +61,7 @@ async fn test_edit_series(pool: PgPool) {
|
||||
async fn test_add_title_group_to_series(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/api/series/title-group")
|
||||
|
||||
@@ -19,8 +19,7 @@ use std::sync::Arc;
|
||||
async fn test_owner_can_edit_their_comment(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
// Create comment
|
||||
let create_body = UserCreatedTitleGroupComment {
|
||||
@@ -67,14 +66,8 @@ async fn test_staff_can_edit_any_comment(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool.clone()));
|
||||
|
||||
// User creates comment
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool.clone(),
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool.clone(), MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let create_body = UserCreatedTitleGroupComment {
|
||||
content: "User comment".into(),
|
||||
@@ -97,8 +90,6 @@ async fn test_staff_can_edit_any_comment(pool: PgPool) {
|
||||
let (service, staff) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditTitleGroupComment,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -23,8 +23,7 @@ async fn test_reject_invalidated_tokens(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let redis_pool = MockRedisPool::default();
|
||||
let (service, user) =
|
||||
create_test_app_and_login(Arc::clone(&pool), redis_pool, 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(Arc::clone(&pool), redis_pool, TestUser::Standard).await;
|
||||
|
||||
// test that valid token by sending a request to an authenitcated endpoint
|
||||
let req = TestRequest::get()
|
||||
@@ -50,8 +49,6 @@ async fn test_reject_invalidated_tokens(pool: PgPool) {
|
||||
let (service, new_user) = create_test_app_and_login(
|
||||
Arc::clone(&pool),
|
||||
MockRedisPool::with_conn(redis_conn),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -89,14 +89,8 @@ where
|
||||
)]
|
||||
async fn test_valid_torrent(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = common::create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
common::create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -142,14 +136,8 @@ async fn test_valid_torrent(pool: PgPool) {
|
||||
)]
|
||||
async fn test_upload_torrent(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = common::create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
common::create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Torrent {
|
||||
@@ -202,8 +190,6 @@ async fn test_fill_torrent_request_uploader_only_within_first_hour(pool: PgPool)
|
||||
let (service_uploader, uploader) = common::create_test_app_and_login(
|
||||
pool.clone(),
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
@@ -211,8 +197,6 @@ async fn test_fill_torrent_request_uploader_only_within_first_hour(pool: PgPool)
|
||||
let (service_other_user, other_user) = common::create_test_app_and_login(
|
||||
pool.clone(),
|
||||
MockRedisPool::default(),
|
||||
101,
|
||||
100,
|
||||
TestUser::EditArtist,
|
||||
)
|
||||
.await;
|
||||
@@ -405,14 +389,8 @@ async fn test_fill_torrent_request_uploader_only_within_first_hour(pool: PgPool)
|
||||
)]
|
||||
async fn test_find_torrents_by_external_link(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = common::create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
common::create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let query = TorrentSearch {
|
||||
title_group_name: Some("https://en.wikipedia.org/wiki/RollerCoaster_Tycoon".to_string()),
|
||||
@@ -462,14 +440,8 @@ async fn test_find_torrents_by_external_link(pool: PgPool) {
|
||||
)]
|
||||
async fn test_find_torrents_by_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = common::create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
common::create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let query = TorrentSearch {
|
||||
title_group_name: Some("Love Me Do".to_string()),
|
||||
@@ -519,14 +491,8 @@ async fn test_find_torrents_by_name(pool: PgPool) {
|
||||
)]
|
||||
async fn test_find_torrents_no_link_or_name_provided(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = common::create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::Standard,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
common::create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let query = TorrentSearch {
|
||||
title_group_name: Some("".to_string()),
|
||||
|
||||
@@ -24,14 +24,8 @@ use std::sync::Arc;
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_staff_can_create_user_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::CreateUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::CreateUserClass).await;
|
||||
|
||||
let user_class = UserCreatedUserClass {
|
||||
name: "power_user".into(),
|
||||
@@ -59,8 +53,7 @@ async fn test_staff_can_create_user_class(pool: PgPool) {
|
||||
async fn test_regular_user_cannot_create_user_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let user_class = UserCreatedUserClass {
|
||||
name: "power_user".into(),
|
||||
@@ -81,7 +74,7 @@ async fn test_regular_user_cannot_create_user_class(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_create_user_class_requires_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let user_class = UserCreatedUserClass {
|
||||
name: "power_user".into(),
|
||||
@@ -101,14 +94,8 @@ async fn test_create_user_class_requires_auth(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_create_user_class_with_invalid_name(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::CreateUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::CreateUserClass).await;
|
||||
|
||||
// Too short name
|
||||
let user_class = UserCreatedUserClass {
|
||||
@@ -137,14 +124,8 @@ async fn test_create_user_class_with_invalid_name(pool: PgPool) {
|
||||
)]
|
||||
async fn test_staff_can_edit_user_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditUserClass).await;
|
||||
|
||||
let edited = EditedUserClass {
|
||||
name: "advanced_user".into(),
|
||||
@@ -169,14 +150,8 @@ async fn test_staff_can_edit_user_class(pool: PgPool) {
|
||||
)]
|
||||
async fn test_edit_nonexistent_user_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::EditUserClass).await;
|
||||
|
||||
let edited = EditedUserClass {
|
||||
name: "new_name".into(),
|
||||
@@ -207,8 +182,6 @@ async fn test_can_delete_user_class_with_migration(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
Arc::clone(&pool_arc),
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::DeleteUserClass,
|
||||
)
|
||||
.await;
|
||||
@@ -235,14 +208,8 @@ async fn test_can_delete_user_class_with_migration(pool: PgPool) {
|
||||
)]
|
||||
async fn test_delete_with_nonexistent_target_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::DeleteUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::DeleteUserClass).await;
|
||||
|
||||
let delete_body = DeleteUserClass {
|
||||
target_class_name: "nonexistent".into(),
|
||||
@@ -265,14 +232,8 @@ async fn test_delete_with_nonexistent_target_class(pool: PgPool) {
|
||||
)]
|
||||
async fn test_delete_nonexistent_user_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::DeleteUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::DeleteUserClass).await;
|
||||
|
||||
let delete_body = DeleteUserClass {
|
||||
target_class_name: "newbie".into(),
|
||||
@@ -299,8 +260,6 @@ async fn test_staff_can_edit_user_permissions(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditUserPermissions,
|
||||
)
|
||||
.await;
|
||||
@@ -329,8 +288,6 @@ async fn test_cannot_edit_permissions_of_locked_user(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditUserPermissions,
|
||||
)
|
||||
.await;
|
||||
@@ -357,14 +314,8 @@ async fn test_cannot_edit_permissions_of_locked_user(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_staff_can_lock_user_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::LockUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::LockUserClass).await;
|
||||
|
||||
let lock_status = UserClassLockStatus { class_locked: true };
|
||||
|
||||
@@ -382,14 +333,8 @@ async fn test_staff_can_lock_user_class(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_staff_can_unlock_user_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::LockUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::LockUserClass).await;
|
||||
|
||||
let lock_status = UserClassLockStatus {
|
||||
class_locked: false,
|
||||
@@ -416,14 +361,8 @@ async fn test_staff_can_unlock_user_class(pool: PgPool) {
|
||||
)]
|
||||
async fn test_staff_can_change_user_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::ChangeUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::ChangeUserClass).await;
|
||||
|
||||
let class_change = UserClassChange {
|
||||
class_name: "test_class".into(),
|
||||
@@ -446,14 +385,8 @@ async fn test_staff_can_change_user_class(pool: PgPool) {
|
||||
)]
|
||||
async fn test_cannot_change_class_of_locked_user(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::ChangeUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::ChangeUserClass).await;
|
||||
|
||||
let class_change = UserClassChange {
|
||||
class_name: "newbie".into(),
|
||||
@@ -476,14 +409,8 @@ async fn test_cannot_change_class_of_locked_user(pool: PgPool) {
|
||||
)]
|
||||
async fn test_cannot_change_to_nonexistent_class(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::ChangeUserClass,
|
||||
)
|
||||
.await;
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::ChangeUserClass).await;
|
||||
|
||||
let class_change = UserClassChange {
|
||||
class_name: "nonexistent_class".into(),
|
||||
|
||||
@@ -16,8 +16,6 @@ async fn test_staff_can_get_user_permissions(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditUserPermissions,
|
||||
)
|
||||
.await;
|
||||
@@ -38,8 +36,7 @@ async fn test_staff_can_get_user_permissions(pool: PgPool) {
|
||||
async fn test_regular_user_cannot_get_user_permissions(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -54,7 +51,7 @@ async fn test_regular_user_cannot_get_user_permissions(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_get_user_permissions_requires_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -71,8 +68,6 @@ async fn test_get_nonexistent_user_permissions(pool: PgPool) {
|
||||
let (service, user) = create_test_app_and_login(
|
||||
pool,
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::EditUserPermissions,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -17,8 +17,7 @@ use std::sync::Arc;
|
||||
async fn test_get_user_settings(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
@@ -37,8 +36,6 @@ async fn test_update_user_settings(pool: PgPool) {
|
||||
let (service, staff_user) = create_test_app_and_login(
|
||||
Arc::clone(&pool),
|
||||
MockRedisPool::default(),
|
||||
100,
|
||||
100,
|
||||
TestUser::CreateCssSheet,
|
||||
)
|
||||
.await;
|
||||
@@ -60,8 +57,7 @@ async fn test_update_user_settings(pool: PgPool) {
|
||||
|
||||
// Now test updating user settings as regular user (reuse same pool, create new service)
|
||||
let (service, user) =
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), 100, 100, TestUser::Standard)
|
||||
.await;
|
||||
create_test_app_and_login(pool, MockRedisPool::default(), TestUser::Standard).await;
|
||||
|
||||
let new_settings = UserSettings {
|
||||
css_sheet_name: "custom_sheet".into(),
|
||||
@@ -91,7 +87,7 @@ async fn test_update_user_settings(pool: PgPool) {
|
||||
#[sqlx::test(fixtures("with_test_users"), migrations = "../storage/migrations")]
|
||||
async fn test_get_user_settings_requires_auth(pool: PgPool) {
|
||||
let pool = Arc::new(ConnectionPool::with_pg_pool(pool));
|
||||
let service = create_test_app(pool, MockRedisPool::default(), 100, 100).await;
|
||||
let service = create_test_app(pool, MockRedisPool::default()).await;
|
||||
|
||||
let req = test::TestRequest::get()
|
||||
.insert_header(("X-Forwarded-For", "10.10.4.88"))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n SELECT user_class_name_on_signup, default_css_sheet_name, open_signups\n FROM arcadia_settings\n LIMIT 1\n ",
|
||||
"query": "\n SELECT user_class_name_on_signup, default_css_sheet_name, open_signups,\n global_upload_factor, global_download_factor\n FROM arcadia_settings\n LIMIT 1\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
@@ -17,16 +17,28 @@
|
||||
"ordinal": 2,
|
||||
"name": "open_signups",
|
||||
"type_info": "Bool"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "global_upload_factor",
|
||||
"type_info": "Int2"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "global_download_factor",
|
||||
"type_info": "Int2"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": []
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "98e680f38faf1889f65078dda373391d927ec50aa6a37c3a7bdbfc3e8494de3b"
|
||||
"hash": "8fdc490ddb4165fd271d76f5366f63600cb7fbb86b0e7298d2a342b19f7de0a2"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"db_name": "PostgreSQL",
|
||||
"query": "\n UPDATE arcadia_settings\n SET user_class_name_on_signup = $1,\n default_css_sheet_name = $2,\n open_signups = $3\n RETURNING *\n ",
|
||||
"query": "\n UPDATE arcadia_settings\n SET user_class_name_on_signup = $1,\n default_css_sheet_name = $2,\n open_signups = $3,\n global_upload_factor = $4,\n global_download_factor = $5\n RETURNING *\n ",
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
@@ -17,20 +17,34 @@
|
||||
"ordinal": 2,
|
||||
"name": "open_signups",
|
||||
"type_info": "Bool"
|
||||
},
|
||||
{
|
||||
"ordinal": 3,
|
||||
"name": "global_upload_factor",
|
||||
"type_info": "Int2"
|
||||
},
|
||||
{
|
||||
"ordinal": 4,
|
||||
"name": "global_download_factor",
|
||||
"type_info": "Int2"
|
||||
}
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Varchar",
|
||||
"Varchar",
|
||||
"Bool"
|
||||
"Bool",
|
||||
"Int2",
|
||||
"Int2"
|
||||
]
|
||||
},
|
||||
"nullable": [
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
]
|
||||
},
|
||||
"hash": "d2e5725bc4b937da8b9ef576592d5e00c7bbaa0cde578e78f35c180e40d4b105"
|
||||
"hash": "eaba4bf12e64d4b4d1aa859f4d4a7fe92f8fe69f1065cd346108fec9ec674dc6"
|
||||
}
|
||||
@@ -116,10 +116,12 @@ ON UPDATE CASCADE;
|
||||
CREATE TABLE arcadia_settings (
|
||||
user_class_name_on_signup VARCHAR(30) NOT NULL REFERENCES user_classes(name) ON UPDATE CASCADE,
|
||||
default_css_sheet_name VARCHAR(30) NOT NULL REFERENCES css_sheets(name) ON UPDATE CASCADE,
|
||||
open_signups BOOLEAN NOT NULL
|
||||
open_signups BOOLEAN NOT NULL,
|
||||
global_upload_factor SMALLINT NOT NULL,
|
||||
global_download_factor SMALLINT NOT NULL
|
||||
);
|
||||
INSERT INTO arcadia_settings (user_class_name_on_signup, default_css_sheet_name, open_signups)
|
||||
VALUES ('newbie', 'arcadia', TRUE);
|
||||
INSERT INTO arcadia_settings (user_class_name_on_signup, default_css_sheet_name, open_signups, global_upload_factor, global_download_factor)
|
||||
VALUES ('newbie', 'arcadia', TRUE, 100, 100);
|
||||
CREATE TABLE api_keys (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
|
||||
|
||||
@@ -7,4 +7,6 @@ pub struct ArcadiaSettings {
|
||||
pub user_class_name_on_signup: String,
|
||||
pub default_css_sheet_name: String,
|
||||
pub open_signups: bool,
|
||||
pub global_upload_factor: i16,
|
||||
pub global_download_factor: i16,
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ impl ConnectionPool {
|
||||
let settings = sqlx::query_as!(
|
||||
ArcadiaSettings,
|
||||
r#"
|
||||
SELECT user_class_name_on_signup, default_css_sheet_name, open_signups
|
||||
SELECT user_class_name_on_signup, default_css_sheet_name, open_signups,
|
||||
global_upload_factor, global_download_factor
|
||||
FROM arcadia_settings
|
||||
LIMIT 1
|
||||
"#,
|
||||
@@ -29,12 +30,16 @@ impl ConnectionPool {
|
||||
UPDATE arcadia_settings
|
||||
SET user_class_name_on_signup = $1,
|
||||
default_css_sheet_name = $2,
|
||||
open_signups = $3
|
||||
open_signups = $3,
|
||||
global_upload_factor = $4,
|
||||
global_download_factor = $5
|
||||
RETURNING *
|
||||
"#,
|
||||
settings.user_class_name_on_signup,
|
||||
settings.default_css_sheet_name,
|
||||
settings.open_signups
|
||||
settings.open_signups,
|
||||
settings.global_upload_factor,
|
||||
settings.global_download_factor
|
||||
)
|
||||
.fetch_one(self.borrow())
|
||||
.await
|
||||
|
||||
@@ -3,12 +3,12 @@ use reqwest::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, bincode::Encode, bincode::Decode, PartialEq)]
|
||||
pub struct Env {
|
||||
pub struct ArcadiaSettingsForTracker {
|
||||
pub global_upload_factor: i16,
|
||||
pub global_download_factor: i16,
|
||||
}
|
||||
|
||||
impl Env {
|
||||
impl ArcadiaSettingsForTracker {
|
||||
pub async fn from_backend() -> Self {
|
||||
let base_url =
|
||||
std::env::var("ARCADIA_API_BASE_URL").expect("env var ARCADIA_API_BASE_URL not set");
|
||||
@@ -28,7 +28,8 @@ impl Env {
|
||||
.expect("failed to read env response body");
|
||||
|
||||
let config = config::standard();
|
||||
let (env, _): (Env, usize) = bincode::decode_from_slice(&bytes[..], config).unwrap();
|
||||
let (env, _): (ArcadiaSettingsForTracker, usize) =
|
||||
bincode::decode_from_slice(&bytes[..], config).unwrap();
|
||||
env
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,8 @@ impl Tracker {
|
||||
pub async fn new(mut env: Env) -> Self {
|
||||
log::info!("[Setup] Getting shared env...");
|
||||
std::io::stdout().flush().unwrap();
|
||||
let shared_env = arcadia_shared::tracker::models::env::Env::from_backend().await;
|
||||
let shared_env =
|
||||
arcadia_shared::tracker::models::env::ArcadiaSettingsForTracker::from_backend().await;
|
||||
env.global_download_factor = shared_env.global_download_factor;
|
||||
env.global_upload_factor = shared_env.global_upload_factor;
|
||||
log::info!("[Setup] Got shared env");
|
||||
|
||||
Reference in New Issue
Block a user