You've already forked AstralRinth
forked from didirus/AstralRinth
Misc testing improvements (#805)
* made dummy data more consistent; not an option * fixed variable dropping issue crashing actix (?) * removed scopes specific tests, removed schedule tests * team routes use api * removed printlns, fmt clippy prepare
This commit is contained in:
@@ -8,13 +8,7 @@ use crate::common::{
|
||||
#[actix_rt::test]
|
||||
pub async fn get_user_notifications_after_team_invitation_returns_notification() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||
let alpha_team_id = test_env
|
||||
.dummy
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.project_alpha
|
||||
.team_id
|
||||
.clone();
|
||||
let alpha_team_id = test_env.dummy.project_alpha.team_id.clone();
|
||||
let api = test_env.api;
|
||||
api.add_user_to_team(&alpha_team_id, FRIEND_USER_ID, None, None, USER_USER_PAT)
|
||||
.await;
|
||||
|
||||
@@ -228,10 +228,10 @@ async fn test_add_remove_project() {
|
||||
#[actix_rt::test]
|
||||
async fn permissions_upload_version() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||
let alpha_project_id = &test_env.dummy.as_ref().unwrap().project_alpha.project_id;
|
||||
let alpha_version_id = &test_env.dummy.as_ref().unwrap().project_alpha.version_id;
|
||||
let alpha_team_id = &test_env.dummy.as_ref().unwrap().project_alpha.team_id;
|
||||
let alpha_file_hash = &test_env.dummy.as_ref().unwrap().project_alpha.file_hash;
|
||||
let alpha_project_id = &test_env.dummy.project_alpha.project_id;
|
||||
let alpha_version_id = &test_env.dummy.project_alpha.version_id;
|
||||
let alpha_team_id = &test_env.dummy.project_alpha.team_id;
|
||||
let alpha_file_hash = &test_env.dummy.project_alpha.file_hash;
|
||||
|
||||
let api = &test_env.api;
|
||||
let basic_mod_different_file = TestFile::BasicModDifferent;
|
||||
@@ -331,7 +331,7 @@ pub async fn test_patch_v2() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||
let api = &test_env.api;
|
||||
|
||||
let alpha_project_slug = &test_env.dummy.as_ref().unwrap().project_alpha.project_slug;
|
||||
let alpha_project_slug = &test_env.dummy.project_alpha.project_slug;
|
||||
|
||||
// Sucessful request to patch many fields.
|
||||
let resp = api
|
||||
@@ -437,8 +437,8 @@ async fn permissions_patch_project_v2() {
|
||||
pub async fn test_bulk_edit_links() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||
let api = &test_env.api;
|
||||
let alpha_project_id: &str = &test_env.dummy.as_ref().unwrap().project_alpha.project_id;
|
||||
let beta_project_id: &str = &test_env.dummy.as_ref().unwrap().project_beta.project_id;
|
||||
let alpha_project_id: &str = &test_env.dummy.project_alpha.project_id;
|
||||
let beta_project_id: &str = &test_env.dummy.project_beta.project_id;
|
||||
|
||||
let resp = api
|
||||
.edit_project_bulk(
|
||||
|
||||
@@ -1,29 +1,27 @@
|
||||
use crate::common::api_common::ApiProject;
|
||||
use crate::common::api_common::ApiVersion;
|
||||
use crate::common::api_v2::request_data::get_public_project_creation_data;
|
||||
use crate::common::api_v2::request_data::get_public_version_creation_data;
|
||||
use crate::common::api_v2::ApiV2;
|
||||
use crate::common::dummy_data::TestFile;
|
||||
use crate::common::environment::with_test_environment;
|
||||
use crate::common::environment::TestEnvironment;
|
||||
use crate::common::scopes::ScopeTest;
|
||||
use actix_web::test;
|
||||
use labrinth::models::ids::base62_impl::parse_base62;
|
||||
use labrinth::models::pats::Scopes;
|
||||
use labrinth::models::projects::ProjectId;
|
||||
use labrinth::util::actix::AppendsMultipart;
|
||||
|
||||
// Project version creation scopes
|
||||
#[actix_rt::test]
|
||||
pub async fn project_version_create_scopes() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||
let api = &test_env.api;
|
||||
// Create project
|
||||
let create_project = Scopes::PROJECT_CREATE;
|
||||
|
||||
let req_gen = || {
|
||||
let req_gen = |pat: Option<String>| async move {
|
||||
let creation_data =
|
||||
get_public_project_creation_data("demo", Some(TestFile::BasicMod), None);
|
||||
test::TestRequest::post()
|
||||
.uri("/v2/project")
|
||||
.set_multipart(creation_data.segment_data)
|
||||
api.create_project(creation_data, pat.as_deref()).await
|
||||
};
|
||||
let (_, success) = ScopeTest::new(&test_env)
|
||||
.test(req_gen, create_project)
|
||||
@@ -34,17 +32,16 @@ pub async fn project_version_create_scopes() {
|
||||
|
||||
// Add version to project
|
||||
let create_version = Scopes::VERSION_CREATE;
|
||||
let req_gen = || {
|
||||
let creation_data = get_public_version_creation_data(
|
||||
let req_gen = |pat: Option<String>| async move {
|
||||
api.add_public_version(
|
||||
project_id,
|
||||
"1.2.3.4",
|
||||
TestFile::BasicModDifferent,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
test::TestRequest::post()
|
||||
.uri("/v2/version")
|
||||
.set_multipart(creation_data.segment_data)
|
||||
pat.as_deref(),
|
||||
)
|
||||
.await
|
||||
};
|
||||
ScopeTest::new(&test_env)
|
||||
.test(req_gen, create_version)
|
||||
|
||||
@@ -17,7 +17,7 @@ async fn transfer_ownership_v2() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||
let api = &test_env.api;
|
||||
|
||||
let alpha_team_id = &test_env.dummy.as_ref().unwrap().project_alpha.team_id;
|
||||
let alpha_team_id = &test_env.dummy.project_alpha.team_id;
|
||||
|
||||
// Cannot set friend as owner (not a member)
|
||||
let resp = api
|
||||
|
||||
@@ -9,6 +9,7 @@ use serde_json::json;
|
||||
|
||||
use crate::common::api_common::{ApiProject, ApiVersion};
|
||||
use crate::common::api_v2::ApiV2;
|
||||
use crate::common::dummy_data::{DummyProjectAlpha, DummyProjectBeta};
|
||||
use crate::common::environment::{with_test_environment, TestEnvironment};
|
||||
use crate::common::{
|
||||
database::{ENEMY_USER_PAT, USER_USER_PAT},
|
||||
@@ -20,7 +21,7 @@ pub async fn test_patch_version() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||
let api = &test_env.api;
|
||||
|
||||
let alpha_version_id = &test_env.dummy.as_ref().unwrap().project_alpha.version_id;
|
||||
let alpha_version_id = &test_env.dummy.project_alpha.version_id;
|
||||
|
||||
// // First, we do some patch requests that should fail.
|
||||
// // Failure because the user is not authorized.
|
||||
@@ -132,18 +133,18 @@ async fn version_updates() {
|
||||
// Test setup and dummy data
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV2>| async move {
|
||||
let api = &test_env.api;
|
||||
|
||||
let alpha_project_id: &String = &test_env.dummy.as_ref().unwrap().project_alpha.project_id;
|
||||
let alpha_project_id_parsed = test_env
|
||||
.dummy
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.project_alpha
|
||||
.project_id_parsed;
|
||||
let alpha_version_id = &test_env.dummy.as_ref().unwrap().project_alpha.version_id;
|
||||
let beta_version_id = &test_env.dummy.as_ref().unwrap().project_beta.version_id;
|
||||
let alpha_version_hash = &test_env.dummy.as_ref().unwrap().project_alpha.file_hash;
|
||||
let beta_version_hash = &test_env.dummy.as_ref().unwrap().project_beta.file_hash;
|
||||
let DummyProjectAlpha {
|
||||
project_id: alpha_project_id,
|
||||
project_id_parsed: alpha_project_id_parsed,
|
||||
version_id: alpha_version_id,
|
||||
file_hash: alpha_version_hash,
|
||||
..
|
||||
} = &test_env.dummy.project_alpha;
|
||||
let DummyProjectBeta {
|
||||
version_id: beta_version_id,
|
||||
file_hash: beta_version_hash,
|
||||
..
|
||||
} = &test_env.dummy.project_beta;
|
||||
|
||||
// Quick test, using get version from hash
|
||||
let version = api
|
||||
@@ -224,7 +225,7 @@ async fn version_updates() {
|
||||
{
|
||||
let version = api
|
||||
.add_public_version_deserialized_common(
|
||||
alpha_project_id_parsed,
|
||||
*alpha_project_id_parsed,
|
||||
version_number,
|
||||
TestFile::build_random_jar(),
|
||||
None,
|
||||
|
||||
Reference in New Issue
Block a user