]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/objects/mod.rs
Add federation tests for Friendica, improve parsing of source field (fixes #2057...
[lemmy.git] / crates / apub / src / protocol / objects / mod.rs
1 use serde::{Deserialize, Serialize};
2 use url::Url;
3
4 pub(crate) mod chat_message;
5 pub(crate) mod group;
6 pub(crate) mod note;
7 pub(crate) mod page;
8 pub(crate) mod person;
9 pub(crate) mod tombstone;
10
11 #[derive(Clone, Debug, Deserialize, Serialize)]
12 #[serde(rename_all = "camelCase")]
13 pub struct Endpoints {
14   pub shared_inbox: Url,
15 }
16
17 #[cfg(test)]
18 mod tests {
19   use crate::{
20     context::WithContext,
21     objects::tests::file_to_json_object,
22     protocol::{
23       objects::{
24         chat_message::ChatMessage,
25         group::Group,
26         note::Note,
27         page::Page,
28         person::Person,
29         tombstone::Tombstone,
30       },
31       tests::test_parse_lemmy_item,
32     },
33   };
34
35   #[actix_rt::test]
36   async fn test_parse_object_lemmy() {
37     test_parse_lemmy_item::<Person>("assets/lemmy/objects/person.json").unwrap();
38     test_parse_lemmy_item::<Group>("assets/lemmy/objects/group.json").unwrap();
39     test_parse_lemmy_item::<Page>("assets/lemmy/objects/page.json").unwrap();
40     test_parse_lemmy_item::<Note>("assets/lemmy/objects/note.json").unwrap();
41     test_parse_lemmy_item::<ChatMessage>("assets/lemmy/objects/chat_message.json").unwrap();
42     test_parse_lemmy_item::<Tombstone>("assets/lemmy/objects/tombstone.json").unwrap();
43   }
44
45   #[actix_rt::test]
46   async fn test_parse_object_pleroma() {
47     file_to_json_object::<WithContext<Person>>("assets/pleroma/objects/person.json").unwrap();
48     file_to_json_object::<WithContext<Note>>("assets/pleroma/objects/note.json").unwrap();
49     file_to_json_object::<WithContext<ChatMessage>>("assets/pleroma/objects/chat_message.json")
50       .unwrap();
51   }
52
53   #[actix_rt::test]
54   async fn test_parse_object_smithereen() {
55     file_to_json_object::<WithContext<Person>>("assets/smithereen/objects/person.json").unwrap();
56     file_to_json_object::<Note>("assets/smithereen/objects/note.json").unwrap();
57   }
58
59   #[actix_rt::test]
60   async fn test_parse_object_mastodon() {
61     file_to_json_object::<WithContext<Person>>("assets/mastodon/objects/person.json").unwrap();
62     file_to_json_object::<WithContext<Note>>("assets/mastodon/objects/note.json").unwrap();
63   }
64
65   #[actix_rt::test]
66   async fn test_parse_object_lotide() {
67     file_to_json_object::<WithContext<Group>>("assets/lotide/objects/group.json").unwrap();
68     file_to_json_object::<WithContext<Person>>("assets/lotide/objects/person.json").unwrap();
69     file_to_json_object::<WithContext<Note>>("assets/lotide/objects/note.json").unwrap();
70     file_to_json_object::<WithContext<Page>>("assets/lotide/objects/page.json").unwrap();
71     file_to_json_object::<WithContext<Tombstone>>("assets/lotide/objects/tombstone.json").unwrap();
72   }
73
74   #[actix_rt::test]
75   async fn test_parse_object_friendica() {
76     file_to_json_object::<WithContext<Person>>("assets/friendica/objects/person.json").unwrap();
77     file_to_json_object::<WithContext<Note>>("assets/friendica/objects/note.json").unwrap();
78   }
79 }