]> Untitled Git - lemmy.git/blob - crates/apub/src/protocol/activities/mod.rs
Cache & Optimize Woodpecker CI (#3450)
[lemmy.git] / crates / apub / src / protocol / activities / mod.rs
1 use serde::{Deserialize, Serialize};
2 use strum_macros::Display;
3
4 pub mod block;
5 pub mod community;
6 pub mod create_or_update;
7 pub mod deletion;
8 pub mod following;
9 pub mod voting;
10
11 #[derive(Clone, Debug, Display, Deserialize, Serialize, PartialEq, Eq)]
12 pub enum CreateOrUpdateType {
13   Create,
14   Update,
15 }
16
17 #[cfg(test)]
18 mod tests {
19   #![allow(clippy::unwrap_used)]
20   #![allow(clippy::indexing_slicing)]
21
22   use crate::protocol::{
23     activities::{
24       community::announce::AnnounceActivity,
25       create_or_update::{note::CreateOrUpdateNote, page::CreateOrUpdatePage},
26       deletion::delete::Delete,
27       following::{follow::Follow, undo_follow::UndoFollow},
28       voting::{undo_vote::UndoVote, vote::Vote},
29     },
30     tests::test_json,
31   };
32
33   #[test]
34   fn test_parse_smithereen_activities() {
35     test_json::<CreateOrUpdateNote>("assets/smithereen/activities/create_note.json").unwrap();
36   }
37
38   #[test]
39   fn test_parse_pleroma_activities() {
40     test_json::<CreateOrUpdateNote>("assets/pleroma/activities/create_note.json").unwrap();
41     test_json::<Delete>("assets/pleroma/activities/delete.json").unwrap();
42     test_json::<Follow>("assets/pleroma/activities/follow.json").unwrap();
43   }
44
45   #[test]
46   fn test_parse_mastodon_activities() {
47     test_json::<CreateOrUpdateNote>("assets/mastodon/activities/create_note.json").unwrap();
48     test_json::<Delete>("assets/mastodon/activities/delete.json").unwrap();
49     test_json::<Follow>("assets/mastodon/activities/follow.json").unwrap();
50     test_json::<UndoFollow>("assets/mastodon/activities/undo_follow.json").unwrap();
51     test_json::<Vote>("assets/mastodon/activities/like_page.json").unwrap();
52     test_json::<UndoVote>("assets/mastodon/activities/undo_like_page.json").unwrap();
53   }
54
55   #[test]
56   fn test_parse_lotide_activities() {
57     test_json::<Follow>("assets/lotide/activities/follow.json").unwrap();
58     test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page.json").unwrap();
59     test_json::<CreateOrUpdatePage>("assets/lotide/activities/create_page_image.json").unwrap();
60     test_json::<CreateOrUpdateNote>("assets/lotide/activities/create_note_reply.json").unwrap();
61   }
62
63   #[test]
64   fn test_parse_friendica_activities() {
65     test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_1.json").unwrap();
66     test_json::<CreateOrUpdatePage>("assets/friendica/activities/create_page_2.json").unwrap();
67     test_json::<CreateOrUpdateNote>("assets/friendica/activities/create_note.json").unwrap();
68     test_json::<CreateOrUpdateNote>("assets/friendica/activities/update_note.json").unwrap();
69     test_json::<Delete>("assets/friendica/activities/delete.json").unwrap();
70     test_json::<Vote>("assets/friendica/activities/like_page.json").unwrap();
71     test_json::<Vote>("assets/friendica/activities/dislike_page.json").unwrap();
72     test_json::<UndoVote>("assets/friendica/activities/undo_dislike_page.json").unwrap();
73   }
74
75   #[test]
76   fn test_parse_gnusocial_activities() {
77     test_json::<CreateOrUpdatePage>("assets/gnusocial/activities/create_page.json").unwrap();
78     test_json::<CreateOrUpdateNote>("assets/gnusocial/activities/create_note.json").unwrap();
79     test_json::<Vote>("assets/gnusocial/activities/like_note.json").unwrap();
80   }
81
82   #[test]
83   fn test_parse_peertube_activities() {
84     test_json::<AnnounceActivity>("assets/peertube/activities/announce_video.json").unwrap();
85   }
86 }