You've already forked AstralRinth
forked from didirus/AstralRinth
Test permissions use api (#784)
* initial push * fmt; clippy --------- Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
@@ -6,7 +6,7 @@ use bytes::Bytes;
|
||||
use labrinth::models::{organizations::Organization, v3::projects::Project};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::common::api_common::{request_data::ImageData, Api};
|
||||
use crate::common::api_common::{request_data::ImageData, Api, AppendsOptionalPat};
|
||||
|
||||
use super::ApiV3;
|
||||
|
||||
@@ -15,11 +15,11 @@ impl ApiV3 {
|
||||
&self,
|
||||
organization_title: &str,
|
||||
description: &str,
|
||||
pat: &str,
|
||||
pat: Option<&str>,
|
||||
) -> ServiceResponse {
|
||||
let req = test::TestRequest::post()
|
||||
.uri("/v3/organization")
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.set_json(json!({
|
||||
"name": organization_title,
|
||||
"description": description,
|
||||
@@ -28,10 +28,10 @@ impl ApiV3 {
|
||||
self.call(req).await
|
||||
}
|
||||
|
||||
pub async fn get_organization(&self, id_or_title: &str, pat: &str) -> ServiceResponse {
|
||||
pub async fn get_organization(&self, id_or_title: &str, pat: Option<&str>) -> ServiceResponse {
|
||||
let req = TestRequest::get()
|
||||
.uri(&format!("/v3/organization/{id_or_title}"))
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.to_request();
|
||||
self.call(req).await
|
||||
}
|
||||
@@ -39,17 +39,21 @@ impl ApiV3 {
|
||||
pub async fn get_organization_deserialized(
|
||||
&self,
|
||||
id_or_title: &str,
|
||||
pat: &str,
|
||||
pat: Option<&str>,
|
||||
) -> Organization {
|
||||
let resp = self.get_organization(id_or_title, pat).await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
test::read_body_json(resp).await
|
||||
}
|
||||
|
||||
pub async fn get_organization_projects(&self, id_or_title: &str, pat: &str) -> ServiceResponse {
|
||||
pub async fn get_organization_projects(
|
||||
&self,
|
||||
id_or_title: &str,
|
||||
pat: Option<&str>,
|
||||
) -> ServiceResponse {
|
||||
let req = test::TestRequest::get()
|
||||
.uri(&format!("/v3/organization/{id_or_title}/projects"))
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.to_request();
|
||||
self.call(req).await
|
||||
}
|
||||
@@ -57,7 +61,7 @@ impl ApiV3 {
|
||||
pub async fn get_organization_projects_deserialized(
|
||||
&self,
|
||||
id_or_title: &str,
|
||||
pat: &str,
|
||||
pat: Option<&str>,
|
||||
) -> Vec<Project> {
|
||||
let resp = self.get_organization_projects(id_or_title, pat).await;
|
||||
assert_eq!(resp.status(), 200);
|
||||
@@ -68,11 +72,11 @@ impl ApiV3 {
|
||||
&self,
|
||||
id_or_title: &str,
|
||||
patch: serde_json::Value,
|
||||
pat: &str,
|
||||
pat: Option<&str>,
|
||||
) -> ServiceResponse {
|
||||
let req = test::TestRequest::patch()
|
||||
.uri(&format!("/v3/organization/{id_or_title}"))
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.set_json(patch)
|
||||
.to_request();
|
||||
|
||||
@@ -83,7 +87,7 @@ impl ApiV3 {
|
||||
&self,
|
||||
id_or_title: &str,
|
||||
icon: Option<ImageData>,
|
||||
pat: &str,
|
||||
pat: Option<&str>,
|
||||
) -> ServiceResponse {
|
||||
if let Some(icon) = icon {
|
||||
// If an icon is provided, upload it
|
||||
@@ -92,7 +96,7 @@ impl ApiV3 {
|
||||
"/v3/organization/{id_or_title}/icon?ext={ext}",
|
||||
ext = icon.extension
|
||||
))
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.set_payload(Bytes::from(icon.icon))
|
||||
.to_request();
|
||||
|
||||
@@ -101,17 +105,21 @@ impl ApiV3 {
|
||||
// If no icon is provided, delete the icon
|
||||
let req = test::TestRequest::delete()
|
||||
.uri(&format!("/v3/organization/{id_or_title}/icon"))
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.to_request();
|
||||
|
||||
self.call(req).await
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn delete_organization(&self, id_or_title: &str, pat: &str) -> ServiceResponse {
|
||||
pub async fn delete_organization(
|
||||
&self,
|
||||
id_or_title: &str,
|
||||
pat: Option<&str>,
|
||||
) -> ServiceResponse {
|
||||
let req = test::TestRequest::delete()
|
||||
.uri(&format!("/v3/organization/{id_or_title}"))
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.to_request();
|
||||
|
||||
self.call(req).await
|
||||
@@ -121,11 +129,11 @@ impl ApiV3 {
|
||||
&self,
|
||||
id_or_title: &str,
|
||||
project_id_or_slug: &str,
|
||||
pat: &str,
|
||||
pat: Option<&str>,
|
||||
) -> ServiceResponse {
|
||||
let req = test::TestRequest::post()
|
||||
.uri(&format!("/v3/organization/{id_or_title}/projects"))
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.set_json(json!({
|
||||
"project_id": project_id_or_slug,
|
||||
}))
|
||||
@@ -138,13 +146,13 @@ impl ApiV3 {
|
||||
&self,
|
||||
id_or_title: &str,
|
||||
project_id_or_slug: &str,
|
||||
pat: &str,
|
||||
pat: Option<&str>,
|
||||
) -> ServiceResponse {
|
||||
let req = test::TestRequest::delete()
|
||||
.uri(&format!(
|
||||
"/v3/organization/{id_or_title}/projects/{project_id_or_slug}"
|
||||
))
|
||||
.append_header(("Authorization", pat))
|
||||
.append_pat(pat)
|
||||
.to_request();
|
||||
|
||||
self.call(req).await
|
||||
|
||||
Reference in New Issue
Block a user