]> Untitled Git - lemmy.git/blob - server/src/apub/mod.rs
Changing to new lemmynet repo location.
[lemmy.git] / server / src / apub / mod.rs
1 pub mod community;
2 pub mod post;
3 pub mod user;
4 use crate::Settings;
5
6 use std::fmt::Display;
7
8 #[cfg(test)]
9 mod tests {
10   use crate::db::community::Community;
11   use crate::db::post::Post;
12   use crate::db::user::User_;
13   use crate::db::{ListingType, SortType};
14   use crate::{naive_now, Settings};
15
16   #[test]
17   fn test_person() {
18     let user = User_ {
19       id: 52,
20       name: "thom".into(),
21       fedi_name: "rrf".into(),
22       preferred_username: None,
23       password_encrypted: "here".into(),
24       email: None,
25       matrix_user_id: 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       embed_title: None,
87       embed_description: None,
88       embed_html: None,
89       thumbnail_url: None,
90     };
91
92     let page = post.as_page();
93     assert_eq!(
94       format!("https://{}/federation/post/62", Settings::get().hostname),
95       page.object_props.id_string().unwrap()
96     );
97   }
98 }
99
100 pub fn make_apub_endpoint<S: Display, T: Display>(point: S, value: T) -> String {
101   format!(
102     "https://{}/federation/{}/{}",
103     Settings::get().hostname,
104     point,
105     value
106   )
107 }