22
33namespace Intercom ;
44
5- use Guzzle \Tests \GuzzleTestCase ;
6-
75class UserTest extends IntercomTestCase
86{
97 public function testGetUserByID ()
108 {
119 $ this ->setMockResponse ($ this ->client , 'User/User.txt ' );
12- $ response = $ this ->client ->getUser (["id " => "123456 " ]);
10+ $ response = $ this ->client ->getUser (['id ' => '123456 ' ]);
11+
12+ $ this ->assertBasicAuth ('my-app ' , '1234 ' );
13+ $ this ->assertRequest ('GET ' , '/users/123456 ' );
14+
1315 $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
14- $ this ->assertEquals ('Joe Schmoe ' , $ response [" name " ]);
16+ $ this ->assertEquals ('Joe Schmoe ' , $ response [' name ' ]);
1517 }
1618
1719 public function testGetUserByEmail ()
1820 {
1921 $ this ->setMockResponse ($ this ->client , 'User/User.txt ' );
20- $ response = $ this ->
client ->
getUser ([
" email " =>
" [email protected] " ]);
21- $ this -> assertInstanceOf ( ' \Guzzle\Service\Resource\Model ' , $ response );
22- $ this ->assertEquals ( ' Joe Schmoe ' , $ response [ " name " ] );
22+ $ this ->
client ->
getUser ([
' email ' =>
' [email protected] ' ]);
23+
24+ $ this ->assertRequest ( ' GET ' , ' /users/?email=a%40example.org ' );
2325 }
2426
2527 public function testGetUserByUserID ()
2628 {
2729 $ this ->setMockResponse ($ this ->client , 'User/User.txt ' );
28- $ response = $ this ->client ->getUser ([" user_id " => " hgsdfhsasdfg " ]);
29- $ this -> assertInstanceOf ( ' \Guzzle\Service\Resource\Model ' , $ response );
30- $ this ->assertEquals ( ' Joe Schmoe ' , $ response [ " name " ] );
30+ $ this ->client ->getUser ([' user_id ' => ' hgsdfhsasdfg ' ]);
31+
32+ $ this ->assertRequest ( ' GET ' , ' /users/?user_id=hgsdfhsasdfg ' );
3133 }
3234
3335 public function testCreateUser ()
3436 {
3537 $ this ->setMockResponse ($ this ->client , 'User/User.txt ' );
36- $ response = $ this ->client ->createUser (["id " => "123456 " ]);
38+ $ response =
$ this ->
client ->
createUser ([
'name ' =>
'Joe Schmoe ' ,
'email ' =>
'[email protected] ' ,
'hi ' =>
'hello ' ]);
39+
40+ $ this ->assertRequest ('POST ' , '/users ' );
41+ $ this ->
assertRequestJson ([
'email ' =>
'[email protected] ' ,
'name ' =>
'Joe Schmoe ' ]);
42+
3743 $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
38- $ this ->assertEquals ('Joe Schmoe ' , $ response [" name " ]);
44+ $ this ->assertEquals ('Joe Schmoe ' , $ response [' name ' ]);
3945 }
4046
4147 public function testUpdateUser ()
4248 {
4349 $ this ->setMockResponse ($ this ->client , 'User/User.txt ' );
44- $ response = $ this ->client ->updateUser (["id " => "123456 " , "updated_at " => time ()]);
50+ $ response = $ this ->client ->updateUser (['id ' => '123456 ' , 'user_id ' => '1234 ' , 'hi ' => 'hello ' ]);
51+
52+ $ this ->assertRequest ('POST ' , '/users ' );
53+ $ this ->assertRequestJson (['id ' => '123456 ' , 'user_id ' => '1234 ' ]);
54+
55+ $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
56+ $ this ->assertEquals ('Joe Schmoe ' , $ response ['name ' ]);
57+ }
58+
59+ public function testDeleteUserByID ()
60+ {
61+ $ this ->setMockResponse ($ this ->client , 'User/User.txt ' );
62+ $ response = $ this ->client ->deleteUser (['id ' => '123456 ' , 'hi ' => 'hello ' ]);
63+
64+ $ this ->assertRequest ('DELETE ' , '/users ' );
65+ $ this ->assertRequestJson (['id ' => '123456 ' ]);
66+
4567 $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
46- $ this ->assertEquals ('Joe Schmoe ' , $ response ["name " ]);
68+ $ this ->assertEquals ('Joe Schmoe ' , $ response ['name ' ]);
69+ }
70+
71+ public function testDeleteUserByEmail ()
72+ {
73+ $ this ->setMockResponse ($ this ->client , 'User/User.txt ' );
74+ $ this ->
client ->
deleteUser ([
'email ' =>
'[email protected] ' ,
'hi ' =>
'hello ' ]);
75+
76+ $ this ->assertRequest ('DELETE ' , '/users ' );
77+ $ this ->
assertRequestJson ([
'email ' =>
'[email protected] ' ]);
78+ }
79+
80+ public function testDeleteUserByUserID ()
81+ {
82+ $ this ->setMockResponse ($ this ->client , 'User/User.txt ' );
83+ $ this ->client ->deleteUser (['user_id ' => '1234 ' , 'hi ' => 'hello ' ]);
84+
85+ $ this ->assertRequest ('DELETE ' , '/users ' );
86+ $ this ->assertRequestJson (['user_id ' => '1234 ' ]);
4787 }
4888
4989 public function testGetUsers ()
5090 {
51- $ this ->setMockResponse ($ this ->client , 'User/Users .txt ' );
91+ $ this ->setMockResponse ($ this ->client , 'User/UserList .txt ' );
5292 $ response = $ this ->client ->getUsers ();
5393 $ users = $ response ->get ('users ' );
5494
95+ $ this ->assertRequest ('GET ' , '/users ' );
96+
5597 $ this ->assertInstanceOf ('\Guzzle\Service\Resource\Model ' , $ response );
98+ $ this ->assertEquals (3 , count ($ users ));
5699 $ this ->
assertEquals (
'[email protected] ' ,
$ users[
'0 ' ][
'email ' ]);
57100 $ this ->
assertEquals (
'[email protected] ' ,
$ users[
'1 ' ][
'email ' ]);
58101 $ this ->
assertEquals (
'[email protected] ' ,
$ users[
'2 ' ][
'email ' ]);
59102 }
103+
104+ public function testGetUsersByTagID ()
105+ {
106+ $ this ->setMockResponse ($ this ->client , 'User/UserList.txt ' );
107+ $ this ->client ->getUsers (['tag_id ' => '10 ' , 'hello ' =>'hi ' ]);
108+
109+ $ this ->assertRequest ('GET ' , '/users?tag_id=10 ' );
110+ }
111+
112+ public function testGetUsersBySegmentID ()
113+ {
114+ $ this ->setMockResponse ($ this ->client , 'User/UserList.txt ' );
115+ $ this ->client ->getUsers (['segment_id ' => '20 ' , 'hello ' =>'hi ' ]);
116+
117+ $ this ->assertRequest ('GET ' , '/users?segment_id=20 ' );
118+ }
119+
120+ /**
121+ * @expectedException \Guzzle\Service\Exception\ValidationException
122+ */
123+ public function testUpdateUserNoID ()
124+ {
125+ $ this ->client ->updateUser ();
126+ }
60127}
0 commit comments