mirror of https://github.com/LemmyNet/lemmy.git
Dont fetch community outbox/moderators during tests
parent
795ad7a65d
commit
5504efa4a6
|
@ -33,9 +33,9 @@
|
|||
"url": "https://lemmy.ml/pictrs/image/waqyZwLAy4.webp"
|
||||
},
|
||||
"sensitive": false,
|
||||
"moderators": "https://lemmy.ml/c/announcements/moderators",
|
||||
"moderators": "https://lemmy.ml/c/announcements/not_moderators",
|
||||
"inbox": "https://lemmy.ml/c/announcements/inbox",
|
||||
"outbox": "https://lemmy.ml/c/announcements/outbox",
|
||||
"outbox": "https://lemmy.ml/c/announcements/not_outbox",
|
||||
"followers": "https://lemmy.ml/c/announcements/followers",
|
||||
"endpoints": {
|
||||
"sharedInbox": "https://lemmy.ml/inbox"
|
||||
|
|
|
@ -36,6 +36,7 @@ use lemmy_utils::{
|
|||
LemmyError,
|
||||
};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use log::debug;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
use std::ops::Deref;
|
||||
|
@ -263,11 +264,19 @@ impl FromApub for ApubCommunity {
|
|||
) -> Result<ApubCommunity, LemmyError> {
|
||||
let form = Group::from_apub_to_form(group, expected_domain, &context.settings()).await?;
|
||||
|
||||
// Fetching mods and outbox is not necessary for Lemmy to work, so ignore errors. Besides,
|
||||
// we need to ignore these errors so that tests can work entirely offline.
|
||||
let community = blocking(context.pool(), move |conn| Community::upsert(conn, &form)).await??;
|
||||
update_community_mods(group, &community, context, request_counter).await?;
|
||||
update_community_mods(group, &community, context, request_counter)
|
||||
.await
|
||||
.map_err(|e| debug!("{}", e))
|
||||
.ok();
|
||||
|
||||
// TODO: doing this unconditionally might cause infinite loop for some reason
|
||||
fetch_community_outbox(context, &group.outbox, request_counter).await?;
|
||||
fetch_community_outbox(context, &group.outbox, request_counter)
|
||||
.await
|
||||
.map_err(|e| debug!("{}", e))
|
||||
.ok();
|
||||
|
||||
Ok(community.into())
|
||||
}
|
||||
|
@ -326,9 +335,7 @@ mod tests {
|
|||
assert!(community.public_key.is_some());
|
||||
assert!(!community.local);
|
||||
assert_eq!(community.description.as_ref().unwrap().len(), 126);
|
||||
// TODO: its fetching the outbox, mod collection, and probably users from the outbox. due to
|
||||
// caching and other things, this may change over multiple runs, so we cant assert it.
|
||||
// find a way to avoid any network requests
|
||||
//assert_eq!(request_counter, 4);
|
||||
// this makes two requests to the (intentionally) broken outbox/moderators collections
|
||||
assert_eq!(request_counter, 2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -291,12 +291,16 @@ mod tests {
|
|||
async fn test_fetch_lemmy_post() {
|
||||
let context = init_context();
|
||||
let url = Url::parse("https://lemmy.ml/post/55143").unwrap();
|
||||
let mut request_counter = -20;
|
||||
let community_json = file_to_json_object("assets/lemmy-community.json");
|
||||
ApubCommunity::from_apub(&community_json, &context, &url, &mut request_counter)
|
||||
ApubCommunity::from_apub(&community_json, &context, &url, &mut 0)
|
||||
.await
|
||||
.unwrap();
|
||||
let person_json = file_to_json_object("assets/lemmy-person.json");
|
||||
ApubPerson::from_apub(&person_json, &context, &url, &mut 0)
|
||||
.await
|
||||
.unwrap();
|
||||
let json = file_to_json_object("assets/lemmy-post.json");
|
||||
let mut request_counter = 0;
|
||||
let post = ApubPost::from_apub(&json, &context, &url, &mut request_counter)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -308,6 +312,6 @@ mod tests {
|
|||
assert!(!post.locked);
|
||||
assert!(post.stickied);
|
||||
// see comment in test_fetch_lemmy_community() about this
|
||||
//assert_eq!(request_counter, 5);
|
||||
assert_eq!(request_counter, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ curl -H "Accept: application/activity+json" https://lemmy.ml/u/nutomic | jq \
|
|||
> crates/apub/assets/lemmy-person.json
|
||||
curl -H "Accept: application/activity+json" https://lemmy.ml/c/announcements | jq \
|
||||
> crates/apub/assets/lemmy-community.json
|
||||
# replace these collection links so that tests dont make any actual http requests
|
||||
sed -i 's/https:\/\/lemmy.ml\/c\/announcements\/outbox/https:\\/\\/lemmy.ml\\/c\\/announcements\\/not_outbox/g' crates/apub/assets/lemmy-community.json
|
||||
sed -i 's/https:\/\/lemmy.ml\/c\/announcements\/moderators/https:\\/\\/lemmy.ml\\/c\\/announcements\\/not_moderators/g' crates/apub/assets/lemmy-community.json
|
||||
curl -H "Accept: application/activity+json" https://lemmy.ml/post/55143 | jq \
|
||||
> crates/apub/assets/lemmy-post.json
|
||||
curl -H "Accept: application/activity+json" https://queer.hacktivis.me/users/lanodan | jq \
|
||||
|
|
Loading…
Reference in New Issue