misskey_api/endpoint/notes/
reactions.rs1use crate::model::{
2 id::Id,
3 note::{Note, Reaction},
4 note_reaction::NoteReaction,
5};
6
7use serde::Serialize;
8use typed_builder::TypedBuilder;
9
10pub mod create;
11pub mod delete;
12
13#[derive(Serialize, Debug, Clone, TypedBuilder)]
14#[serde(rename_all = "camelCase")]
15#[builder(doc)]
16pub struct Request {
17 pub note_id: Id<Note>,
18 #[serde(rename = "type")]
19 #[builder(default, setter(strip_option, into))]
20 pub type_: Option<Reaction>,
21 #[serde(skip_serializing_if = "Option::is_none")]
23 #[builder(default, setter(into))]
24 pub limit: Option<u8>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 #[builder(default, setter(into))]
27 pub offset: Option<u64>,
28}
29
30impl misskey_core::Request for Request {
31 type Response = Vec<NoteReaction>;
32 const ENDPOINT: &'static str = "notes/reactions";
33}
34
35impl_offset_pagination!(Request, NoteReaction);
36
37#[cfg(test)]
38mod tests {
39 use super::Request;
40 use crate::test::{ClientExt, TestClient};
41
42 #[tokio::test]
43 async fn request_simple() {
44 let client = TestClient::new();
45 let note = client.user.create_note(Some("hello"), None, None).await;
46 client
47 .user
48 .test(Request {
49 note_id: note.id,
50 type_: None,
51 limit: None,
52 offset: None,
53 })
54 .await;
55 }
56
57 #[tokio::test]
58 async fn request_with_type() {
59 let client = TestClient::new();
60 let note = client.user.create_note(Some("hello"), None, None).await;
61 client
62 .admin
63 .test(crate::endpoint::notes::reactions::create::Request {
64 note_id: note.id,
65 reaction: "👍".into(),
66 })
67 .await;
68
69 client
70 .user
71 .test(Request {
72 note_id: note.id,
73 type_: Some("👍".into()),
74 limit: None,
75 offset: None,
76 })
77 .await;
78 }
79
80 #[tokio::test]
81 async fn request_with_limit() {
82 let client = TestClient::new();
83 let note = client.user.create_note(Some("hello"), None, None).await;
84 client
85 .admin
86 .test(crate::endpoint::notes::reactions::create::Request {
87 note_id: note.id,
88 reaction: "👍".into(),
89 })
90 .await;
91
92 client
93 .user
94 .test(Request {
95 note_id: note.id,
96 type_: None,
97 limit: Some(100),
98 offset: None,
99 })
100 .await;
101 }
102
103 #[tokio::test]
104 async fn request_with_offset() {
105 let client = TestClient::new();
106 let note = client.user.create_note(Some("hello"), None, None).await;
107 client
108 .admin
109 .test(crate::endpoint::notes::reactions::create::Request {
110 note_id: note.id,
111 reaction: "👍".into(),
112 })
113 .await;
114
115 client
116 .user
117 .test(Request {
118 note_id: note.id,
119 type_: None,
120 limit: None,
121 offset: Some(1),
122 })
123 .await;
124 }
125}