|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Class PilotApiClientTest |
|
4
|
|
|
* |
|
5
|
|
|
* @author Mauro Moreno <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace Zephia\PilotApiClient\Tests\Client; |
|
8
|
|
|
|
|
9
|
|
|
use GuzzleHttp\Stream\Stream; |
|
10
|
|
|
use Zephia\PilotApiClient\Client\PilotApiClient; |
|
11
|
|
|
use GuzzleHttp\Client; |
|
12
|
|
|
use GuzzleHttp\Subscriber\Mock; |
|
13
|
|
|
use GuzzleHttp\Message\Response; |
|
14
|
|
|
use Zephia\PilotApiClient\Exception\InvalidArgumentException; |
|
15
|
|
|
use Zephia\PilotApiClient\Model\LeadData; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class NominatimClientTest |
|
19
|
|
|
* @package MauroMoreno\Client\Tests\Client |
|
20
|
|
|
*/ |
|
21
|
|
|
class PilotApiClientTest extends \PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Test valid client |
|
25
|
|
|
*/ |
|
26
|
|
|
public function testValidClient() |
|
27
|
|
|
{ |
|
28
|
|
|
$client = new PilotApiClient(); |
|
29
|
|
|
$this->assertInstanceOf(Client::class, $client->getGuzzleClient()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @expectedException InvalidArgumentException |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testLeadDataIsEmpty() |
|
36
|
|
|
{ |
|
37
|
|
|
$client = new PilotApiClient(); |
|
38
|
|
|
$client->storeLead(new LeadData()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @expectedException InvalidArgumentException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function testStoreLeadAppKeyIsEmpty() |
|
45
|
|
|
{ |
|
46
|
|
|
$client = new PilotApiClient([ |
|
47
|
|
|
'debug' => true |
|
48
|
|
|
]); |
|
49
|
|
|
$mock = new Mock([new Response(200, [], Stream::factory('Error capturado: Missing argument 5 for logCall(), called in C:\Inetpub\vhosts\dragon686.startdedicated.com\httpdocs\api\webhooks\welcome.php on line 141 and defined<br />Error capturado: Undefined variable: ipcliente<br />{"success":false,"message":"Error","data":"No se indico el parametro requerido appKey"}'))]); |
|
50
|
|
|
$client->getGuzzleClient()->getEmitter()->attach($mock); |
|
51
|
|
|
$client->storeLead(new LeadData([ |
|
52
|
|
|
'firstname' => 'Test', |
|
53
|
|
|
'lastname' => 'Test', |
|
54
|
|
|
'contact_type_id' => 1, |
|
55
|
|
|
'business_type_id' => 1, |
|
56
|
|
|
'suborigin_id' => "FFFF0000", |
|
57
|
|
|
])); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @expectedException InvalidArgumentException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function testStoreLeadAppKeyIsWrong() |
|
64
|
|
|
{ |
|
65
|
|
|
$client = new PilotApiClient([ |
|
66
|
|
|
'debug' => true, |
|
67
|
|
|
'app_key' => 'APP-WRONG-KEY' |
|
68
|
|
|
]); |
|
69
|
|
|
$mock = new Mock([new Response(200, [], Stream::factory('Error capturado: Missing argument 5 for logCall(), called in C:\Inetpub\vhosts\dragon686.startdedicated.com\httpdocs\api\webhooks\welcome.php on line 141 and defined<br />Error capturado: Undefined variable: ipcliente<br />{"success":false,"message":"Error","data":"No se encontro la key APP-WRONG-KEY"}'))]); |
|
70
|
|
|
$client->getGuzzleClient()->getEmitter()->attach($mock); |
|
71
|
|
|
$client->storeLead(new LeadData([ |
|
72
|
|
|
'firstname' => 'Test', |
|
73
|
|
|
'lastname' => 'Test', |
|
74
|
|
|
'contact_type_id' => 1, |
|
75
|
|
|
'business_type_id' => 1, |
|
76
|
|
|
'suborigin_id' => "FFFF0000", |
|
77
|
|
|
])); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @expectedException InvalidArgumentException |
|
82
|
|
|
*/ |
|
83
|
|
|
public function testStoreLeadWrongSuboriginId() |
|
84
|
|
|
{ |
|
85
|
|
|
$client = new PilotApiClient([ |
|
86
|
|
|
'debug' => true, |
|
87
|
|
|
'app_key' => 'APP-KEY' |
|
88
|
|
|
]); |
|
89
|
|
|
$mock = new Mock([new Response(200, [], Stream::factory('Error capturado: Missing argument 5 for logCall(), called in C:\Inetpub\vhosts\dragon686.startdedicated.com\httpdocs\api\webhooks\welcome.php on line 141 and defined<br />Error capturado: Undefined variable: ipcliente<br />{"success":false,"message":"Error","data":"(3.0) El codigo de origen del dato FFFF0000no existe."}'))]); |
|
90
|
|
|
$client->getGuzzleClient()->getEmitter()->attach($mock); |
|
91
|
|
|
$client->storeLead(new LeadData([ |
|
92
|
|
|
'firstname' => 'Test', |
|
93
|
|
|
'phone' => '123456', |
|
94
|
|
|
'contact_type_id' => 1, |
|
95
|
|
|
'business_type_id' => 1, |
|
96
|
|
|
'suborigin_id' => "WRONG-SUB-ORIGIN-ID", |
|
97
|
|
|
])); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testStoreLeadDebugOk() |
|
101
|
|
|
{ |
|
102
|
|
|
$client = new PilotApiClient([ |
|
103
|
|
|
'debug' => true, |
|
104
|
|
|
'app_key' => 'APP-KEY' |
|
105
|
|
|
]); |
|
106
|
|
|
$mock = new Mock([new Response(200, [], Stream::factory('{"success":true,"message":"Success","data":{"message":"(3.0) El servicio de carga de datos se ejecuto correctamente en modo DEBUG.","success":true}}'))]); |
|
107
|
|
|
$client->getGuzzleClient()->getEmitter()->attach($mock); |
|
108
|
|
|
$response = $client->storeLead(new LeadData([ |
|
109
|
|
|
'firstname' => 'Test', |
|
110
|
|
|
'phone' => '123456', |
|
111
|
|
|
'contact_type_id' => 1, |
|
112
|
|
|
'business_type_id' => 1, |
|
113
|
|
|
'suborigin_id' => "FFFF0000", |
|
114
|
|
|
])); |
|
115
|
|
|
$this->assertTrue($response->success); |
|
116
|
|
|
$this->assertEquals('Success', $response->message); |
|
117
|
|
|
$this->assertEquals('(3.0) El servicio de carga de datos se ejecuto correctamente en modo DEBUG.', $response->data->message); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function testStoreLeadOk() |
|
121
|
|
|
{ |
|
122
|
|
|
$client = new PilotApiClient([ |
|
123
|
|
|
'debug' => false, |
|
124
|
|
|
'app_key' => 'APP-KEY' |
|
125
|
|
|
]); |
|
126
|
|
|
$mock = new Mock([new Response(200, [], Stream::factory('{"success":true,"message":"Success","data":{"message":"(3.2) El servicio de carga de datos se ejecuto correctamente.","assigned_user_id":1234,"success":true,"id":1}}'))]); |
|
127
|
|
|
$client->getGuzzleClient()->getEmitter()->attach($mock); |
|
128
|
|
|
$response = $client->storeLead(new LeadData([ |
|
129
|
|
|
'firstname' => 'Test', |
|
130
|
|
|
'phone' => '123456', |
|
131
|
|
|
'contact_type_id' => 1, |
|
132
|
|
|
'business_type_id' => 1, |
|
133
|
|
|
'suborigin_id' => "FFFF0000", |
|
134
|
|
|
])); |
|
135
|
|
|
$this->assertTrue($response->success); |
|
136
|
|
|
$this->assertEquals('Success', $response->message); |
|
137
|
|
|
$this->assertEquals('(3.2) El servicio de carga de datos se ejecuto correctamente.', $response->data->message); |
|
138
|
|
|
$this->assertEquals(1234, $response->data->assigned_user_id); |
|
139
|
|
|
$this->assertEquals(1, $response->data->id); |
|
140
|
|
|
} |
|
141
|
|
|
} |