fix tests

This commit is contained in:
Felix Ableitner 2023-12-13 13:13:10 +01:00
parent 446556ff1a
commit 02db60ba15
7 changed files with 18 additions and 9 deletions

1
Cargo.lock generated
View File

@ -730,6 +730,7 @@ dependencies = [
"rand", "rand",
"reqwest", "reqwest",
"serde", "serde",
"serde_json",
"sha2", "sha2",
"tokio", "tokio",
"tracing", "tracing",

View File

@ -22,6 +22,7 @@ hex = "0.4.3"
jsonwebtoken = "9.2.0" jsonwebtoken = "9.2.0"
rand = "0.8.5" rand = "0.8.5"
serde = "1.0.192" serde = "1.0.192"
serde_json = "1.0.108"
sha2 = "0.10.8" sha2 = "0.10.8"
tokio = { version = "1.34.0", features = ["full"] } tokio = { version = "1.34.0", features = ["full"] }
tracing = "0.1.40" tracing = "0.1.40"

View File

@ -29,7 +29,7 @@ create table local_user (
create table instance_follow ( create table instance_follow (
id serial primary key, id serial primary key,
instance_id int REFERENCES instance ON UPDATE CASCADE ON DELETE CASCADE NOT NULL, instance_id int REFERENCES instance ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
follower_id int REFERENCES person ON UPDATE CASCADE ON DELETE CASCADE NOT NULL, follower_id int REFERENCES instance ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
pending boolean not null, pending boolean not null,
unique(instance_id, follower_id) unique(instance_id, follower_id)
); );

View File

@ -82,8 +82,6 @@ diesel::table! {
diesel::joinable!(article -> instance (instance_id)); diesel::joinable!(article -> instance (instance_id));
diesel::joinable!(conflict -> article (article_id)); diesel::joinable!(conflict -> article (article_id));
diesel::joinable!(edit -> article (article_id)); diesel::joinable!(edit -> article (article_id));
diesel::joinable!(instance_follow -> instance (instance_id));
diesel::joinable!(instance_follow -> person (follower_id));
diesel::joinable!(local_user -> person (person_id)); diesel::joinable!(local_user -> person (person_id));
diesel::allow_tables_to_appear_in_same_query!( diesel::allow_tables_to_appear_in_same_query!(

View File

@ -52,6 +52,7 @@ impl ActivityHandler for Accept {
let local_instance = DbInstance::read_local_instance(&data.db_connection)?; let local_instance = DbInstance::read_local_instance(&data.db_connection)?;
let actor = self.actor.dereference(data).await?; let actor = self.actor.dereference(data).await?;
DbInstance::follow(local_instance.id, actor.id, false, data)?; DbInstance::follow(local_instance.id, actor.id, false, data)?;
dbg!(&self);
Ok(()) Ok(())
} }
} }

View File

@ -26,6 +26,7 @@ impl Follow {
to: DbInstance, to: DbInstance,
data: &Data<MyDataHandle>, data: &Data<MyDataHandle>,
) -> MyResult<()> { ) -> MyResult<()> {
dbg!(1);
let id = generate_activity_id(local_instance.ap_id.inner())?; let id = generate_activity_id(local_instance.ap_id.inner())?;
let follow = Follow { let follow = Follow {
actor: local_instance.ap_id.clone(), actor: local_instance.ap_id.clone(),
@ -33,6 +34,7 @@ impl Follow {
kind: Default::default(), kind: Default::default(),
id, id,
}; };
dbg!(&follow);
local_instance local_instance
.send(follow, vec![to.shared_inbox_or_inbox()], data) .send(follow, vec![to.shared_inbox_or_inbox()], data)
.await?; .await?;

View File

@ -20,6 +20,7 @@ use std::thread::{sleep, spawn};
use std::time::Duration; use std::time::Duration;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use tracing::log::LevelFilter; use tracing::log::LevelFilter;
use tracing::warn;
use url::Url; use url::Url;
pub static CLIENT: Lazy<Client> = Lazy::new(Client::new); pub static CLIENT: Lazy<Client> = Lazy::new(Client::new);
@ -208,11 +209,12 @@ where
T: for<'de> Deserialize<'de>, T: for<'de> Deserialize<'de>,
{ {
let res = req.send().await?; let res = req.send().await?;
if res.status() == StatusCode::OK { let status = res.status();
Ok(res.json().await?) let text = res.text().await?;
if status == StatusCode::OK {
Ok(serde_json::from_str(&text).map_err(|e| anyhow!("Json error on {text}: {e}"))?)
} else { } else {
let text = res.text().await?; Err(anyhow!("API error: {text}").into())
Err(anyhow!("Post API response {text}").into())
} }
} }
@ -229,10 +231,14 @@ pub async fn follow_instance(api_instance: &str, follow_instance: &str) -> MyRes
id: instance_resolved.id, id: instance_resolved.id,
}; };
// cant use post helper because follow doesnt return json // cant use post helper because follow doesnt return json
CLIENT let res = CLIENT
.post(format!("http://{}/api/v1/instance/follow", api_instance)) .post(format!("http://{}/api/v1/instance/follow", api_instance))
.form(&follow_form) .form(&follow_form)
.send() .send()
.await?; .await?;
Ok(()) if res.status() == StatusCode::OK {
Ok(())
} else {
Err(anyhow!("API error: {}", res.text().await?).into())
}
} }