1 use crate::protocol::Source;
2 use html2md::parse_html;
8 pub mod private_message;
10 pub(crate) fn get_summary_from_string_or_source(
12 source: &Option<Source>,
14 if let Some(source) = &source {
15 Some(source.content.clone())
17 raw.as_ref().map(|s| parse_html(s))
22 pub(crate) mod tests {
24 use background_jobs::QueueHandle;
26 r2d2::{ConnectionManager, Pool},
29 use lemmy_db_schema::{
30 establish_unpooled_connection,
31 get_database_url_from_env,
32 source::secret::Secret,
35 rate_limit::{rate_limiter::RateLimiter, RateLimit},
36 request::build_user_agent,
37 settings::structs::Settings,
40 use lemmy_websocket::{chat_server::ChatServer, LemmyContext};
42 use serde::de::DeserializeOwned;
43 use std::{fs::File, io::BufReader, sync::Arc};
44 use tokio::sync::Mutex;
46 // TODO: would be nice if we didnt have to use a full context for tests.
47 // or at least write a helper function so this code is shared with main.rs
48 pub(crate) fn init_context(activity_queue: QueueHandle) -> LemmyContext {
49 // call this to run migrations
50 establish_unpooled_connection();
51 let settings = Settings::init().unwrap();
52 let rate_limiter = RateLimit {
53 rate_limiter: Arc::new(Mutex::new(RateLimiter::default())),
54 rate_limit_config: settings.rate_limit.to_owned().unwrap_or_default(),
56 let client = Client::builder()
57 .user_agent(build_user_agent(&settings))
62 jwt_secret: "".to_string(),
64 let db_url = match get_database_url_from_env() {
66 Err(_) => settings.get_database_url(),
68 let manager = ConnectionManager::<PgConnection>::new(&db_url);
69 let pool = Pool::builder()
70 .max_size(settings.database.pool_size)
72 .unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
73 async fn x() -> Result<String, LemmyError> {
76 let chat_server = ChatServer::startup(
79 |_, _, _, _| Box::pin(x()),
80 |_, _, _, _| Box::pin(x()),
82 activity_queue.clone(),
87 LemmyContext::create(pool, chat_server, client, activity_queue, settings, secret)
90 pub(crate) fn file_to_json_object<T: DeserializeOwned>(path: &str) -> T {
91 let file = File::open(path).unwrap();
92 let reader = BufReader::new(file);
93 serde_json::from_reader(reader).unwrap()