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:
@@ -4,7 +4,10 @@ use std::io::{Cursor, Write};
|
||||
use actix_http::StatusCode;
|
||||
use actix_web::test::{self, TestRequest};
|
||||
use labrinth::models::{
|
||||
oauth_clients::OAuthClient, organizations::Organization, pats::Scopes, projects::ProjectId,
|
||||
oauth_clients::OAuthClient,
|
||||
organizations::Organization,
|
||||
pats::Scopes,
|
||||
projects::{Project, ProjectId, Version},
|
||||
};
|
||||
use serde_json::json;
|
||||
use sqlx::Executor;
|
||||
@@ -13,14 +16,7 @@ use zip::{write::FileOptions, CompressionMethod, ZipWriter};
|
||||
use crate::common::{api_common::Api, database::USER_USER_PAT};
|
||||
use labrinth::util::actix::{AppendsMultipart, MultipartSegment, MultipartSegmentData};
|
||||
|
||||
use super::{
|
||||
api_common::{
|
||||
models::{CommonProject, CommonVersion},
|
||||
ApiProject,
|
||||
},
|
||||
api_v3::ApiV3,
|
||||
database::TemporaryDatabase,
|
||||
};
|
||||
use super::{api_common::ApiProject, api_v3::ApiV3, database::TemporaryDatabase};
|
||||
|
||||
use super::{asserts::assert_status, database::USER_USER_ID, get_json_val_str};
|
||||
|
||||
@@ -174,16 +170,16 @@ pub struct DummyData {
|
||||
|
||||
impl DummyData {
|
||||
pub fn new(
|
||||
project_alpha: CommonProject,
|
||||
project_alpha_version: CommonVersion,
|
||||
project_beta: CommonProject,
|
||||
project_beta_version: CommonVersion,
|
||||
project_alpha: Project,
|
||||
project_alpha_version: Version,
|
||||
project_beta: Project,
|
||||
project_beta_version: Version,
|
||||
organization_zeta: Organization,
|
||||
oauth_client_alpha: OAuthClient,
|
||||
) -> Self {
|
||||
DummyData {
|
||||
project_alpha: DummyProjectAlpha {
|
||||
team_id: project_alpha.team.to_string(),
|
||||
team_id: project_alpha.team_id.to_string(),
|
||||
project_id: project_alpha.id.to_string(),
|
||||
project_slug: project_alpha.slug.unwrap(),
|
||||
project_id_parsed: project_alpha.id,
|
||||
@@ -193,7 +189,7 @@ impl DummyData {
|
||||
},
|
||||
|
||||
project_beta: DummyProjectBeta {
|
||||
team_id: project_beta.team.to_string(),
|
||||
team_id: project_beta.team_id.to_string(),
|
||||
project_id: project_beta.id.to_string(),
|
||||
project_slug: project_beta.slug.unwrap(),
|
||||
project_id_parsed: project_beta.id,
|
||||
@@ -205,7 +201,7 @@ impl DummyData {
|
||||
organization_zeta: DummyOrganizationZeta {
|
||||
organization_id: organization_zeta.id.to_string(),
|
||||
team_id: organization_zeta.team_id.to_string(),
|
||||
organization_title: organization_zeta.title,
|
||||
organization_name: organization_zeta.name,
|
||||
},
|
||||
|
||||
oauth_client_alpha: DummyOAuthClientAlpha {
|
||||
@@ -247,7 +243,7 @@ pub struct DummyProjectBeta {
|
||||
#[derive(Clone)]
|
||||
pub struct DummyOrganizationZeta {
|
||||
pub organization_id: String,
|
||||
pub organization_title: String,
|
||||
pub organization_name: String,
|
||||
pub team_id: String,
|
||||
}
|
||||
|
||||
@@ -311,7 +307,7 @@ pub async fn get_dummy_data(api: &ApiV3) -> DummyData {
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn add_project_alpha(api: &ApiV3) -> (CommonProject, CommonVersion) {
|
||||
pub async fn add_project_alpha(api: &ApiV3) -> (Project, Version) {
|
||||
let (project, versions) = api
|
||||
.add_public_project(
|
||||
"alpha",
|
||||
@@ -320,20 +316,29 @@ pub async fn add_project_alpha(api: &ApiV3) -> (CommonProject, CommonVersion) {
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
(project, versions.into_iter().next().unwrap())
|
||||
let alpha_project = api
|
||||
.get_project_deserialized(project.id.to_string().as_str(), USER_USER_PAT)
|
||||
.await;
|
||||
let alpha_version = api
|
||||
.get_version_deserialized(
|
||||
&versions.into_iter().next().unwrap().id.to_string(),
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
(alpha_project, alpha_version)
|
||||
}
|
||||
|
||||
pub async fn add_project_beta(api: &ApiV3) -> (CommonProject, CommonVersion) {
|
||||
pub async fn add_project_beta(api: &ApiV3) -> (Project, Version) {
|
||||
// Adds dummy data to the database with sqlx (projects, versions, threads)
|
||||
// Generate test project data.
|
||||
let jar = TestFile::DummyProjectBeta;
|
||||
// TODO: this shouldnt be hardcoded (nor should other similar ones be)
|
||||
let json_data = json!(
|
||||
{
|
||||
"title": "Test Project Beta",
|
||||
"name": "Test Project Beta",
|
||||
"slug": "beta",
|
||||
"description": "A dummy project for testing with.",
|
||||
"body": "This project is not-yet-approved, and versions are draft.",
|
||||
"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",
|
||||
@@ -390,7 +395,7 @@ pub async fn add_organization_zeta(api: &ApiV3) -> Organization {
|
||||
.uri("/v3/organization")
|
||||
.append_header(("Authorization", USER_USER_PAT))
|
||||
.set_json(json!({
|
||||
"title": "zeta",
|
||||
"name": "zeta",
|
||||
"description": "A dummy organization for testing with."
|
||||
}))
|
||||
.to_request();
|
||||
@@ -401,14 +406,14 @@ pub async fn add_organization_zeta(api: &ApiV3) -> Organization {
|
||||
get_organization_zeta(api).await
|
||||
}
|
||||
|
||||
pub async fn get_project_alpha(api: &ApiV3) -> (CommonProject, CommonVersion) {
|
||||
pub async fn get_project_alpha(api: &ApiV3) -> (Project, Version) {
|
||||
// Get project
|
||||
let req = TestRequest::get()
|
||||
.uri("/v3/project/alpha")
|
||||
.append_header(("Authorization", USER_USER_PAT))
|
||||
.to_request();
|
||||
let resp = api.call(req).await;
|
||||
let project: CommonProject = test::read_body_json(resp).await;
|
||||
let project: Project = test::read_body_json(resp).await;
|
||||
|
||||
// Get project's versions
|
||||
let req = TestRequest::get()
|
||||
@@ -416,13 +421,13 @@ pub async fn get_project_alpha(api: &ApiV3) -> (CommonProject, CommonVersion) {
|
||||
.append_header(("Authorization", USER_USER_PAT))
|
||||
.to_request();
|
||||
let resp = api.call(req).await;
|
||||
let versions: Vec<CommonVersion> = test::read_body_json(resp).await;
|
||||
let versions: Vec<Version> = test::read_body_json(resp).await;
|
||||
let version = versions.into_iter().next().unwrap();
|
||||
|
||||
(project, version)
|
||||
}
|
||||
|
||||
pub async fn get_project_beta(api: &ApiV3) -> (CommonProject, CommonVersion) {
|
||||
pub async fn get_project_beta(api: &ApiV3) -> (Project, Version) {
|
||||
// Get project
|
||||
let req = TestRequest::get()
|
||||
.uri("/v3/project/beta")
|
||||
@@ -431,7 +436,7 @@ pub async fn get_project_beta(api: &ApiV3) -> (CommonProject, CommonVersion) {
|
||||
let resp = api.call(req).await;
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
let project: serde_json::Value = test::read_body_json(resp).await;
|
||||
let project: CommonProject = serde_json::from_value(project).unwrap();
|
||||
let project: Project = serde_json::from_value(project).unwrap();
|
||||
|
||||
// Get project's versions
|
||||
let req = TestRequest::get()
|
||||
@@ -440,7 +445,7 @@ pub async fn get_project_beta(api: &ApiV3) -> (CommonProject, CommonVersion) {
|
||||
.to_request();
|
||||
let resp = api.call(req).await;
|
||||
assert_status(&resp, StatusCode::OK);
|
||||
let versions: Vec<CommonVersion> = test::read_body_json(resp).await;
|
||||
let versions: Vec<Version> = test::read_body_json(resp).await;
|
||||
let version = versions.into_iter().next().unwrap();
|
||||
|
||||
(project, version)
|
||||
|
||||
Reference in New Issue
Block a user