1use crate::cosmos_types::Timestamp;
4use crate::posts::types::AttachmentContent;
5use crate::posts::types::{
6 Attachment, Media, Post, PostOwnerTransferRequest,
7 QueryIncomingPostOwnerTransferRequestsResponse, QueryPollAnswersResponse,
8 QueryPostAttachmentsResponse, QueryPostResponse, QuerySectionPostsResponse,
9 QuerySubspacePostsResponse, ReplySetting, UserAnswer,
10};
11
12use chrono::DateTime;
13use cosmwasm_std::Addr;
14
15pub const MOCK_AUTHOR: &str = "author";
17
18pub const MOCK_ANSWERER: &str = "answerer";
20
21pub struct MockPostsQueries {}
24impl MockPostsQueries {
25 pub fn get_mocked_post(subspace_id: u64, section_id: u32, post_id: u64) -> Post {
27 Post {
28 subspace_id,
29 section_id,
30 id: post_id,
31 external_id: "".into(),
32 text: "test".into(),
33 entities: None,
34 tags: vec!["hello".into(), "world".into()],
35 author: MOCK_AUTHOR.into(),
36 conversation_id: 0,
37 referenced_posts: vec![],
38 reply_settings: ReplySetting::Everyone.into(),
39 creation_date: Some(Timestamp::from(DateTime::from(
40 DateTime::parse_from_rfc3339("2011-11-11T11:11:11.111Z").unwrap(),
41 ))),
42 last_edited_date: None,
43 owner: MOCK_AUTHOR.into(),
44 }
45 }
46 pub fn get_mocked_attachment(subspace_id: u64, post_id: u64, attachment_id: u32) -> Attachment {
48 Attachment {
49 subspace_id,
50 post_id,
51 id: attachment_id,
52 content: Some(
53 AttachmentContent::Media(Media {
54 uri: "ftp://domain.io/image.png".into(),
55 mime_type: "image/png".into(),
56 })
57 .into(),
58 ),
59 }
60 }
61 pub fn get_mocked_user_answer(
63 subspace_id: u64,
64 post_id: u64,
65 poll_id: u32,
66 user: Addr,
67 ) -> UserAnswer {
68 UserAnswer {
69 subspace_id,
70 post_id,
71 poll_id,
72 answers_indexes: vec![0],
73 user: user.into(),
74 }
75 }
76 pub fn get_mocked_subspace_posts(subspace_id: u64) -> Vec<Post> {
78 vec![
79 Self::get_mocked_post(subspace_id, 0, 1),
80 Self::get_mocked_post(subspace_id, 0, 2),
81 ]
82 }
83 pub fn get_mocked_subspace_posts_response() -> QuerySubspacePostsResponse {
85 QuerySubspacePostsResponse {
86 posts: Self::get_mocked_subspace_posts(1),
87 pagination: None,
88 }
89 }
90 pub fn get_mocked_section_posts(subspace_id: u64, section_id: u32) -> Vec<Post> {
92 vec![
93 Self::get_mocked_post(subspace_id, section_id, 1),
94 Self::get_mocked_post(subspace_id, section_id, 2),
95 ]
96 }
97 pub fn get_mocked_section_posts_response() -> QuerySectionPostsResponse {
99 QuerySectionPostsResponse {
100 posts: Self::get_mocked_section_posts(1, 1),
101 pagination: None,
102 }
103 }
104 pub fn get_mocked_post_response() -> QueryPostResponse {
106 QueryPostResponse {
107 post: Some(Self::get_mocked_post(1, 0, 1)),
108 }
109 }
110 pub fn get_mocked_post_attachments(subspace_id: u64, post_id: u64) -> Vec<Attachment> {
112 vec![
113 Self::get_mocked_attachment(subspace_id, post_id, 1),
114 Self::get_mocked_attachment(subspace_id, post_id, 2),
115 ]
116 }
117 pub fn get_mocked_post_attachments_response() -> QueryPostAttachmentsResponse {
119 QueryPostAttachmentsResponse {
120 attachments: Self::get_mocked_post_attachments(1, 1),
121 pagination: None,
122 }
123 }
124 pub fn get_mocked_poll_answers(
126 subspace_id: u64,
127 post_id: u64,
128 poll_id: u32,
129 ) -> Vec<UserAnswer> {
130 vec![Self::get_mocked_user_answer(
131 subspace_id,
132 post_id,
133 poll_id,
134 Addr::unchecked(MOCK_ANSWERER),
135 )]
136 }
137 pub fn get_mocked_poll_answers_response() -> QueryPollAnswersResponse {
139 QueryPollAnswersResponse {
140 answers: Self::get_mocked_poll_answers(1, 1, 1),
141 pagination: None,
142 }
143 }
144
145 pub fn get_mocked_incoming_post_transfer_requests_response(
147 ) -> QueryIncomingPostOwnerTransferRequestsResponse {
148 QueryIncomingPostOwnerTransferRequestsResponse {
149 requests: vec![PostOwnerTransferRequest {
150 subspace_id: 1,
151 post_id: 1,
152 sender: "sender".into(),
153 receiver: "receiver".into(),
154 }],
155 pagination: None,
156 }
157 }
158}