You've already forked AstralRinth
forked from didirus/AstralRinth
Misc v3 linear tasks (#767)
* v3_reroute 404 error * hash change * fixed issue with error conversion * added new model confirmation tests + title name change * renaming, fields * owner; test changes * clippy prepare * fmt * merge fixes * clippy * working merge * revs * merge fixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use crate::common::{
|
||||
api_common::{
|
||||
models::{CommonImageData, CommonProject, CommonVersion},
|
||||
request_data::ProjectCreationRequestData,
|
||||
Api, ApiProject,
|
||||
},
|
||||
dummy_data::TestFile,
|
||||
@@ -20,7 +21,10 @@ use serde_json::json;
|
||||
|
||||
use crate::common::{asserts::assert_status, database::MOD_USER_PAT};
|
||||
|
||||
use super::{request_data::get_public_project_creation_data, ApiV2};
|
||||
use super::{
|
||||
request_data::{self, get_public_project_creation_data},
|
||||
ApiV2,
|
||||
};
|
||||
|
||||
impl ApiV2 {
|
||||
pub async fn get_project_deserialized(&self, id_or_slug: &str, pat: &str) -> LegacyProject {
|
||||
@@ -80,17 +84,13 @@ impl ApiProject for ApiV2 {
|
||||
let creation_data = get_public_project_creation_data(slug, version_jar, modify_json);
|
||||
|
||||
// Add a project.
|
||||
let req = TestRequest::post()
|
||||
.uri("/v2/project")
|
||||
.append_header(("Authorization", pat))
|
||||
.set_multipart(creation_data.segment_data)
|
||||
.to_request();
|
||||
let resp = self.call(req).await;
|
||||
let slug = creation_data.slug.clone();
|
||||
let resp = self.create_project(creation_data, pat).await;
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
|
||||
// Approve as a moderator.
|
||||
let req = TestRequest::patch()
|
||||
.uri(&format!("/v2/project/{}", creation_data.slug))
|
||||
.uri(&format!("/v2/project/{}", slug))
|
||||
.append_header(("Authorization", MOD_USER_PAT))
|
||||
.set_json(json!(
|
||||
{
|
||||
@@ -101,13 +101,11 @@ impl ApiProject for ApiV2 {
|
||||
let resp = self.call(req).await;
|
||||
assert_status(&resp, StatusCode::NO_CONTENT);
|
||||
|
||||
let project = self
|
||||
.get_project_deserialized_common(&creation_data.slug, pat)
|
||||
.await;
|
||||
let project = self.get_project_deserialized_common(&slug, pat).await;
|
||||
|
||||
// Get project's versions
|
||||
let req = TestRequest::get()
|
||||
.uri(&format!("/v2/project/{}/version", creation_data.slug))
|
||||
.uri(&format!("/v2/project/{}/version", slug))
|
||||
.append_header(("Authorization", pat))
|
||||
.to_request();
|
||||
let resp = self.call(req).await;
|
||||
@@ -116,6 +114,27 @@ impl ApiProject for ApiV2 {
|
||||
(project, versions)
|
||||
}
|
||||
|
||||
async fn get_public_project_creation_data_json(
|
||||
&self,
|
||||
slug: &str,
|
||||
version_jar: Option<&TestFile>,
|
||||
) -> serde_json::Value {
|
||||
request_data::get_public_project_creation_data_json(slug, version_jar)
|
||||
}
|
||||
|
||||
async fn create_project(
|
||||
&self,
|
||||
creation_data: ProjectCreationRequestData,
|
||||
pat: &str,
|
||||
) -> ServiceResponse {
|
||||
let req = TestRequest::post()
|
||||
.uri("/v2/project")
|
||||
.append_header(("Authorization", pat))
|
||||
.set_multipart(creation_data.segment_data)
|
||||
.to_request();
|
||||
self.call(req).await
|
||||
}
|
||||
|
||||
async fn remove_project(&self, project_slug_or_id: &str, pat: &str) -> ServiceResponse {
|
||||
let req = test::TestRequest::delete()
|
||||
.uri(&format!("/v2/project/{project_slug_or_id}"))
|
||||
@@ -137,7 +156,11 @@ impl ApiProject for ApiV2 {
|
||||
async fn get_project_deserialized_common(&self, id_or_slug: &str, pat: &str) -> CommonProject {
|
||||
let resp = self.get_project(id_or_slug, pat).await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
test::read_body_json(resp).await
|
||||
// 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
|
||||
let value = serde_json::to_value(project).unwrap();
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
|
||||
async fn get_user_projects(&self, user_id_or_username: &str, pat: &str) -> ServiceResponse {
|
||||
@@ -155,7 +178,11 @@ impl ApiProject for ApiV2 {
|
||||
) -> Vec<CommonProject> {
|
||||
let resp = self.get_user_projects(user_id_or_username, pat).await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
test::read_body_json(resp).await
|
||||
// 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
|
||||
let value = serde_json::to_value(projects).unwrap();
|
||||
serde_json::from_value(value).unwrap()
|
||||
}
|
||||
|
||||
async fn edit_project(
|
||||
|
||||
Reference in New Issue
Block a user