aboutsummaryrefslogtreecommitdiff
path: root/src/models/block/tests.rs
blob: 18306a6064b866d6cfa6dd83ed1146807796fe20 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#[cfg(test)]
mod tests {
    use crate::ids::{BlockId, UserId};
    use crate::models::block::{
        Block, BlockCommon, Callout, ExternalFileObject, FileOrEmojiObject, InternalFileObject,
        Text as TextBlockModel,
    };
    use crate::models::text::{Annotations, RichText, RichTextCommon, Text, TextColor};
    use crate::models::users::UserCommon;
    use crate::models::Object;
    use chrono::DateTime;
    use std::str::FromStr;

    #[test]
    fn heading_1() {
        let heading_1: Block = serde_json::from_str(include_str!("tests/heading_1.json")).unwrap();
        assert_eq!(
            heading_1,
            Block::Heading1 {
                common: BlockCommon {
                    id: BlockId::from_str("9e891834-6a03-475c-a2b8-421e17f0f3aa").unwrap(),
                    created_time: DateTime::from_str("2022-05-12T21:15:00.000Z").unwrap(),
                    last_edited_time: DateTime::from_str("2022-05-12T22:10:00.000Z").unwrap(),
                    has_children: false,
                    created_by: UserCommon {
                        id: UserId::from_str("6419f912-5293-4ea8-b2c8-9c3ce44f90e3").unwrap(),
                        name: None,
                        avatar_url: None,
                    },
                    last_edited_by: UserCommon {
                        id: UserId::from_str("6419f912-5293-4ea8-b2c8-9c3ce44f90e3").unwrap(),
                        name: None,
                        avatar_url: None,
                    },
                },
                heading_1: TextBlockModel {
                    rich_text: vec![
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: "This".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(true),
                                    color: Some(TextColor::Default),
                                    italic: Some(false),
                                    strikethrough: Some(false),
                                    underline: Some(false),
                                }),
                            },
                            text: Text {
                                content: "This".to_string(),
                                link: None,
                            },
                        },
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: " ".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(false),
                                    strikethrough: Some(false),
                                    underline: Some(false),
                                }),
                            },
                            text: Text {
                                content: " ".to_string(),
                                link: None,
                            },
                        },
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: "is".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(false),
                                    strikethrough: Some(false),
                                    underline: Some(true),
                                }),
                            },
                            text: Text {
                                content: "is".to_string(),
                                link: None,
                            },
                        },
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: " ".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(false),
                                    strikethrough: Some(false),
                                    underline: Some(false),
                                }),
                            },
                            text: Text {
                                content: " ".to_string(),
                                link: None,
                            },
                        },
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: "a".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(true),
                                    strikethrough: Some(false),
                                    underline: Some(true),
                                }),
                            },
                            text: Text {
                                content: "a".to_string(),
                                link: None,
                            },
                        },
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: " ".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(false),
                                    strikethrough: Some(false),
                                    underline: Some(false),
                                }),
                            },
                            text: Text {
                                content: " ".to_string(),
                                link: None,
                            },
                        },
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: "Heading".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(true),
                                    strikethrough: Some(false),
                                    underline: Some(false),
                                }),
                            },
                            text: Text {
                                content: "Heading".to_string(),
                                link: None,
                            },
                        },
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: " ".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(false),
                                    strikethrough: Some(false),
                                    underline: Some(false),
                                }),
                            },
                            text: Text {
                                content: " ".to_string(),
                                link: None,
                            },
                        },
                        RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: "1".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(false),
                                    strikethrough: Some(true),
                                    underline: Some(false),
                                }),
                            },
                            text: Text {
                                content: "1".to_string(),
                                link: None,
                            },
                        },
                    ]
                },
            }
        )
    }

    #[test]
    fn emoji_object() {
        let emoji_object: FileOrEmojiObject =
            serde_json::from_str(include_str!("tests/emoji_object.json")).unwrap();
        assert_eq!(
            emoji_object,
            FileOrEmojiObject::Emoji {
                emoji: "💡".to_string()
            }
        )
    }

    #[test]
    fn file_object() {
        let file_object: FileOrEmojiObject =
            serde_json::from_str(include_str!("tests/file_object.json")).unwrap();
        assert_eq!(file_object, FileOrEmojiObject::File {
            file: InternalFileObject {
                url: "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/2703e742-ace5-428c-a74d-1c587ceddc32/DiRT_Rally.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20220513%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20220513T201035Z&X-Amz-Expires=3600&X-Amz-Signature=714b49bde0b499fb8f3aae1a88a8cbd374f2b09c1d128e91cac49e85ce0e00fb&X-Amz-SignedHeaders=host&x-id=GetObject".to_string(),
                expiry_time: DateTime::from_str("2022-05-13T21:10:35.817Z").unwrap(),
            }
        })
    }

    #[test]
    fn external_file_object() {
        let external_file_object: FileOrEmojiObject =
            serde_json::from_str(include_str!("tests/external_file_object.json")).unwrap();
        assert_eq!(
            external_file_object,
            FileOrEmojiObject::External {
                external: ExternalFileObject {
                    url: "https://nerdist.com/wp-content/uploads/2020/07/maxresdefault.jpg"
                        .to_string(),
                }
            }
        )
    }

    #[test]
    fn callout() {
        let callout: Object = serde_json::from_str(include_str!("tests/callout.json")).unwrap();
        assert_eq!(
            callout,
            Object::Block {
                block: Block::Callout {
                    common: BlockCommon {
                        id: BlockId::from_str("00e8829a-a7b8-4075-884a-8f53be145d2f").unwrap(),
                        created_time: DateTime::from_str("2022-05-13T20:08:00.000Z").unwrap(),
                        last_edited_time: DateTime::from_str("2022-05-13T20:08:00.000Z").unwrap(),
                        has_children: true,
                        created_by: UserCommon {
                            id: UserId::from_str("e2507360-468c-4e0f-a928-7bbcbbb45353").unwrap(),
                            name: None,
                            avatar_url: None,
                        },
                        last_edited_by: UserCommon {
                            id: UserId::from_str("e2507360-468c-4e0f-a928-7bbcbbb45353").unwrap(),
                            name: None,
                            avatar_url: None,
                        },
                    },
                    callout: Callout {
                        rich_text: vec![RichText::Text {
                            rich_text: RichTextCommon {
                                plain_text: "Test callout".to_string(),
                                href: None,
                                annotations: Some(Annotations {
                                    bold: Some(false),
                                    code: Some(false),
                                    color: Some(TextColor::Default),
                                    italic: Some(false),
                                    strikethrough: Some(false),
                                    underline: Some(false),
                                }),
                            },
                            text: Text {
                                content: "Test callout".to_string(),
                                link: None
                            },
                        }],
                        icon: FileOrEmojiObject::Emoji {
                            emoji: "💡".to_string()
                        },
                        color: TextColor::Green,
                    },
                }
            }
        )
    }
}