33from unit import Unit
44from unit .models .customer import *
55from unit .models .codecs import DtoDecoder
6+ from e2e_tests .helpers .helpers import create_individual_customer
67
78token = os .environ .get ('TOKEN' )
89client = Unit ("https://api.s.unit.sh" , token )
910
11+ authorized_users = [
12+ {
13+ "fullName" : {
14+ "first" : "Jared" ,
15+ "last" : "Dunn"
16+ },
17+ 18+ "phone" : {
19+ "countryCode" : "1" ,
20+ "number" : "1555555590"
21+ }
22+ }
23+ ]
24+
25+
1026def get_customer_by_type (type : str ):
11- response = client .customers .list (ListCustomerParams (0 ,1000 ))
27+ response = client .customers .list (ListCustomerParams (0 , 1000 ))
1228 for c in response .data :
1329 if c .type == type :
1430 return c
1531 return None
1632
33+
1734def test_update_individual_customer ():
1835 individual_customer_id = get_customer_by_type ("individualCustomer" ).id
1936 request = PatchIndividualCustomerRequest (individual_customer_id , phone = Phone ("1" , "1115551111" ))
2037 response = client .customers .update (request )
2138 assert response .data .type == "individualCustomer"
2239
40+
2341def test_update_business_customer ():
2442 business_customer_id = get_customer_by_type ("businessCustomer" ).id
2543 request = PatchBusinessCustomerRequest (business_customer_id , phone = Phone ("1" , "1115551111" ))
2644 response = client .customers .update (request )
2745 assert response .data .type == "businessCustomer"
2846
47+
2948def test_get_customer ():
3049 customer_ids = []
3150 response = client .customers .list ()
@@ -36,6 +55,7 @@ def test_get_customer():
3655 response = client .customers .get (id )
3756 assert response .data .type == "individualCustomer" or response .data .type == "businessCustomer"
3857
58+
3959def test_list_customers ():
4060 response = client .customers .list ()
4161 for customer in response .data :
@@ -44,91 +64,58 @@ def test_list_customers():
4464
4565def test_business_customer ():
4666 business_customer_api_response = {
47- "type" : "businessCustomer" ,
48- "id" : "1" ,
49- "attributes" : {
67+ "type" : "businessCustomer" ,
68+ "id" : "1" ,
69+ "attributes" : {
5070 "createdAt" : "2020-05-10T12:28:37.698Z" ,
5171 "name" : "Pied Piper" ,
5272 "address" : {
53- "street" : "5230 Newell Rd" ,
54- "street2" : None ,
55- "city" : "Palo Alto" ,
56- "state" : "CA" ,
57- "postalCode" : "94303" ,
58- "country" : "US"
73+ "street" : "5230 Newell Rd" ,
74+ "street2" : None ,
75+ "city" : "Palo Alto" ,
76+ "state" : "CA" ,
77+ "postalCode" : "94303" ,
78+ "country" : "US"
5979 },
6080 "phone" : {
61- "countryCode" : "1" ,
62- "number" : "1555555578"
81+ "countryCode" : "1" ,
82+ "number" : "1555555578"
6383 },
6484 "stateOfIncorporation" : "DE" ,
6585 "ein" : "123456789" ,
6686 "entityType" : "Corporation" ,
6787 "contact" : {
68- "fullName" : {
69- "first" : "Richard" ,
70- "last" : "Hendricks"
71- },
72- 73- "phone" : {
74- "countryCode" : "1" ,
75- "number" : "1555555578"
76- }
77- },
78- "authorizedUsers" : [
79- {
8088 "fullName" : {
81- "first" : "Jared " ,
82- "last" : "Dunn "
89+ "first" : "Richard " ,
90+ "last" : "Hendricks "
8391 },
84- "email" : "jared @piedpiper.com" ,
92+ "email" : "richard @piedpiper.com" ,
8593 "phone" : {
86- "countryCode" : "1" ,
87- "number" : "1555555590 "
94+ "countryCode" : "1" ,
95+ "number" : "1555555578 "
8896 }
89- },
90- {
91- "fullName" : {
92- "first" : "Jared" ,
93- "last" : "Dunn"
94- },
95- 96- "phone" : {
97- "countryCode" : "1" ,
98- "number" : "1555555590"
99- }
100- },{
101- "fullName" : {
102- "first" : "Jared" ,
103- "last" : "Dunn"
104- },
105- 106- "phone" : {
107- "countryCode" : "1" ,
108- "number" : "1555555590"
109- }
110- }
111- ],
97+ },
98+ "authorizedUsers" : authorized_users ,
11299 "status" : "Active" ,
113100 "tags" : {
114- "userId" : "106a75e9-de77-4e25-9561-faffe59d7814"
101+ "userId" : "106a75e9-de77-4e25-9561-faffe59d7814"
115102 }
116- },
117- "relationships" : {
103+ },
104+ "relationships" : {
118105 "org" : {
119- "data" : {
120- "type" : "org" ,
121- "id" : "1"
122- }
106+ "data" : {
107+ "type" : "org" ,
108+ "id" : "1"
109+ }
123110 },
124111 "application" : {
125- "data" : {
126- "type" : "businessApplication" ,
127- "id" : "1"
128- }
112+ "data" : {
113+ "type" : "businessApplication" ,
114+ "id" : "1"
115+ }
129116 }
130- }
131117 }
118+ }
132119
133120 id = business_customer_api_response ["id" ]
134121 _type = business_customer_api_response ["type" ]
@@ -144,6 +131,7 @@ def test_business_customer():
144131 assert customer .attributes ["authorizedUsers" ][0 ].full_name .first == "Jared"
145132 assert customer .attributes ["status" ] == "Active"
146133
134+
147135def test_individual_customer ():
148136 individual_customer_api_response = {
149137 "type" : "individualCustomer" ,
@@ -191,7 +179,6 @@ def test_individual_customer():
191179 }
192180 }
193181
194-
195182 id = individual_customer_api_response ["id" ]
196183 _type = individual_customer_api_response ["type" ]
197184
@@ -207,3 +194,28 @@ def test_individual_customer():
207194 assert customer .attributes ["authorizedUsers" ] == []
208195 assert customer .attributes ["status" ] == "Active"
209196
197+
198+ def add_authorized_users_to_individual_customer ():
199+ individual_customer_id = create_individual_customer (client )
200+ request = AddAuthorizedUsersRequest (individual_customer_id , authorized_users )
201+ return client .customers .add_authorized_users (request )
202+
203+
204+ def test_add_authorized_users_to_individual_customer ():
205+ response = add_authorized_users_to_individual_customer ()
206+ assert response .data .type == "individualCustomer"
207+ assert len (response .data .attributes .get ("authorizedUsers" )) == 1
208+ assert response .data .attributes .get ("authorizedUsers" )[0 ].email == authorized_users [0 ].get ("email" )
209+
210+
211+ def test_remove_authorized_users_to_individual_customer ():
212+ add_response = add_authorized_users_to_individual_customer ()
213+ assert add_response .data .type == "individualCustomer"
214+ assert len (add_response .data .attributes .get ("authorizedUsers" )) == 1
215+ assert add_response .data .attributes .get ("authorizedUsers" )[0 ].email == authorized_users [0 ].get ("email" )
216+ authorized_users_emails = [authorized_users [0 ].get ("email" )]
217+ request = RemoveAuthorizedUsersRequest (add_response .data .id , authorized_users_emails )
218+ remove_response = client .customers .remove_authorized_users (request )
219+ assert remove_response .data .id == add_response .data .id
220+ assert remove_response .data .type == add_response .data .type
221+ assert len (remove_response .data .attributes .get ("authorizedUsers" )) == 0
0 commit comments