aboutsummaryrefslogtreecommitdiff
path: root/src/models/properties/tests.rs
blob: 8073c94d7e24642c8cc6411b080f9e7278ad26b8 (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
use crate::models::{
    properties::{DateOrDateTime, RollupPropertyValue, RollupValue},
    PropertyValue,
};
use chrono::NaiveDate;

#[test]
fn verify_date_parsing() {
    let date = NaiveDate::from_ymd_opt(2021, 01, 02).unwrap();
    let result = serde_json::to_string(&DateOrDateTime::Date(date)).unwrap();
    let parsed: DateOrDateTime = serde_json::from_str(&result).unwrap();
    println!("{:?}", parsed);
}

#[test]
fn parse_date_property() {
    let _property: PropertyValue =
        serde_json::from_str(include_str!("tests/date_property.json")).unwrap();
}

#[test]
fn parse_null_select_property() {
    let _property: PropertyValue =
        serde_json::from_str(include_str!("tests/null_select_property.json")).unwrap();
}

#[test]
fn parse_select_property() {
    let _property: PropertyValue =
        serde_json::from_str(include_str!("tests/select_property.json")).unwrap();
}

#[test]
fn parse_text_property_with_link() {
    let _property: PropertyValue =
        serde_json::from_str(include_str!("tests/text_with_link.json")).unwrap();
}

#[test]
fn parse_rollup_property() {
    let property: PropertyValue =
        serde_json::from_str(include_str!("tests/rollup_property.json")).unwrap();

    assert!(matches!(
        property,
        PropertyValue::Rollup {
            rollup: Some(RollupValue::Array { .. }),
            ..
        }
    ));

    if let PropertyValue::Rollup {
        rollup: Some(RollupValue::Array { array }),
        ..
    } = property
    {
        assert!(matches!(array[0], RollupPropertyValue::Text { .. }))
    }
}