1 | <?php |
||
2 | |||
3 | namespace MauticPlugin\MauticCrmBundle\Tests\Pipedrive\Import; |
||
4 | |||
5 | use Mautic\LeadBundle\Entity\Lead; |
||
6 | use MauticPlugin\MauticCrmBundle\Tests\Pipedrive\PipedriveTest; |
||
7 | |||
8 | class LeadTest extends PipedriveTest |
||
9 | { |
||
10 | private $features = [ |
||
11 | 'objects' => [ |
||
12 | 'company', |
||
13 | ], |
||
14 | 'leadFields' => [ |
||
15 | 'first_name' => 'firstname', |
||
16 | 'last_name' => 'lastname', |
||
17 | 'email' => 'email', |
||
18 | 'phone' => 'phone', |
||
19 | ], |
||
20 | ]; |
||
21 | |||
22 | private $updateData = ['email' => '[email protected]', 'firstname'=> 'Test', 'lastname'=>'Person', 'phone'=>'678465345']; |
||
23 | |||
24 | protected function beforeBeginTransaction(): void |
||
25 | { |
||
26 | $this->resetAutoincrement([ |
||
27 | 'leads', |
||
28 | ]); |
||
29 | } |
||
30 | |||
31 | public function testCreateLeadViaUpdate() |
||
32 | { |
||
33 | $this->installPipedriveIntegration( |
||
34 | true, |
||
35 | $this->features, |
||
36 | [ |
||
37 | 'url' => '', |
||
38 | 'token' => 'token', |
||
39 | ] |
||
40 | ); |
||
41 | $data = $this->getData('person.updated'); |
||
42 | |||
43 | $this->makeRequest('POST', $data); |
||
44 | |||
45 | $response = $this->client->getResponse(); |
||
46 | $responseData = json_decode($response->getContent(), true); |
||
47 | $lead = $this->em->getRepository(Lead::class)->find(1); |
||
48 | |||
49 | $this->assertSame(200, $response->getStatusCode()); |
||
50 | $this->assertEquals('ok', $responseData['status']); |
||
51 | $this->assertEquals('Test Person', $lead->getName()); |
||
52 | $this->assertEquals('[email protected]', $lead->getEmail()); |
||
53 | $this->assertEquals('678465345', $lead->getPhone()); |
||
54 | $this->assertNotNull($lead->getDateAdded()); |
||
55 | $this->assertEquals('gravatar', $lead->getPreferredProfileImage()); |
||
56 | } |
||
57 | |||
58 | public function testUpdateLead() |
||
59 | { |
||
60 | $this->installPipedriveIntegration( |
||
61 | true, |
||
62 | $this->features, |
||
63 | [ |
||
64 | 'url' => '', |
||
65 | 'token' => 'token', |
||
66 | ] |
||
67 | ); |
||
68 | $data = json_decode($this->getData('person.updated'), true); |
||
69 | |||
70 | $lead = $this->createLead([], null, $this->updateData); |
||
71 | $this->createLeadIntegrationEntity($data['current']['id'], $lead->getId()); |
||
72 | |||
73 | $this->makeRequest('POST', json_encode($data)); |
||
74 | |||
75 | $response = $this->client->getResponse(); |
||
76 | $responseData = json_decode($response->getContent(), true); |
||
77 | $lead = $this->em->getRepository(Lead::class)->find(1); |
||
78 | |||
79 | $this->assertSame(200, $response->getStatusCode()); |
||
80 | $this->assertEquals('ok', $responseData['status']); |
||
81 | $this->assertEquals('Test Person', $lead->getName()); |
||
82 | $this->assertEquals('[email protected]', $lead->getEmail()); |
||
83 | $this->assertEquals('678465345', $lead->getPhone()); |
||
84 | $this->assertNull($lead->getOwner()); |
||
85 | $this->assertNull($lead->getCompany()); |
||
86 | $this->assertNotNull($lead->getDateModified()); |
||
87 | } |
||
88 | |||
89 | public function testUpdateLeadOwner() |
||
90 | { |
||
91 | $newOwnerId = 88; |
||
92 | $newOwnerEmail = '[email protected]'; |
||
93 | |||
94 | $this->installPipedriveIntegration( |
||
95 | true, |
||
96 | $this->features, |
||
97 | [ |
||
98 | 'url' => '', |
||
99 | 'token' => 'token', |
||
100 | ] |
||
101 | ); |
||
102 | |||
103 | $data = json_decode($this->getData('person.updated'), true); |
||
104 | |||
105 | $oldUser = $this->createUser(true); |
||
106 | $this->createLead([], $oldUser); |
||
107 | $newUser = $this->createUser(true, $newOwnerEmail, 'admin2'); |
||
108 | |||
109 | $this->addPipedriveOwner($newOwnerId, $newUser->getEmail()); |
||
110 | |||
111 | $data['current']['owner_id'] = $newOwnerId; |
||
112 | |||
113 | $this->makeRequest('POST', json_encode($data)); |
||
114 | |||
115 | $response = $this->client->getResponse(); |
||
116 | $responseData = json_decode($response->getContent(), true); |
||
117 | $lead = $this->em->getRepository(Lead::class)->find(2); |
||
118 | |||
119 | $this->assertSame(200, $response->getStatusCode()); |
||
120 | $this->assertEquals('ok', $responseData['status']); |
||
121 | $this->assertNotNull($lead->getOwner()); |
||
122 | $this->assertEquals($newOwnerEmail, $lead->getOwner()->getEmail()); |
||
123 | } |
||
124 | |||
125 | public function testUpdateLeadCompany() |
||
126 | { |
||
127 | $newCompanyId = 88; |
||
128 | $newCompanyName = 'New Company Name'; |
||
129 | $newCompanyAddress = 'Madrid, Spain'; |
||
130 | |||
131 | $this->installPipedriveIntegration( |
||
132 | true, |
||
133 | $this->features, |
||
134 | [ |
||
135 | 'url' => '', |
||
136 | 'token' => 'token', |
||
137 | ] |
||
138 | ); |
||
139 | |||
140 | $data = json_decode($this->getData('person.updated'), true); |
||
141 | |||
142 | $oldCompany = $this->createCompany(); |
||
143 | $newCompany = $this->createCompany($newCompanyName, $newCompanyAddress); |
||
144 | |||
145 | $lead = $this->createLead($oldCompany, null); |
||
146 | |||
147 | $this->createLeadIntegrationEntity($data['current']['id'], $lead->getId()); |
||
148 | $this->createCompanyIntegrationEntity($newCompanyId, $newCompany->getId()); |
||
149 | |||
150 | $data['current']['org_id'] = $newCompanyId; |
||
151 | $this->makeRequest('POST', json_encode($data)); |
||
152 | |||
153 | $response = $this->client->getResponse(); |
||
154 | $responseData = json_decode($response->getContent(), true); |
||
155 | $lead = $this->em->getRepository(Lead::class)->find(1); |
||
156 | |||
157 | $this->assertSame(200, $response->getStatusCode()); |
||
158 | $this->assertEquals('ok', $responseData['status']); |
||
159 | $this->assertNotNull($lead->getCompany()); |
||
160 | $this->assertEquals($newCompanyName, $lead->getCompany()); |
||
161 | $this->assertNotNull($lead->getDateModified()); |
||
162 | } |
||
163 | |||
164 | public function testRemoveLeadCompany() |
||
165 | { |
||
166 | $companyModel = $this->container->get('mautic.lead.model.company'); |
||
167 | |||
168 | $this->installPipedriveIntegration( |
||
169 | true, |
||
170 | $this->features, |
||
171 | [ |
||
172 | 'url' => '', |
||
173 | 'token' => 'token', |
||
174 | ] |
||
175 | ); |
||
176 | $data = json_decode($this->getData('person.updated'), true); |
||
177 | |||
178 | $oldCompany = $this->createCompany(); |
||
179 | $lead = $this->createLead($oldCompany, null, $this->updateData); |
||
180 | $leadCompanies = $companyModel->getCompanyLeadRepository()->getCompaniesByLeadId($lead->getId()); |
||
181 | $this->assertEquals(count($leadCompanies), 1); |
||
182 | |||
183 | $this->createLeadIntegrationEntity($data['current']['id'], $lead->getId()); |
||
184 | |||
185 | $this->makeRequest('POST', json_encode($data)); |
||
186 | |||
187 | $response = $this->client->getResponse(); |
||
188 | $responseData = json_decode($response->getContent(), true); |
||
189 | $lead = $this->em->getRepository(Lead::class)->find(1); |
||
190 | |||
191 | $leadCompanies = $companyModel->getCompanyLeadRepository()->getCompaniesByLeadId($lead->getId()); |
||
192 | |||
193 | $this->assertSame(200, $response->getStatusCode()); |
||
194 | $this->assertEquals($responseData['status'], 'ok'); |
||
195 | $this->assertEquals(count($leadCompanies), 0); |
||
196 | $this->assertNotNull($lead->getDateModified()); |
||
197 | } |
||
198 | |||
199 | public function testRemoveLeadOwner() |
||
200 | { |
||
201 | $this->installPipedriveIntegration( |
||
202 | true, |
||
203 | $this->features, |
||
204 | [ |
||
205 | 'url' => '', |
||
206 | 'token' => 'token', |
||
207 | ] |
||
208 | ); |
||
209 | $data = json_decode($this->getData('person.updated'), true); |
||
210 | |||
211 | $owner = $this->createUser(true); |
||
212 | $lead = $this->createLead([], $owner); |
||
213 | |||
214 | $this->assertNotNull($lead->getOwner()); |
||
215 | $this->assertEquals($lead->getOwner()->getEmail(), $owner->getEmail()); |
||
216 | |||
217 | $this->createLeadIntegrationEntity($data['current']['id'], $lead->getId()); |
||
218 | |||
219 | $data['current']['owner_id'] = null; |
||
220 | |||
221 | $this->makeRequest('POST', json_encode($data)); |
||
222 | |||
223 | $response = $this->client->getResponse(); |
||
224 | $responseData = json_decode($response->getContent(), true); |
||
225 | $lead = $this->em->getRepository(Lead::class)->find(1); |
||
226 | |||
227 | $this->assertSame(200, $response->getStatusCode()); |
||
228 | $this->assertEquals($responseData['status'], 'ok'); |
||
229 | $this->assertNull($lead->getOwner()); |
||
230 | $this->assertNotNull($lead->getDateModified()); |
||
231 | } |
||
232 | |||
233 | public function testDeleteLead() |
||
234 | { |
||
235 | $features = [ |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
236 | 'leadFields' => [ |
||
237 | 'first_name' => 'firstname', |
||
238 | 'last_name' => 'lastname', |
||
239 | 'email' => 'email', |
||
240 | 'phone' => 'phone', |
||
241 | ], |
||
242 | ]; |
||
243 | |||
244 | $this->installPipedriveIntegration( |
||
245 | true, |
||
246 | $this->features, |
||
247 | [ |
||
248 | 'url' => '', |
||
249 | 'token' => 'token', |
||
250 | ] |
||
251 | ); |
||
252 | $lead = $this->createLead(); |
||
253 | $json = $this->getData('person.deleted'); |
||
254 | $data = json_decode($json, true); |
||
255 | $this->createLeadIntegrationEntity($data['previous']['id'], $lead->getId()); |
||
256 | |||
257 | $this->assertEquals(count($this->em->getRepository(Lead::class)->findAll()), 1); |
||
258 | |||
259 | $this->makeRequest('POST', json_encode($data)); |
||
260 | |||
261 | $response = $this->client->getResponse(); |
||
262 | $responseData = json_decode($response->getContent(), true); |
||
263 | |||
264 | $this->assertSame(200, $response->getStatusCode()); |
||
265 | $this->assertEquals($responseData['status'], 'ok'); |
||
266 | $this->assertEquals(count($this->em->getRepository(Lead::class)->findAll()), 0); |
||
267 | } |
||
268 | } |
||
269 |