]> Untitled Git - lemmy.git/blob - server/src/apub/mod.rs
7a8b74f289c19bc17e1b6b0aeeaf7125c400fa37
[lemmy.git] / server / src / apub / mod.rs
1 pub mod community;
2 pub mod post;
3 pub mod puller;
4 pub mod user;
5 use crate::Settings;
6
7 use std::fmt::Display;
8
9 #[cfg(test)]
10 mod tests {
11   use crate::db::community::Community;
12   use crate::db::post::Post;
13   use crate::db::user::User_;
14   use crate::db::{ListingType, SortType};
15   use crate::{naive_now, Settings};
16
17   #[test]
18   fn test_person() {
19     let user = User_ {
20       id: 52,
21       name: "thom".into(),
22       fedi_name: "rrf".into(),
23       preferred_username: None,
24       password_encrypted: "here".into(),
25       email: None,
26       matrix_user_id: None,
27       avatar: None,
28       published: naive_now(),
29       admin: false,
30       banned: false,
31       updated: None,
32       show_nsfw: false,
33       theme: "darkly".into(),
34       default_sort_type: SortType::Hot as i16,
35       default_listing_type: ListingType::Subscribed as i16,
36       lang: "browser".into(),
37       show_avatars: true,
38       send_notifications_to_email: false,
39     };
40
41     let person = user.as_person();
42     assert_eq!(
43       format!("https://{}/federation/u/thom", Settings::get().hostname),
44       person.object_props.id_string().unwrap()
45     );
46   }
47
48   #[test]
49   fn test_community() {
50     let community = Community {
51       id: 42,
52       name: "Test".into(),
53       title: "Test Title".into(),
54       description: Some("Test community".into()),
55       category_id: 32,
56       creator_id: 52,
57       removed: false,
58       published: naive_now(),
59       updated: Some(naive_now()),
60       deleted: false,
61       nsfw: false,
62     };
63
64     let group = community.as_group();
65     assert_eq!(
66       format!("https://{}/federation/c/Test", Settings::get().hostname),
67       group.object_props.id_string().unwrap()
68     );
69   }
70
71   #[test]
72   fn test_post() {
73     let post = Post {
74       id: 62,
75       name: "A test post".into(),
76       url: None,
77       body: None,
78       creator_id: 52,
79       community_id: 42,
80       published: naive_now(),
81       removed: false,
82       locked: false,
83       stickied: false,
84       nsfw: false,
85       deleted: false,
86       updated: None,
87     };
88
89     let page = post.as_page();
90     assert_eq!(
91       format!("https://{}/federation/post/62", Settings::get().hostname),
92       page.object_props.id_string().unwrap()
93     );
94   }
95 }
96
97 pub fn make_apub_endpoint<S: Display, T: Display>(point: S, value: T) -> String {
98   format!(
99     "https://{}/federation/{}/{}",
100     Settings::get().hostname,
101     point,
102     value
103   )
104 }