Fixes failing tests (#813)

* fixes failing  tests

* fmt clippy

* updated dockerfile

* fixes failing tests; adds important fix from extracts_versions PR

* assert_eq -> assert_status, giving better error messages

* fixed random failure bug

* fmt, clippy, etc
This commit is contained in:
Wyatt Verchere
2024-01-05 08:20:56 -08:00
committed by GitHub
parent f5802fee31
commit 10eed05d87
37 changed files with 555 additions and 330 deletions

View File

@@ -35,7 +35,7 @@ impl ApiV2 {
pat: Option<&str>,
) -> LegacyProject {
let resp = self.get_project(id_or_slug, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -45,7 +45,7 @@ impl ApiV2 {
pat: Option<&str>,
) -> Vec<LegacyProject> {
let resp = self.get_user_projects(user_id_or_username, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -72,8 +72,7 @@ impl ApiV2 {
.append_pat(pat)
.to_request();
let resp = self.call(req).await;
let status = resp.status();
assert_eq!(status, 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}
@@ -164,7 +163,7 @@ impl ApiProject for ApiV2 {
pat: Option<&str>,
) -> CommonProject {
let resp = self.get_project(id_or_slug, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let project: LegacyProject = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -214,7 +213,7 @@ impl ApiProject for ApiV2 {
pat: Option<&str>,
) -> Vec<CommonProject> {
let resp = self.get_user_projects(user_id_or_username, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let projects: Vec<LegacyProject> = test::read_body_json(resp).await;
// Then, deserialize to the common format

View File

@@ -1,3 +1,4 @@
use actix_http::StatusCode;
use actix_web::{
dev::ServiceResponse,
test::{self, TestRequest},
@@ -12,6 +13,7 @@ use crate::common::{
models::{CommonCategoryData, CommonLoaderData},
Api, ApiTags, AppendsOptionalPat,
},
asserts::assert_status,
database::ADMIN_USER_PAT,
};
@@ -30,7 +32,7 @@ impl ApiV2 {
pub async fn get_side_types_deserialized(&self) -> Vec<String> {
let resp = self.get_side_types().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -44,19 +46,19 @@ impl ApiV2 {
pub async fn get_game_versions_deserialized(&self) -> Vec<GameVersionQueryData> {
let resp = self.get_game_versions().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
pub async fn get_loaders_deserialized(&self) -> Vec<LoaderData> {
let resp = self.get_loaders().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
pub async fn get_categories_deserialized(&self) -> Vec<CategoryData> {
let resp = self.get_categories().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -70,8 +72,7 @@ impl ApiV2 {
pub async fn get_donation_platforms_deserialized(&self) -> Vec<DonationPlatformQueryData> {
let resp = self.get_donation_platforms().await;
println!("Response: {:?}", resp.response().body());
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}
@@ -88,7 +89,7 @@ impl ApiTags for ApiV2 {
async fn get_loaders_deserialized_common(&self) -> Vec<CommonLoaderData> {
let resp = self.get_loaders().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<LoaderData> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -106,7 +107,7 @@ impl ApiTags for ApiV2 {
async fn get_categories_deserialized_common(&self) -> Vec<CommonCategoryData> {
let resp = self.get_categories().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<CategoryData> = test::read_body_json(resp).await;
// Then, deserialize to the common format

View File

@@ -24,7 +24,7 @@ impl ApiV2 {
pat: Option<&str>,
) -> Vec<LegacyTeamMember> {
let resp = self.get_organization_members(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -34,7 +34,7 @@ impl ApiV2 {
pat: Option<&str>,
) -> Vec<LegacyTeamMember> {
let resp = self.get_team_members(team_id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -44,7 +44,7 @@ impl ApiV2 {
pat: Option<&str>,
) -> Vec<LegacyNotification> {
let resp = self.get_user_notifications(user_id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}
@@ -65,7 +65,7 @@ impl ApiTeams for ApiV2 {
pat: Option<&str>,
) -> Vec<CommonTeamMember> {
let resp = self.get_team_members(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// TODO: Note, this does NOT deserialize to any other struct first, as currently TeamMember is the same in v2 and v3.
// CommonTeamMember = TeamMember (v3)
// This may yet change, so we should keep common struct.
@@ -102,7 +102,7 @@ impl ApiTeams for ApiV2 {
pat: Option<&str>,
) -> Vec<CommonTeamMember> {
let resp = self.get_project_members(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// TODO: Note, this does NOT deserialize to any other struct first, as currently TeamMember is the same in v2 and v3.
// CommonTeamMember = TeamMember (v3)
// This may yet change, so we should keep common struct.
@@ -127,7 +127,7 @@ impl ApiTeams for ApiV2 {
pat: Option<&str>,
) -> Vec<CommonTeamMember> {
let resp = self.get_organization_members(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// TODO: Note, this does NOT deserialize to any other struct first, as currently TeamMember is the same in v2 and v3.
// CommonTeamMember = TeamMember (v3)
// This may yet change, so we should keep common struct.

View File

@@ -33,7 +33,7 @@ pub fn url_encode_json_serialized_vec(elements: &[String]) -> String {
impl ApiV2 {
pub async fn get_version_deserialized(&self, id: &str, pat: Option<&str>) -> LegacyVersion {
let resp = self.get_version(id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -44,7 +44,7 @@ impl ApiV2 {
pat: Option<&str>,
) -> LegacyVersion {
let resp = self.get_version_from_hash(hash, algorithm, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -55,7 +55,7 @@ impl ApiV2 {
pat: Option<&str>,
) -> HashMap<String, LegacyVersion> {
let resp = self.get_versions_from_hashes(hashes, algorithm, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -83,7 +83,7 @@ impl ApiV2 {
pat: Option<&str>,
) -> HashMap<String, LegacyVersion> {
let resp = self.update_individual_files(algorithm, hashes, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}
@@ -135,7 +135,7 @@ impl ApiVersion for ApiV2 {
pat,
)
.await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: LegacyVersion = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -153,7 +153,7 @@ impl ApiVersion for ApiV2 {
async fn get_version_deserialized_common(&self, id: &str, pat: Option<&str>) -> CommonVersion {
let resp = self.get_version(id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: LegacyVersion = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -212,7 +212,7 @@ impl ApiVersion for ApiV2 {
pat: Option<&str>,
) -> CommonVersion {
let resp = self.get_version_from_hash(hash, algorithm, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: LegacyVersion = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -244,7 +244,7 @@ impl ApiVersion for ApiV2 {
pat: Option<&str>,
) -> HashMap<String, CommonVersion> {
let resp = self.get_versions_from_hashes(hashes, algorithm, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: HashMap<String, LegacyVersion> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -287,7 +287,7 @@ impl ApiVersion for ApiV2 {
let resp = self
.get_update_from_hash(hash, algorithm, loaders, game_versions, version_types, pat)
.await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: LegacyVersion = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -337,7 +337,7 @@ impl ApiVersion for ApiV2 {
pat,
)
.await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: HashMap<String, LegacyVersion> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -420,7 +420,7 @@ impl ApiVersion for ApiV2 {
pat,
)
.await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<LegacyVersion> = test::read_body_json(resp).await;
// Then, deserialize to the common format

View File

@@ -1,3 +1,4 @@
use actix_http::StatusCode;
use actix_web::{
dev::ServiceResponse,
test::{self, TestRequest},
@@ -6,7 +7,10 @@ use bytes::Bytes;
use labrinth::models::{collections::Collection, v3::projects::Project};
use serde_json::json;
use crate::common::api_common::{request_data::ImageData, Api, AppendsOptionalPat};
use crate::common::{
api_common::{request_data::ImageData, Api, AppendsOptionalPat},
asserts::assert_status,
};
use super::ApiV3;
@@ -40,7 +44,7 @@ impl ApiV3 {
pub async fn get_collection_deserialized(&self, id: &str, pat: Option<&str>) -> Collection {
let resp = self.get_collection(id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -70,7 +74,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> Vec<Project> {
let resp = self.get_collection_projects(id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -145,7 +149,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> Vec<Collection> {
let resp = self.get_user_collections(user_id_or_username, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let projects: Vec<Project> = test::read_body_json(resp).await;
// Then, deserialize to the common format

View File

@@ -1,3 +1,4 @@
use actix_http::StatusCode;
use actix_web::{
dev::ServiceResponse,
test::{self, TestRequest},
@@ -6,7 +7,10 @@ use bytes::Bytes;
use labrinth::models::{organizations::Organization, users::UserId, v3::projects::Project};
use serde_json::json;
use crate::common::api_common::{request_data::ImageData, Api, AppendsOptionalPat};
use crate::common::{
api_common::{request_data::ImageData, Api, AppendsOptionalPat},
asserts::assert_status,
};
use super::ApiV3;
@@ -14,6 +18,7 @@ impl ApiV3 {
pub async fn create_organization(
&self,
organization_title: &str,
organization_slug: &str,
description: &str,
pat: Option<&str>,
) -> ServiceResponse {
@@ -22,6 +27,7 @@ impl ApiV3 {
.append_pat(pat)
.set_json(json!({
"name": organization_title,
"slug": organization_slug,
"description": description,
}))
.to_request();
@@ -42,7 +48,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> Organization {
let resp = self.get_organization(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -80,7 +86,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> Vec<Project> {
let resp = self.get_organization_projects(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}

View File

@@ -119,7 +119,7 @@ impl ApiProject for ApiV3 {
pat: Option<&str>,
) -> CommonProject {
let resp = self.get_project(id_or_slug, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let project: Project = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -169,7 +169,7 @@ impl ApiProject for ApiV3 {
pat: Option<&str>,
) -> Vec<CommonProject> {
let resp = self.get_user_projects(user_id_or_username, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let projects: Vec<Project> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -383,10 +383,7 @@ impl ApiProject for ApiV3 {
.append_pat(pat)
.to_request();
let t = self.call(req).await;
println!("Status: {}", t.status());
println!("respone Body: {:?}", t.response().body());
t
self.call(req).await
}
async fn remove_gallery_item(
@@ -480,7 +477,7 @@ impl ApiProject for ApiV3 {
impl ApiV3 {
pub async fn get_project_deserialized(&self, id_or_slug: &str, pat: Option<&str>) -> Project {
let resp = self.get_project(id_or_slug, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -503,7 +500,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> Organization {
let resp = self.get_project_organization(id_or_slug, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -530,8 +527,7 @@ impl ApiV3 {
.append_pat(pat)
.to_request();
let resp = self.call(req).await;
let status = resp.status();
assert_eq!(status, 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -598,7 +594,7 @@ impl ApiV3 {
pat,
)
.await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}

View File

@@ -1,3 +1,4 @@
use actix_http::StatusCode;
use actix_web::{
dev::ServiceResponse,
test::{self, TestRequest},
@@ -13,6 +14,7 @@ use crate::common::{
models::{CommonCategoryData, CommonLoaderData},
Api, ApiTags, AppendsOptionalPat,
},
asserts::assert_status,
database::ADMIN_USER_PAT,
};
@@ -30,7 +32,7 @@ impl ApiTags for ApiV3 {
async fn get_loaders_deserialized_common(&self) -> Vec<CommonLoaderData> {
let resp = self.get_loaders().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<LoaderData> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -48,7 +50,7 @@ impl ApiTags for ApiV3 {
async fn get_categories_deserialized_common(&self) -> Vec<CommonCategoryData> {
let resp = self.get_categories().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<CategoryData> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -60,7 +62,7 @@ impl ApiTags for ApiV3 {
impl ApiV3 {
pub async fn get_loaders_deserialized(&self) -> Vec<LoaderData> {
let resp = self.get_loaders().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -77,7 +79,7 @@ impl ApiV3 {
loader_field: &str,
) -> Vec<LoaderFieldEnumValue> {
let resp = self.get_loader_field_variants(loader_field).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -92,7 +94,7 @@ impl ApiV3 {
pub async fn get_games_deserialized(&self) -> Vec<GameData> {
let resp = self.get_games().await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}

View File

@@ -24,7 +24,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> Vec<TeamMember> {
let resp = self.get_organization_members(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -34,7 +34,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> Vec<TeamMember> {
let resp = self.get_team_members(team_id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -44,7 +44,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> Vec<TeamMember> {
let resp = self.get_project_members(project_id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}
@@ -65,7 +65,7 @@ impl ApiTeams for ApiV3 {
pat: Option<&str>,
) -> Vec<CommonTeamMember> {
let resp = self.get_team_members(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<TeamMember> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -103,7 +103,7 @@ impl ApiTeams for ApiV3 {
pat: Option<&str>,
) -> Vec<CommonTeamMember> {
let resp = self.get_project_members(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<TeamMember> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -129,7 +129,7 @@ impl ApiTeams for ApiV3 {
pat: Option<&str>,
) -> Vec<CommonTeamMember> {
let resp = self.get_organization_members(id_or_title, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<TeamMember> = test::read_body_json(resp).await;
// Then, deserialize to the common format

View File

@@ -60,7 +60,7 @@ impl ApiV3 {
pub async fn get_version_deserialized(&self, id: &str, pat: Option<&str>) -> Version {
let resp = self.get_version(id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
@@ -88,7 +88,7 @@ impl ApiV3 {
pat: Option<&str>,
) -> HashMap<String, Version> {
let resp = self.update_individual_files(algorithm, hashes, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
test::read_body_json(resp).await
}
}
@@ -158,7 +158,7 @@ impl ApiVersion for ApiV3 {
async fn get_version_deserialized_common(&self, id: &str, pat: Option<&str>) -> CommonVersion {
let resp = self.get_version(id, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Version = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -217,7 +217,7 @@ impl ApiVersion for ApiV3 {
pat: Option<&str>,
) -> CommonVersion {
let resp = self.get_version_from_hash(hash, algorithm, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Version = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -249,7 +249,7 @@ impl ApiVersion for ApiV3 {
pat: Option<&str>,
) -> HashMap<String, CommonVersion> {
let resp = self.get_versions_from_hashes(hashes, algorithm, pat).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: HashMap<String, Version> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -301,7 +301,7 @@ impl ApiVersion for ApiV3 {
let resp = self
.get_update_from_hash(hash, algorithm, loaders, game_versions, version_types, pat)
.await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Version = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -361,7 +361,7 @@ impl ApiVersion for ApiV3 {
pat,
)
.await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: HashMap<String, Version> = test::read_body_json(resp).await;
// Then, deserialize to the common format
@@ -444,7 +444,7 @@ impl ApiVersion for ApiV3 {
pat,
)
.await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
// First, deserialize to the non-common format (to test the response is valid for this api version)
let v: Vec<Version> = test::read_body_json(resp).await;
// Then, deserialize to the common format

View File

@@ -1,6 +1,6 @@
#![allow(dead_code)]
use labrinth::database::redis::RedisPool;
use labrinth::{database::redis::RedisPool, search};
use sqlx::{postgres::PgPoolOptions, PgPool};
use std::time::Duration;
use url::Url;
@@ -39,6 +39,7 @@ const TEMPLATE_DATABASE_NAME: &str = "labrinth_tests_template";
pub struct TemporaryDatabase {
pub pool: PgPool,
pub redis_pool: RedisPool,
pub search_config: labrinth::search::SearchConfig,
pub database_name: String,
}
@@ -84,10 +85,13 @@ impl TemporaryDatabase {
// Gets new Redis pool
let redis_pool = RedisPool::new(Some(temp_database_name.clone()));
// Create new meilisearch config
let search_config = search::SearchConfig::new(Some(temp_database_name.clone()));
Self {
pool,
database_name: temp_database_name,
redis_pool,
search_config,
}
}
@@ -168,10 +172,12 @@ impl TemporaryDatabase {
if !dummy_data_exists {
// Add dummy data
let name = generate_random_name("test_template_");
let db = TemporaryDatabase {
pool: pool.clone(),
database_name: TEMPLATE_DATABASE_NAME.to_string(),
redis_pool: RedisPool::new(Some(generate_random_name("test_template_"))),
redis_pool: RedisPool::new(Some(name.clone())),
search_config: search::SearchConfig::new(Some(name)),
};
let setup_api = TestEnvironment::<ApiV3>::build_setup_api(&db).await;
dummy_data::add_dummy_data(&setup_api, db.clone()).await;

View File

@@ -207,7 +207,7 @@ impl DummyData {
organization_zeta: DummyOrganizationZeta {
organization_id: organization_zeta.id.to_string(),
team_id: organization_zeta.team_id.to_string(),
organization_name: organization_zeta.name,
organization_slug: organization_zeta.slug,
},
oauth_client_alpha: DummyOAuthClientAlpha {
@@ -249,7 +249,7 @@ pub struct DummyProjectBeta {
#[derive(Clone)]
pub struct DummyOrganizationZeta {
pub organization_id: String,
pub organization_name: String,
pub organization_slug: String,
pub team_id: String,
}
@@ -390,7 +390,7 @@ pub async fn add_project_beta(api: &ApiV3) -> (Project, Version) {
.set_multipart(vec![json_segment.clone(), file_segment.clone()])
.to_request();
let resp = api.call(req).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
get_project_beta(api).await
}
@@ -401,13 +401,14 @@ pub async fn add_organization_zeta(api: &ApiV3) -> Organization {
.uri("/v3/organization")
.append_pat(USER_USER_PAT)
.set_json(json!({
"name": "zeta",
"name": "Zeta",
"slug": "zeta",
"description": "A dummy organization for testing with."
}))
.to_request();
let resp = api.call(req).await;
assert_eq!(resp.status(), 200);
assert_status(&resp, StatusCode::OK);
get_organization_zeta(api).await
}

View File

@@ -27,6 +27,7 @@ pub async fn setup(db: &database::TemporaryDatabase) -> LabrinthConfig {
let pool = db.pool.clone();
let redis_pool = db.redis_pool.clone();
let search_config = db.search_config.clone();
let file_host: Arc<dyn file_hosting::FileHost + Send + Sync> =
Arc::new(file_hosting::MockHost::new());
let mut clickhouse = clickhouse::init_client().await.unwrap();
@@ -36,6 +37,7 @@ pub async fn setup(db: &database::TemporaryDatabase) -> LabrinthConfig {
labrinth::app_setup(
pool.clone(),
redis_pool.clone(),
search_config,
&mut clickhouse,
file_host.clone(),
maxmind_reader,

View File

@@ -356,12 +356,13 @@ impl<'a, A: Api> PermissionsTest<'a, A> {
.await;
if !self.allowed_failure_codes.contains(&resp.status().as_u16()) {
return Err(format!(
"Failure permissions test failed. Expected failure codes {} got {}",
"Failure permissions test failed. Expected failure codes {} got {}. Body: {:#?}",
self.allowed_failure_codes
.iter()
.map(|code| code.to_string())
.join(","),
resp.status().as_u16()
resp.status().as_u16(),
resp.response().body()
));
}
@@ -385,8 +386,9 @@ impl<'a, A: Api> PermissionsTest<'a, A> {
.await;
if !resp.status().is_success() {
return Err(format!(
"Success permissions test failed. Expected success, got {}",
resp.status().as_u16()
"Success permissions test failed. Expected success, got {}. Body: {:#?}",
resp.status().as_u16(),
resp.response().body()
));
}
@@ -1007,15 +1009,15 @@ async fn create_dummy_project(setup_api: &ApiV3) -> (String, String) {
async fn create_dummy_org(setup_api: &ApiV3) -> (String, String) {
// Create a very simple organization
let name = generate_random_name("test_org");
let slug = generate_random_name("test_org");
let resp = setup_api
.create_organization(&name, "Example description.", ADMIN_USER_PAT)
.create_organization("Example org", &slug, "Example description.", ADMIN_USER_PAT)
.await;
assert!(resp.status().is_success());
let organization = setup_api
.get_organization_deserialized(&name, ADMIN_USER_PAT)
.get_organization_deserialized(&slug, ADMIN_USER_PAT)
.await;
let organizaion_id = organization.id.to_string();
let team_id = organization.team_id.to_string();
@@ -1109,7 +1111,7 @@ async fn get_project_permissions(
.await;
let permissions = members
.iter()
.find(|member| &member.user.id.to_string() == user_id)
.find(|member| member.user.id.to_string() == user_id)
.and_then(|member| member.permissions);
let organization_members = match organization {
@@ -1123,7 +1125,7 @@ async fn get_project_permissions(
let organization_default_project_permissions = match organization_members {
Some(members) => members
.iter()
.find(|member| &member.user.id.to_string() == user_id)
.find(|member| member.user.id.to_string() == user_id)
.and_then(|member| member.permissions),
None => None,
};

View File

@@ -2,6 +2,7 @@
use std::{collections::HashMap, sync::Arc};
use actix_http::StatusCode;
use serde_json::json;
use crate::common::{
@@ -10,7 +11,7 @@ use crate::common::{
dummy_data::{TestFile, DUMMY_CATEGORIES},
};
use super::{api_v3::ApiV3, environment::TestEnvironment};
use super::{api_v3::ApiV3, asserts::assert_status, environment::TestEnvironment};
pub async fn setup_search_projects(test_env: &TestEnvironment<ApiV3>) -> Arc<HashMap<u64, u64>> {
// Test setup and dummy data
@@ -47,7 +48,7 @@ pub async fn setup_search_projects(test_env: &TestEnvironment<ApiV3>) -> Arc<Has
MOD_USER_PAT,
)
.await;
assert_eq!(resp.status(), 204);
assert_status(&resp, StatusCode::NO_CONTENT);
(project.id.0, id)
}
};
@@ -209,7 +210,7 @@ pub async fn setup_search_projects(test_env: &TestEnvironment<ApiV3>) -> Arc<Has
// Forcibly reset the search index
let resp = api.reset_search_index().await;
assert_eq!(resp.status(), 204);
assert_status(&resp, StatusCode::NO_CONTENT);
id_conversion
}