diff --git a/.sqlx/query-2efd0efe9ce16b2da01d9bcc1603e3a7ad0f9a1e5a457770608bc41dbb83f2dd.json b/.sqlx/query-2efd0efe9ce16b2da01d9bcc1603e3a7ad0f9a1e5a457770608bc41dbb83f2dd.json deleted file mode 100644 index e666764f..00000000 --- a/.sqlx/query-2efd0efe9ce16b2da01d9bcc1603e3a7ad0f9a1e5a457770608bc41dbb83f2dd.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n INSERT INTO payouts_values (user_id, mod_id, amount, created)\n SELECT * FROM UNNEST ($1::bigint[], $2::bigint[], $3::numeric[], $4::timestamptz[])\n ", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Int8Array", - "Int8Array", - "NumericArray", - "TimestamptzArray" - ] - }, - "nullable": [] - }, - "hash": "2efd0efe9ce16b2da01d9bcc1603e3a7ad0f9a1e5a457770608bc41dbb83f2dd" -} diff --git a/tests/analytics.rs b/tests/analytics.rs index b64d5de9..4f00258d 100644 --- a/tests/analytics.rs +++ b/tests/analytics.rs @@ -1,12 +1,12 @@ use actix_web::test; use chrono::{DateTime, Duration, Utc}; +use common::permissions::PermissionsTest; +use common::permissions::PermissionsTestContext; use common::{ api_v3::ApiV3, database::*, environment::{with_test_environment, TestEnvironment}, }; -use common::permissions::PermissionsTest; -use common::permissions::PermissionsTestContext; use itertools::Itertools; use labrinth::models::ids::base62_impl::parse_base62; use labrinth::models::teams::ProjectPermissions; @@ -78,7 +78,7 @@ pub async fn analytics_revenue() { .get_analytics_revenue_deserialized( vec![&alpha_project_id], false, - None, + None, None, None, USER_USER_PAT, @@ -108,7 +108,7 @@ pub async fn analytics_revenue() { .get_analytics_revenue_deserialized( vec![&alpha_project_id], false, - Some(Utc::now() - Duration::days(801)), + Some(Utc::now() - Duration::days(801)), None, None, USER_USER_PAT, @@ -144,8 +144,7 @@ fn to_f64_vec_rounded_up(d: Vec) -> Vec { #[actix_rt::test] pub async fn permissions_analytics_revenue() { - with_test_environment(None, |test_env : TestEnvironment| async move { - + with_test_environment(None, |test_env: TestEnvironment| async move { let alpha_project_id = test_env .dummy .as_ref() @@ -229,6 +228,6 @@ pub async fn permissions_analytics_revenue() { // Cleanup test db test_env.cleanup().await; - }).await; - + }) + .await; } diff --git a/tests/common/api_common/mod.rs b/tests/common/api_common/mod.rs index 869c1b09..abf38293 100644 --- a/tests/common/api_common/mod.rs +++ b/tests/common/api_common/mod.rs @@ -1,5 +1,9 @@ use std::collections::HashMap; +use self::models::{ + CommonCategoryData, CommonImageData, CommonLoaderData, CommonNotification, CommonProject, + CommonTeamMember, CommonVersion, +}; use actix_web::dev::ServiceResponse; use async_trait::async_trait; use labrinth::{ @@ -10,10 +14,6 @@ use labrinth::{ search::SearchResults, LabrinthConfig, }; -use self::models::{ - CommonCategoryData, CommonImageData, CommonLoaderData, CommonNotification, CommonProject, - CommonTeamMember, CommonVersion, -}; use super::dummy_data::TestFile; diff --git a/tests/common/api_v3/project.rs b/tests/common/api_v3/project.rs index 40ac8d38..a2616c09 100644 --- a/tests/common/api_v3/project.rs +++ b/tests/common/api_v3/project.rs @@ -276,4 +276,4 @@ impl ApiV3 { assert_eq!(resp.status(), 200); test::read_body_json(resp).await } -} \ No newline at end of file +} diff --git a/tests/common/permissions.rs b/tests/common/permissions.rs index cd9a1363..7e27def7 100644 --- a/tests/common/permissions.rs +++ b/tests/common/permissions.rs @@ -22,6 +22,7 @@ use super::{ // - returns a 200-299 if the scope is present // - returns failure and success JSON bodies for requests that are 200 (for performing non-simple follow-up tests on) // This uses a builder format, so you can chain methods to set the parameters to non-defaults (most will probably be not need to be set). +type JsonCheck = Box; pub struct PermissionsTest<'a, A: Api> { test_env: &'a TestEnvironment, // Permissions expected to fail on this test. By default, this is all permissions except the success permissions. @@ -54,8 +55,8 @@ pub struct PermissionsTest<'a, A: Api> { // Closures that check the JSON body of the response for failure and success cases. // These are used to perform more complex tests than just checking the status code. // (eg: checking that the response contains the correct data) - failure_json_check: Option>, - success_json_check: Option>, + failure_json_check: Option, + success_json_check: Option, } pub struct PermissionsTestContext<'a> { diff --git a/tests/project.rs b/tests/project.rs index 5abf1e5a..0c71bd56 100644 --- a/tests/project.rs +++ b/tests/project.rs @@ -42,27 +42,27 @@ async fn test_get_project() { let versions = body["versions"].as_array().unwrap(); assert_eq!(versions[0], json!(alpha_version_id)); - // Confirm that the request was cached - let mut redis_pool = test_env.db.redis_pool.connect().await.unwrap(); - assert_eq!( - redis_pool - .get(PROJECTS_SLUGS_NAMESPACE, alpha_project_slug) + // Confirm that the request was cached + let mut redis_pool = test_env.db.redis_pool.connect().await.unwrap(); + assert_eq!( + redis_pool + .get(PROJECTS_SLUGS_NAMESPACE, alpha_project_slug) + .await + .unwrap() + .and_then(|x| x.parse::().ok()), + Some(parse_base62(alpha_project_id).unwrap() as i64) + ); + + let cached_project = redis_pool + .get( + PROJECTS_NAMESPACE, + &parse_base62(alpha_project_id).unwrap().to_string(), + ) .await .unwrap() - .and_then(|x| x.parse::().ok()), - Some(parse_base62(alpha_project_id).unwrap() as i64) - ); - - let cached_project = redis_pool - .get( - PROJECTS_NAMESPACE, - &parse_base62(alpha_project_id).unwrap().to_string(), - ) - .await - .unwrap() - .unwrap(); - let cached_project: serde_json::Value = serde_json::from_str(&cached_project).unwrap(); - assert_eq!(cached_project["inner"]["slug"], json!(alpha_project_slug)); + .unwrap(); + let cached_project: serde_json::Value = serde_json::from_str(&cached_project).unwrap(); + assert_eq!(cached_project["inner"]["slug"], json!(alpha_project_slug)); // Make the request again, this time it should be cached let req = test::TestRequest::get() @@ -259,24 +259,24 @@ async fn test_add_remove_project() { let resp = test_env.api.remove_project("demo", USER_USER_PAT).await; assert_eq!(resp.status(), 204); - // Confirm that the project is gone from the cache - let mut redis_pool = test_env.db.redis_pool.connect().await.unwrap(); - assert_eq!( - redis_pool - .get(PROJECTS_SLUGS_NAMESPACE, "demo") - .await - .unwrap() - .and_then(|x| x.parse::().ok()), - None - ); - assert_eq!( - redis_pool - .get(PROJECTS_SLUGS_NAMESPACE, &id) - .await - .unwrap() - .and_then(|x| x.parse::().ok()), - None - ); + // Confirm that the project is gone from the cache + let mut redis_pool = test_env.db.redis_pool.connect().await.unwrap(); + assert_eq!( + redis_pool + .get(PROJECTS_SLUGS_NAMESPACE, "demo") + .await + .unwrap() + .and_then(|x| x.parse::().ok()), + None + ); + assert_eq!( + redis_pool + .get(PROJECTS_SLUGS_NAMESPACE, &id) + .await + .unwrap() + .and_then(|x| x.parse::().ok()), + None + ); // Old slug no longer works let resp = api.get_project("demo", USER_USER_PAT).await; diff --git a/tests/v2/project.rs b/tests/v2/project.rs index cd6db745..2bb4c757 100644 --- a/tests/v2/project.rs +++ b/tests/v2/project.rs @@ -213,24 +213,24 @@ async fn test_add_remove_project() { let resp = test_env.api.remove_project("demo", USER_USER_PAT).await; assert_eq!(resp.status(), 204); - // Confirm that the project is gone from the cache - let mut redis_conn = test_env.db.redis_pool.connect().await.unwrap(); - assert_eq!( - redis_conn - .get(PROJECTS_SLUGS_NAMESPACE, "demo") - .await - .unwrap() - .map(|x| x.parse::().unwrap()), - None - ); - assert_eq!( - redis_conn - .get(PROJECTS_SLUGS_NAMESPACE, &id) - .await - .unwrap() - .map(|x| x.parse::().unwrap()), - None - ); + // Confirm that the project is gone from the cache + let mut redis_conn = test_env.db.redis_pool.connect().await.unwrap(); + assert_eq!( + redis_conn + .get(PROJECTS_SLUGS_NAMESPACE, "demo") + .await + .unwrap() + .map(|x| x.parse::().unwrap()), + None + ); + assert_eq!( + redis_conn + .get(PROJECTS_SLUGS_NAMESPACE, &id) + .await + .unwrap() + .map(|x| x.parse::().unwrap()), + None + ); // Old slug no longer works let resp = api.get_project("demo", USER_USER_PAT).await; diff --git a/tests/version.rs b/tests/version.rs index 93ca971f..dc559d7c 100644 --- a/tests/version.rs +++ b/tests/version.rs @@ -36,20 +36,20 @@ async fn test_get_version() { assert_eq!(&version.project_id.to_string(), alpha_project_id); assert_eq!(&version.id.to_string(), alpha_version_id); - let mut redis_conn = test_env.db.redis_pool.connect().await.unwrap(); - let cached_project = redis_conn - .get( - VERSIONS_NAMESPACE, - &parse_base62(alpha_version_id).unwrap().to_string(), - ) - .await - .unwrap() - .unwrap(); - let cached_project: serde_json::Value = serde_json::from_str(&cached_project).unwrap(); - assert_eq!( - cached_project["inner"]["project_id"], - json!(parse_base62(alpha_project_id).unwrap()) - ); + let mut redis_conn = test_env.db.redis_pool.connect().await.unwrap(); + let cached_project = redis_conn + .get( + VERSIONS_NAMESPACE, + &parse_base62(alpha_version_id).unwrap().to_string(), + ) + .await + .unwrap() + .unwrap(); + let cached_project: serde_json::Value = serde_json::from_str(&cached_project).unwrap(); + assert_eq!( + cached_project["inner"]["project_id"], + json!(parse_base62(alpha_project_id).unwrap()) + ); // Request should fail on non-existent version let resp = api.get_version("false", USER_USER_PAT).await;