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
//! Mapping for the [frnic-2.0
//! extension](https://www.afnic.fr/wp-media/uploads/2022/10/guide_d_integration_technique_EN_FRandoverseasTLD_30_09_VF.pdf)
use instant_xml::{FromXml, ToXml};

pub mod contact;

pub use contact::ContactCreate;

pub const XMLNS: &str = "http://www.afnic.fr/xml/epp/frnic-2.0";

#[derive(Debug, FromXml, ToXml)]
#[xml(rename = "ext", ns(XMLNS))]
pub struct Ext<T> {
    pub data: T,
}

#[derive(Debug, FromXml, ToXml)]
#[xml(rename = "create", ns(XMLNS))]
pub struct Create<T> {
    pub data: T,
}

#[cfg(test)]
mod tests {
    use crate::contact::ContactCreate;
    use crate::contact::{Address, PostalInfo, Voice};
    use crate::extensions::frnic;
    use crate::tests::assert_serialized;
    use frnic::{contact, Ext};

    #[test]
    fn test_contact_create_natural_person() {
        // Technical Integration Guide, page 23.
        let frnic_contact = Ext::from(frnic::ContactCreate::new_natural_person("Michel"));
        let object = ContactCreate::new(
            "XXX000",
            "test@test.fr",
            PostalInfo::new(
                "loc",
                "Dupont",
                None,
                Address::new(
                    &["1 Rue des fleurs"],
                    "Paris",
                    None,
                    Some("75000"),
                    "FR".parse().unwrap(),
                ),
            ),
            Some(Voice::new("+33.1234567890")),
            "Afn-12345678",
        );
        assert_serialized(
            "request/extensions/frnic_create_contact_natural_person.xml",
            (&object, &frnic_contact),
        );
    }

    #[test]
    fn test_contact_create_company() {
        // Technical Integration Guide, page 27.
        let frnic_contact = Ext::from(frnic::ContactCreate::new_company(
            None, None, None, None, None,
        ));
        let object = ContactCreate::new(
            "XXXXXXX",
            "test@test.fr",
            PostalInfo::new(
                "loc",
                "SARL DUPONT",
                None,
                Address::new(
                    &["1 Rue des coquelicots"],
                    "Paris",
                    None,
                    Some("75000"),
                    "FR".parse().unwrap(),
                ),
            ),
            Some(Voice::new("+33.1234567890")),
            "Afn-123456",
        );
        assert_serialized(
            "request/extensions/frnic_create_contact_company.xml",
            (&object, &frnic_contact),
        );
    }

    #[test]
    fn test_contact_create_corporation_with_siren() {
        // Technical Integration Guide, page 28.
        let frnic_contact = Ext::from(frnic::ContactCreate::new_company(
            Some("123456789"),
            None,
            None,
            None,
            None,
        ));
        let object = ContactCreate::new(
            "XXXX0000",
            "test@test.fr",
            PostalInfo::new(
                "loc",
                "SARL DUPONT SIREN",
                None,
                Address::new(
                    &["1 Rue des Sirenes"],
                    "Paris",
                    None,
                    Some("75000"),
                    "FR".parse().unwrap(),
                ),
            ),
            Some(Voice::new("+33.1234567890")),
            "Afn-123456",
        );
        assert_serialized(
            "request/extensions/frnic_create_contact_siren.xml",
            (&object, &frnic_contact),
        );
    }

    #[test]
    fn test_contact_create_non_profit() {
        // Technical Integration Guide, page 38.
        let frnic_contact = Ext::from(frnic::ContactCreate::new_non_profit(
            None,
            Some("2011-05-02"),
            Some(contact::Publication {
                announce: 123456,
                page: 15,
                date: "2011-05-07".into(),
            }),
        ));
        let object = ContactCreate::new(
            "XXXX0000",
            "test@test.fr",
            PostalInfo::new(
                "loc",
                "Dupont JO",
                None,
                Address::new(
                    &["1 Rue des Fleurs"],
                    "Paris",
                    None,
                    Some("75000"),
                    "FR".parse().unwrap(),
                ),
            ),
            Some(Voice::new("+33.1234567890")),
            "Afn-123456",
        );
        assert_serialized(
            "request/extensions/frnic_create_contact_non_profit.xml",
            (&object, &frnic_contact),
        );
    }
}