]> Untitled Git - lemmy.git/blob - server/src/apub/mod.rs
e28d7f1c41dcb79e2c78431c73498d8d9eb99962
[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       avatar: None,
27       published: naive_now(),
28       admin: false,
29       banned: false,
30       updated: None,
31       show_nsfw: false,
32       theme: "darkly".into(),
33       default_sort_type: SortType::Hot as i16,
34       default_listing_type: ListingType::Subscribed as i16,
35       lang: "browser".into(),
36       show_avatars: true,
37       send_notifications_to_email: false,
38     };
39
40     let person = user.as_person();
41     assert_eq!(
42       format!("https://{}/federation/u/thom", Settings::get().hostname),
43       person.object_props.id_string().unwrap()
44     );
45   }
46
47   #[test]
48   fn test_community() {
49     let community = Community {
50       id: 42,
51       name: "Test".into(),
52       title: "Test Title".into(),
53       description: Some("Test community".into()),
54       category_id: 32,
55       creator_id: 52,
56       removed: false,
57       published: naive_now(),
58       updated: Some(naive_now()),
59       deleted: false,
60       nsfw: false,
61     };
62
63     let group = community.as_group();
64     assert_eq!(
65       format!("https://{}/federation/c/Test", Settings::get().hostname),
66       group.object_props.id_string().unwrap()
67     );
68   }
69
70   #[test]
71   fn test_post() {
72     let post = Post {
73       id: 62,
74       name: "A test post".into(),
75       url: None,
76       body: None,
77       creator_id: 52,
78       community_id: 42,
79       published: naive_now(),
80       removed: false,
81       locked: false,
82       stickied: false,
83       nsfw: false,
84       deleted: false,
85       updated: None,
86     };
87
88     let page = post.as_page();
89     assert_eq!(
90       format!("https://{}/federation/post/62", Settings::get().hostname),
91       page.object_props.id_string().unwrap()
92     );
93   }
94 }
95
96 pub fn make_apub_endpoint<S: Display, T: Display>(point: S, value: T) -> String {
97   format!(
98     "https://{}/federation/{}/{}",
99     Settings::get().hostname,
100     point,
101     value
102   )
103 }