You've already forked AstralRinth
forked from didirus/AstralRinth
Cleans up and removes TODOs, adds tests (#844)
* removes version ordering from v2; simplifies now-unecessary three-level faceting * resolved some todos * test for game version updating * merge fixes; display_categories fix
This commit is contained in:
@@ -77,9 +77,6 @@ pub struct CommonVersion {
|
||||
pub requested_status: Option<VersionStatus>,
|
||||
pub files: Vec<VersionFile>,
|
||||
pub dependencies: Vec<Dependency>,
|
||||
|
||||
// TODO: should ordering be in v2?
|
||||
pub ordering: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
@@ -21,8 +21,6 @@ use crate::{
|
||||
|
||||
use super::ApiV2;
|
||||
|
||||
// TODO: Tag gets do not include PAT, as they are public.
|
||||
|
||||
impl ApiV2 {
|
||||
async fn get_side_types(&self) -> ServiceResponse {
|
||||
let req = TestRequest::get()
|
||||
|
||||
@@ -66,10 +66,11 @@ impl ApiTeams for ApiV2 {
|
||||
) -> Vec<CommonTeamMember> {
|
||||
let resp = self.get_team_members(id_or_title, pat).await;
|
||||
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.
|
||||
test::read_body_json(resp).await
|
||||
// First, deserialize to the non-common format (to test the response is valid for this api version)
|
||||
let v: Vec<LegacyTeamMember> = test::read_body_json(resp).await;
|
||||
// Then, deserialize to the common format
|
||||
let value = serde_json::to_value(v).unwrap();
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
|
||||
async fn get_teams_members(
|
||||
@@ -103,10 +104,11 @@ impl ApiTeams for ApiV2 {
|
||||
) -> Vec<CommonTeamMember> {
|
||||
let resp = self.get_project_members(id_or_title, pat).await;
|
||||
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.
|
||||
test::read_body_json(resp).await
|
||||
// First, deserialize to the non-common format (to test the response is valid for this api version)
|
||||
let v: Vec<LegacyTeamMember> = test::read_body_json(resp).await;
|
||||
// Then, deserialize to the common format
|
||||
let value = serde_json::to_value(v).unwrap();
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
|
||||
async fn get_organization_members(
|
||||
@@ -128,10 +130,11 @@ impl ApiTeams for ApiV2 {
|
||||
) -> Vec<CommonTeamMember> {
|
||||
let resp = self.get_organization_members(id_or_title, pat).await;
|
||||
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.
|
||||
test::read_body_json(resp).await
|
||||
// First, deserialize to the non-common format (to test the response is valid for this api version)
|
||||
let v: Vec<LegacyTeamMember> = test::read_body_json(resp).await;
|
||||
// Then, deserialize to the common format
|
||||
let value = serde_json::to_value(v).unwrap();
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
|
||||
async fn join_team(&self, team_id: &str, pat: Option<&str>) -> ServiceResponse {
|
||||
|
||||
@@ -85,7 +85,6 @@ impl ApiV3 {
|
||||
test::read_body_json(resp).await
|
||||
}
|
||||
|
||||
// TODO: fold this into v3 API of other v3 testing PR
|
||||
async fn get_games(&self) -> ServiceResponse {
|
||||
let req = TestRequest::get()
|
||||
.uri("/v3/games")
|
||||
|
||||
@@ -66,6 +66,16 @@ impl ApiV3 {
|
||||
test::read_body_json(resp).await
|
||||
}
|
||||
|
||||
pub async fn get_versions_deserialized(
|
||||
&self,
|
||||
version_ids: Vec<String>,
|
||||
pat: Option<&str>,
|
||||
) -> Vec<Version> {
|
||||
let resp = self.get_versions(version_ids, pat).await;
|
||||
assert_status!(&resp, StatusCode::OK);
|
||||
test::read_body_json(resp).await
|
||||
}
|
||||
|
||||
pub async fn update_individual_files(
|
||||
&self,
|
||||
algorithm: &str,
|
||||
@@ -454,7 +464,6 @@ impl ApiVersion for ApiV3 {
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
|
||||
// TODO: remove redundancy in these functions
|
||||
async fn edit_version_ordering(
|
||||
&self,
|
||||
version_id: &str,
|
||||
|
||||
@@ -15,9 +15,8 @@ use zip::{write::FileOptions, CompressionMethod, ZipWriter};
|
||||
|
||||
use crate::{
|
||||
assert_status,
|
||||
common::{api_common::Api, database::USER_USER_PAT},
|
||||
common::{api_common::Api, api_v3, database::USER_USER_PAT},
|
||||
};
|
||||
use labrinth::util::actix::{AppendsMultipart, MultipartSegment, MultipartSegmentData};
|
||||
|
||||
use super::{
|
||||
api_common::{request_data::ImageData, ApiProject, AppendsOptionalPat},
|
||||
@@ -342,58 +341,22 @@ pub async fn add_project_beta(api: &ApiV3) -> (Project, Version) {
|
||||
// Generate test project data.
|
||||
let jar = TestFile::DummyProjectBeta;
|
||||
// TODO: this shouldnt be hardcoded (nor should other similar ones be)
|
||||
let json_data = json!(
|
||||
{
|
||||
"name": "Test Project Beta",
|
||||
"slug": "beta",
|
||||
"summary": "A dummy project for testing with.",
|
||||
"description": "This project is not-yet-approved, and versions are draft.",
|
||||
"initial_versions": [{
|
||||
"file_parts": [jar.filename()],
|
||||
"version_number": "1.2.3",
|
||||
"version_title": "start",
|
||||
"status": "unlisted",
|
||||
"dependencies": [],
|
||||
"singleplayer": true,
|
||||
"client_and_server": true,
|
||||
"client_only": true,
|
||||
"server_only": false,
|
||||
"game_versions": ["1.20.1"] ,
|
||||
"release_channel": "release",
|
||||
"loaders": ["fabric"],
|
||||
"featured": true
|
||||
}],
|
||||
"status": "private",
|
||||
"requested_status": "private",
|
||||
"categories": [],
|
||||
"license_id": "MIT"
|
||||
}
|
||||
|
||||
let modify_json = serde_json::from_value(json!([
|
||||
{ "op": "add", "path": "/summary", "value": "A dummy project for testing with." },
|
||||
{ "op": "add", "path": "/description", "value": "This project is not-yet-approved, and versions are draft." },
|
||||
{ "op": "add", "path": "/initial_versions/0/status", "value": "unlisted" },
|
||||
{ "op": "add", "path": "/status", "value": "private" },
|
||||
{ "op": "add", "path": "/requested_status", "value": "private" },
|
||||
]))
|
||||
.unwrap();
|
||||
|
||||
let creation_data = api_v3::request_data::get_public_project_creation_data(
|
||||
"beta",
|
||||
Some(jar),
|
||||
Some(modify_json),
|
||||
);
|
||||
|
||||
// Basic json
|
||||
let json_segment = MultipartSegment {
|
||||
name: "data".to_string(),
|
||||
filename: None,
|
||||
content_type: Some("application/json".to_string()),
|
||||
data: MultipartSegmentData::Text(serde_json::to_string(&json_data).unwrap()),
|
||||
};
|
||||
|
||||
// Basic file
|
||||
let file_segment = MultipartSegment {
|
||||
name: jar.filename(),
|
||||
filename: Some(jar.filename()),
|
||||
content_type: Some("application/java-archive".to_string()),
|
||||
data: MultipartSegmentData::Binary(jar.bytes()),
|
||||
};
|
||||
|
||||
// Add a project.
|
||||
let req = TestRequest::post()
|
||||
.uri("/v3/project")
|
||||
.append_pat(USER_USER_PAT)
|
||||
.set_multipart(vec![json_segment.clone(), file_segment.clone()])
|
||||
.to_request();
|
||||
let resp = api.call(req).await;
|
||||
assert_status!(&resp, StatusCode::OK);
|
||||
api.create_project(creation_data, USER_USER_PAT).await;
|
||||
|
||||
get_project_beta(api).await
|
||||
}
|
||||
|
||||
@@ -25,9 +25,6 @@ pub async fn with_test_environment<Fut, A>(
|
||||
db.cleanup().await;
|
||||
}
|
||||
|
||||
// TODO: This needs to be slightly redesigned in order to do both V2 and v3 tests.
|
||||
// TODO: Most tests, since they use API functions, can be applied to both. The ones that weren't are in v2/, but
|
||||
// all tests that can be applied to both should use both v2 and v3 (extract api to a trait with all the API functions and call both).
|
||||
pub async fn with_test_environment_all<Fut, F>(max_connections: Option<u32>, f: F)
|
||||
where
|
||||
Fut: Future<Output = ()>,
|
||||
|
||||
Reference in New Issue
Block a user