You've already forked AstralRinth
forked from didirus/AstralRinth
Links (#763)
This commit is contained in:
@@ -3,8 +3,8 @@ use labrinth::models::{
|
||||
notifications::{NotificationAction, NotificationBody, NotificationId},
|
||||
organizations::OrganizationId,
|
||||
projects::{
|
||||
Dependency, DonationLink, GalleryItem, License, ModeratorMessage, MonetizationStatus,
|
||||
ProjectId, ProjectStatus, VersionFile, VersionId, VersionStatus, VersionType,
|
||||
Dependency, GalleryItem, License, ModeratorMessage, MonetizationStatus, ProjectId,
|
||||
ProjectStatus, VersionFile, VersionId, VersionStatus, VersionType,
|
||||
},
|
||||
teams::{OrganizationPermissions, ProjectPermissions, TeamId},
|
||||
threads::ThreadId,
|
||||
@@ -52,11 +52,6 @@ pub struct CommonProject {
|
||||
pub loaders: Vec<String>,
|
||||
pub versions: Vec<VersionId>,
|
||||
pub icon_url: Option<String>,
|
||||
pub issues_url: Option<String>,
|
||||
pub source_url: Option<String>,
|
||||
pub wiki_url: Option<String>,
|
||||
pub discord_url: Option<String>,
|
||||
pub donation_urls: Option<Vec<DonationLink>>,
|
||||
pub gallery: Vec<GalleryItem>,
|
||||
pub color: Option<u32>,
|
||||
pub thread_id: ThreadId,
|
||||
|
||||
118
tests/project.rs
118
tests/project.rs
@@ -271,7 +271,7 @@ async fn test_add_remove_project() {
|
||||
|
||||
#[actix_rt::test]
|
||||
pub async fn test_patch_project() {
|
||||
with_test_environment_all(None, |test_env| async move {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV3>| async move {
|
||||
let api = &test_env.api;
|
||||
|
||||
let alpha_project_slug = &test_env.dummy.as_ref().unwrap().project_alpha.project_slug;
|
||||
@@ -291,12 +291,14 @@ pub async fn test_patch_project() {
|
||||
assert_eq!(resp.status(), 401);
|
||||
|
||||
// Failure because we are setting URL fields to invalid urls.
|
||||
for url_type in ["issues_url", "source_url", "wiki_url", "discord_url"] {
|
||||
for url_type in ["issues", "source", "wiki", "discord"] {
|
||||
let resp = api
|
||||
.edit_project(
|
||||
alpha_project_slug,
|
||||
json!({
|
||||
url_type: "w.fake.url",
|
||||
"link_urls": {
|
||||
url_type: "not a url",
|
||||
},
|
||||
}),
|
||||
USER_USER_PAT,
|
||||
)
|
||||
@@ -391,18 +393,18 @@ pub async fn test_patch_project() {
|
||||
"body": "New successful body",
|
||||
"categories": [DUMMY_CATEGORIES[0]],
|
||||
"license_id": "MIT",
|
||||
"issues_url": "https://github.com",
|
||||
"discord_url": "https://discord.gg",
|
||||
"wiki_url": "https://wiki.com",
|
||||
"donation_urls": [{
|
||||
"id": "patreon",
|
||||
"platform": "Patreon",
|
||||
"url": "https://patreon.com"
|
||||
}]
|
||||
"link_urls":
|
||||
{
|
||||
"patreon": "https://patreon.com",
|
||||
"issues": "https://github.com",
|
||||
"discord": "https://discord.gg",
|
||||
"wiki": "https://wiki.com"
|
||||
}
|
||||
}),
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
println!("{:?}", resp.response().body());
|
||||
assert_eq!(resp.status(), 204);
|
||||
|
||||
// Old slug no longer works
|
||||
@@ -410,9 +412,7 @@ pub async fn test_patch_project() {
|
||||
assert_eq!(resp.status(), 404);
|
||||
|
||||
// New slug does work
|
||||
let project = api
|
||||
.get_project_deserialized_common("newslug", USER_USER_PAT)
|
||||
.await;
|
||||
let project = api.get_project_deserialized("newslug", USER_USER_PAT).await;
|
||||
|
||||
assert_eq!(project.slug.unwrap(), "newslug");
|
||||
assert_eq!(project.title, "New successful title");
|
||||
@@ -420,13 +420,40 @@ pub async fn test_patch_project() {
|
||||
assert_eq!(project.body, "New successful body");
|
||||
assert_eq!(project.categories, vec![DUMMY_CATEGORIES[0]]);
|
||||
assert_eq!(project.license.id, "MIT");
|
||||
assert_eq!(project.issues_url, Some("https://github.com".to_string()));
|
||||
assert_eq!(project.discord_url, Some("https://discord.gg".to_string()));
|
||||
assert_eq!(project.wiki_url, Some("https://wiki.com".to_string()));
|
||||
assert_eq!(project.donation_urls.unwrap()[0].url, "https://patreon.com");
|
||||
|
||||
// TODO:
|
||||
// for loader fields?
|
||||
let link_urls = project.link_urls;
|
||||
assert_eq!(link_urls.len(), 4);
|
||||
assert_eq!(link_urls["patreon"].platform, "patreon");
|
||||
assert_eq!(link_urls["patreon"].url, "https://patreon.com");
|
||||
assert!(link_urls["patreon"].donation);
|
||||
assert_eq!(link_urls["issues"].platform, "issues");
|
||||
assert_eq!(link_urls["issues"].url, "https://github.com");
|
||||
assert!(!link_urls["issues"].donation);
|
||||
assert_eq!(link_urls["discord"].platform, "discord");
|
||||
assert_eq!(link_urls["discord"].url, "https://discord.gg");
|
||||
assert!(!link_urls["discord"].donation);
|
||||
assert_eq!(link_urls["wiki"].platform, "wiki");
|
||||
assert_eq!(link_urls["wiki"].url, "https://wiki.com");
|
||||
assert!(!link_urls["wiki"].donation);
|
||||
|
||||
// Unset the set link_urls
|
||||
let resp = api
|
||||
.edit_project(
|
||||
"newslug",
|
||||
json!({
|
||||
"link_urls":
|
||||
{
|
||||
"issues": null,
|
||||
}
|
||||
}),
|
||||
USER_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
println!("{:?}", resp.response().body());
|
||||
assert_eq!(resp.status(), 204);
|
||||
let project = api.get_project_deserialized("newslug", USER_USER_PAT).await;
|
||||
assert_eq!(project.link_urls.len(), 3);
|
||||
assert!(!project.link_urls.contains_key("issues"));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
@@ -472,6 +499,57 @@ pub async fn test_bulk_edit_categories() {
|
||||
.await;
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
pub async fn test_bulk_edit_links() {
|
||||
with_test_environment(None, |test_env: TestEnvironment<ApiV3>| 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;
|
||||
|
||||
// Sets links for issue, source, wiki, and patreon for all projects
|
||||
// The first loop, sets issue, the second, clears it for all projects.
|
||||
for issues in [Some("https://www.issues.com"), None] {
|
||||
let resp = api
|
||||
.edit_project_bulk(
|
||||
&[alpha_project_id, beta_project_id],
|
||||
json!({
|
||||
"link_urls": {
|
||||
"issues": issues,
|
||||
"wiki": "https://wiki.com",
|
||||
"patreon": "https://patreon.com",
|
||||
},
|
||||
}),
|
||||
ADMIN_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let alpha_body = api
|
||||
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
|
||||
.await;
|
||||
if let Some(issues) = issues {
|
||||
assert_eq!(alpha_body.link_urls.len(), 3);
|
||||
assert_eq!(alpha_body.link_urls["issues"].url, issues);
|
||||
} else {
|
||||
assert_eq!(alpha_body.link_urls.len(), 2);
|
||||
assert!(!alpha_body.link_urls.contains_key("issues"));
|
||||
}
|
||||
assert_eq!(alpha_body.link_urls["wiki"].url, "https://wiki.com");
|
||||
assert_eq!(alpha_body.link_urls["patreon"].url, "https://patreon.com");
|
||||
|
||||
let beta_body = api
|
||||
.get_project_deserialized(beta_project_id, ADMIN_USER_PAT)
|
||||
.await;
|
||||
assert_eq!(beta_body.categories, alpha_body.categories);
|
||||
assert_eq!(
|
||||
beta_body.additional_categories,
|
||||
alpha_body.additional_categories,
|
||||
);
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn permissions_patch_project() {
|
||||
with_test_environment_all(Some(8), |test_env| async move {
|
||||
|
||||
@@ -4,11 +4,15 @@ use crate::common::{
|
||||
request_data::{get_public_project_creation_data_json, get_public_version_creation_data},
|
||||
ApiV2,
|
||||
},
|
||||
database::{ENEMY_USER_PAT, FRIEND_USER_ID, FRIEND_USER_PAT, MOD_USER_PAT, USER_USER_PAT},
|
||||
database::{
|
||||
ADMIN_USER_PAT, ENEMY_USER_PAT, FRIEND_USER_ID, FRIEND_USER_PAT, MOD_USER_PAT,
|
||||
USER_USER_PAT,
|
||||
},
|
||||
dummy_data::{TestFile, DUMMY_CATEGORIES},
|
||||
environment::{with_test_environment, TestEnvironment},
|
||||
permissions::{PermissionsTest, PermissionsTestContext},
|
||||
};
|
||||
use actix_http::StatusCode;
|
||||
use actix_web::test;
|
||||
use itertools::Itertools;
|
||||
use labrinth::{
|
||||
@@ -475,7 +479,6 @@ pub async fn test_patch_project() {
|
||||
|
||||
// New slug does work
|
||||
let project = api.get_project_deserialized("newslug", USER_USER_PAT).await;
|
||||
|
||||
assert_eq!(project.slug.unwrap(), "newslug");
|
||||
assert_eq!(project.title, "New successful title");
|
||||
assert_eq!(project.description, "New successful description");
|
||||
@@ -495,3 +498,169 @@ pub async fn test_patch_project() {
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
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 resp = api
|
||||
.edit_project_bulk(
|
||||
&[alpha_project_id, beta_project_id],
|
||||
json!({
|
||||
"issues_url": "https://github.com",
|
||||
"donation_urls": [
|
||||
{
|
||||
"id": "patreon",
|
||||
"platform": "Patreon",
|
||||
"url": "https://www.patreon.com/my_user"
|
||||
}
|
||||
],
|
||||
}),
|
||||
ADMIN_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let alpha_body = api
|
||||
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
|
||||
.await;
|
||||
let donation_urls = alpha_body.donation_urls.unwrap();
|
||||
assert_eq!(donation_urls.len(), 1);
|
||||
assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user");
|
||||
assert_eq!(
|
||||
alpha_body.issues_url,
|
||||
Some("https://github.com".to_string())
|
||||
);
|
||||
assert_eq!(alpha_body.discord_url, None);
|
||||
|
||||
let beta_body = api
|
||||
.get_project_deserialized(beta_project_id, ADMIN_USER_PAT)
|
||||
.await;
|
||||
let donation_urls = beta_body.donation_urls.unwrap();
|
||||
assert_eq!(donation_urls.len(), 1);
|
||||
assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user");
|
||||
assert_eq!(beta_body.issues_url, Some("https://github.com".to_string()));
|
||||
assert_eq!(beta_body.discord_url, None);
|
||||
|
||||
let resp = api
|
||||
.edit_project_bulk(
|
||||
&[alpha_project_id, beta_project_id],
|
||||
json!({
|
||||
"discord_url": "https://discord.gg",
|
||||
"issues_url": null,
|
||||
"add_donation_urls": [
|
||||
{
|
||||
"id": "bmac",
|
||||
"platform": "Buy Me a Coffee",
|
||||
"url": "https://www.buymeacoffee.com/my_user"
|
||||
}
|
||||
],
|
||||
}),
|
||||
ADMIN_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let alpha_body = api
|
||||
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
|
||||
.await;
|
||||
let donation_urls = alpha_body
|
||||
.donation_urls
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.sorted_by_key(|x| x.id.clone())
|
||||
.collect_vec();
|
||||
assert_eq!(donation_urls.len(), 2);
|
||||
assert_eq!(donation_urls[0].url, "https://www.buymeacoffee.com/my_user");
|
||||
assert_eq!(donation_urls[1].url, "https://www.patreon.com/my_user");
|
||||
assert_eq!(alpha_body.issues_url, None);
|
||||
assert_eq!(
|
||||
alpha_body.discord_url,
|
||||
Some("https://discord.gg".to_string())
|
||||
);
|
||||
|
||||
let beta_body = api
|
||||
.get_project_deserialized(beta_project_id, ADMIN_USER_PAT)
|
||||
.await;
|
||||
let donation_urls = beta_body
|
||||
.donation_urls
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.sorted_by_key(|x| x.id.clone())
|
||||
.collect_vec();
|
||||
assert_eq!(donation_urls.len(), 2);
|
||||
assert_eq!(donation_urls[0].url, "https://www.buymeacoffee.com/my_user");
|
||||
assert_eq!(donation_urls[1].url, "https://www.patreon.com/my_user");
|
||||
assert_eq!(alpha_body.issues_url, None);
|
||||
assert_eq!(
|
||||
alpha_body.discord_url,
|
||||
Some("https://discord.gg".to_string())
|
||||
);
|
||||
|
||||
let resp = api
|
||||
.edit_project_bulk(
|
||||
&[alpha_project_id, beta_project_id],
|
||||
json!({
|
||||
"donation_urls": [
|
||||
{
|
||||
"id": "patreon",
|
||||
"platform": "Patreon",
|
||||
"url": "https://www.patreon.com/my_user"
|
||||
},
|
||||
{
|
||||
"id": "ko-fi",
|
||||
"platform": "Ko-fi",
|
||||
"url": "https://www.ko-fi.com/my_user"
|
||||
}
|
||||
],
|
||||
"add_donation_urls": [
|
||||
{
|
||||
"id": "paypal",
|
||||
"platform": "PayPal",
|
||||
"url": "https://www.paypal.com/my_user"
|
||||
}
|
||||
],
|
||||
"remove_donation_urls": [
|
||||
{
|
||||
"id": "ko-fi",
|
||||
"platform": "Ko-fi",
|
||||
"url": "https://www.ko-fi.com/my_user"
|
||||
}
|
||||
],
|
||||
}),
|
||||
ADMIN_USER_PAT,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(resp.status(), StatusCode::NO_CONTENT);
|
||||
|
||||
let alpha_body = api
|
||||
.get_project_deserialized(alpha_project_id, ADMIN_USER_PAT)
|
||||
.await;
|
||||
let donation_urls = alpha_body
|
||||
.donation_urls
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.sorted_by_key(|x| x.id.clone())
|
||||
.collect_vec();
|
||||
assert_eq!(donation_urls.len(), 2);
|
||||
assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user");
|
||||
assert_eq!(donation_urls[1].url, "https://www.paypal.com/my_user");
|
||||
|
||||
let beta_body = api
|
||||
.get_project_deserialized(beta_project_id, ADMIN_USER_PAT)
|
||||
.await;
|
||||
let donation_urls = beta_body
|
||||
.donation_urls
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.sorted_by_key(|x| x.id.clone())
|
||||
.collect_vec();
|
||||
assert_eq!(donation_urls.len(), 2);
|
||||
assert_eq!(donation_urls[0].url, "https://www.patreon.com/my_user");
|
||||
assert_eq!(donation_urls[1].url, "https://www.paypal.com/my_user");
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user