mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
no network requests in test
This commit is contained in:
parent
dbeeb755d1
commit
dc7b391313
@ -76,7 +76,7 @@ impl LemmyContext {
|
||||
.app_data(context)
|
||||
.debug(true)
|
||||
// Dont allow any network fetches
|
||||
.http_fetch_limit(10)
|
||||
.http_fetch_limit(0)
|
||||
.build()
|
||||
.await
|
||||
.expect("build federation config")
|
||||
|
@ -310,7 +310,7 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
#[expect(clippy::indexing_slicing)]
|
||||
mod tests {
|
||||
pub(crate) mod tests {
|
||||
|
||||
use crate::api::user_settings_backup::{export_settings, import_settings, UserSettingsBackup};
|
||||
use activitypub_federation::config::Data;
|
||||
@ -332,7 +332,7 @@ mod tests {
|
||||
use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
|
||||
async fn create_user(
|
||||
pub(crate) async fn create_user(
|
||||
name: String,
|
||||
bio: Option<String>,
|
||||
context: &Data<LemmyContext>,
|
||||
|
@ -105,54 +105,81 @@ async fn format_actor_url(
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use crate::api::user_settings_backup::tests::create_user;
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
community::{Community, CommunityInsertForm},
|
||||
post::{Post, PostInsertForm},
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_markdown_rewrite_remote_post_links() {
|
||||
async fn test_markdown_rewrite_remote_links() -> LemmyResult<()> {
|
||||
let context = LemmyContext::init_test_context().await;
|
||||
let instance = Instance::read_or_create(&mut context.pool(), "example.com".to_string()).await?;
|
||||
let community = Community::create(
|
||||
&mut context.pool(),
|
||||
&CommunityInsertForm::new(
|
||||
instance.id,
|
||||
"my_community".to_string(),
|
||||
"My Community".to_string(),
|
||||
"pubkey".to_string(),
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
dbg!(&community.actor_id);
|
||||
let user = create_user("john".to_string(), None, &context).await?;
|
||||
let post_form = PostInsertForm {
|
||||
..PostInsertForm::new("My post".to_string(), user.person.id, community.id)
|
||||
};
|
||||
let post = Post::create(&mut context.pool(), &post_form).await?;
|
||||
dbg!(&post.ap_id);
|
||||
let tests: Vec<_> = vec![
|
||||
(
|
||||
"rewrite remote link",
|
||||
"[link](https://feddit.org/post/3172593)",
|
||||
format!("[link]({})", post.ap_id),
|
||||
"[link](https://lemmy-alpha/post/1)",
|
||||
),
|
||||
(
|
||||
"rewrite community link",
|
||||
"[link](https://feddit.org/c/dach)",
|
||||
"[link](https://lemmy-alpha/c/dach@feddit.org)",
|
||||
format!("[link]({})", community.actor_id),
|
||||
"[link](https://lemmy-alpha/c/my_community@example.com)",
|
||||
),
|
||||
(
|
||||
"dont rewrite local post link",
|
||||
"[link](https://lemmy-alpha/post/2)",
|
||||
"[link](https://lemmy-alpha/post/2)".to_string(),
|
||||
"[link](https://lemmy-alpha/post/2)",
|
||||
),
|
||||
(
|
||||
"dont rewrite local community link",
|
||||
"[link](https://lemmy-alpha/c/test)",
|
||||
"[link](https://lemmy-alpha/c/test)".to_string(),
|
||||
"[link](https://lemmy-alpha/c/test)",
|
||||
),
|
||||
(
|
||||
"dont rewrite non-fediverse link",
|
||||
"[link](https://example.com/)",
|
||||
"[link](https://example.com/)".to_string(),
|
||||
"[link](https://example.com/)",
|
||||
),
|
||||
(
|
||||
"dont rewrite invalid url",
|
||||
"[link](example-com)",
|
||||
"[link](example-com)".to_string(),
|
||||
"[link](example-com)",
|
||||
),
|
||||
];
|
||||
|
||||
let context = LemmyContext::init_test_context().await;
|
||||
for &(msg, input, expected) in &tests {
|
||||
for (msg, input, expected) in &tests {
|
||||
let result = markdown_rewrite_remote_links(input.to_string(), &context).await;
|
||||
|
||||
assert_eq!(
|
||||
result, expected,
|
||||
&result, expected,
|
||||
"Testing {}, with original input '{}'",
|
||||
msg, input
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user