1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-12-04 18:51:08 +00:00

Fix test cases

This commit is contained in:
Felix Ableitner 2024-11-25 14:56:57 +01:00
parent 805c669d00
commit c21d6fe08c
7 changed files with 33 additions and 30 deletions

View file

@ -5,12 +5,7 @@ edition = "2021"
[features]
default = ["ssr"]
ssr = [
"katex/duktape",
"leptos/ssr",
"leptos-use/ssr",
"leptos-use/axum",
]
ssr = ["katex/duktape", "leptos/ssr", "leptos-use/ssr", "leptos-use/axum"]
hydrate = ["leptos/hydrate", "katex/wasm-js"]
# This profile significantly speeds up build time. If debug info is needed you can comment the line
@ -101,10 +96,7 @@ async-trait = { version = "0.1.83" }
config = { version = "0.14.1", features = ["toml"] }
tower = { version = "0.5.1" }
tower-layer = { version = "0.3.3" }
reqwest = { version = "0.12.9", features = [
"json",
"cookies",
] }
reqwest = { version = "0.12.9", features = ["json", "cookies"] }
futures = "0.3.31"
env_logger = { version = "0.11.5", default-features = false }

View file

@ -161,6 +161,7 @@ pub(in crate::backend::api) async fn get_article(
Query(query): Query<GetArticleForm>,
data: Data<IbisData>,
) -> MyResult<Json<ArticleView>> {
dbg!(&query);
match (query.title, query.id) {
(Some(title), None) => Ok(Json(DbArticle::read_view_title(
&title,

View file

@ -3,11 +3,11 @@ use crate::{
common::{
DbInstance,
FollowInstance,
FollowInstanceResponse,
GetInstance,
InstanceView,
LocalUserView,
ResolveObject,
SuccessResponse,
},
};
use activitypub_federation::{config::Data, fetch::object_id::ObjectId};
@ -31,13 +31,13 @@ pub(in crate::backend::api) async fn follow_instance(
Extension(user): Extension<LocalUserView>,
data: Data<IbisData>,
Form(query): Form<FollowInstance>,
) -> MyResult<Json<FollowInstanceResponse>> {
) -> MyResult<Json<SuccessResponse>> {
let target = DbInstance::read(query.id, &data)?;
let pending = !target.local;
DbInstance::follow(&user.person, &target, pending, &data)?;
let instance = DbInstance::read(query.id, &data)?;
Follow::send(user.person, &instance, &data).await?;
Ok(Json(FollowInstanceResponse { success: true }))
Ok(Json(SuccessResponse::default()))
}
/// Fetch a remote instance actor. This automatically synchronizes the remote articles collection to

View file

@ -63,7 +63,7 @@ pub fn api_routes() -> Router<()> {
.route("/user/notifications/count", get(count_notifications))
.route("/account/register", post(register_user))
.route("/account/login", post(login_user))
.route("/account/logout", get(logout_user))
.route("/account/logout", post(logout_user))
.route("/site", get(site_view))
.route_layer(middleware::from_fn(auth))
}

View file

@ -12,6 +12,7 @@ use crate::{
LoginUserForm,
Notification,
RegisterUserForm,
SuccessResponse,
AUTH_COOKIE,
},
};
@ -125,9 +126,9 @@ fn create_cookie(jwt: String, data: &Data<IbisData>) -> Cookie<'static> {
pub(in crate::backend::api) async fn logout_user(
data: Data<IbisData>,
jar: CookieJar,
) -> MyResult<CookieJar> {
) -> MyResult<(CookieJar, Json<SuccessResponse>)> {
let jar = jar.remove(create_cookie(String::new(), &data));
Ok(jar)
Ok((jar, Json(SuccessResponse::default())))
}
#[debug_handler]

View file

@ -245,8 +245,14 @@ pub struct FollowInstance {
}
#[derive(Deserialize, Serialize, Debug)]
pub struct FollowInstanceResponse {
pub success: bool,
pub struct SuccessResponse {
success: bool,
}
impl Default for SuccessResponse {
fn default() -> Self {
Self { success: true }
}
}
#[derive(Deserialize, Serialize, Clone, Debug)]

View file

@ -12,7 +12,6 @@ use crate::{
DeleteConflictForm,
EditArticleForm,
FollowInstance,
FollowInstanceResponse,
ForkArticleForm,
GetArticleForm,
GetInstance,
@ -27,6 +26,7 @@ use crate::{
ResolveObject,
SearchArticleForm,
SiteView,
SuccessResponse,
},
frontend::error::MyResult,
};
@ -105,7 +105,8 @@ impl ApiClient {
&self,
edit_form: &EditArticleForm,
) -> MyResult<Option<ApiConflict>> {
self.get("/api/v1/article", Some(&edit_form)).await
self.send(Method::PATCH, "/api/v1/article", Some(&edit_form))
.await
}
pub async fn edit_article(&self, edit_form: &EditArticleForm) -> MyResult<ArticleView> {
@ -180,10 +181,7 @@ impl ApiClient {
Ok(instance_resolved)
}
pub async fn follow_instance(
&self,
follow_form: FollowInstance,
) -> MyResult<FollowInstanceResponse> {
pub async fn follow_instance(&self, follow_form: FollowInstance) -> MyResult<SuccessResponse> {
self.post("/api/v1/instance/follow", Some(follow_form))
.await
}
@ -192,8 +190,8 @@ impl ApiClient {
self.get("/api/v1/site", None::<()>).await
}
pub async fn logout(&self) -> MyResult<()> {
self.get("/api/v1/account/logout", None::<()>).await
pub async fn logout(&self) -> MyResult<SuccessResponse> {
self.post("/api/v1/account/logout", None::<()>).await
}
pub async fn fork_article(&self, form: &ForkArticleForm) -> MyResult<ArticleView> {
@ -246,8 +244,12 @@ impl ApiClient {
use reqwest::header::HeaderName;
let mut req = self
.client
.request(method, self.request_endpoint(path))
.query(&params);
.request(method.clone(), self.request_endpoint(path));
req = if method == Method::GET {
req.query(&params)
} else {
req.form(&params)
};
let auth = use_context::<Auth>();
if let Some(Auth(Some(auth))) = auth {
req = req.header(HeaderName::from_static(AUTH_COOKIE), auth);
@ -288,17 +290,18 @@ impl ApiClient {
let path_with_endpoint = self.request_endpoint(path);
let params_encoded = serde_urlencoded::to_string(&params).unwrap();
let path = if method == Method::GET {
// Cannot pass the struct directly but need to convert it manually
// Cannot pass the form data directly but need to convert it manually
// https://github.com/rustwasm/gloo/issues/378
format!("{path_with_endpoint}?{params_encoded}")
} else {
path_with_endpoint
};
let builder = RequestBuilder::new(&path)
.method(method.clone())
.abort_signal(abort_signal.as_ref())
.credentials(RequestCredentials::Include);
let req = if method == Method::POST {
let req = if method != Method::GET {
builder
.header("content-type", "application/x-www-form-urlencoded")
.body(params_encoded)