Skip to content

Commit

Permalink
Merge pull request #924 from bakaphp/refact-test-
Browse files Browse the repository at this point in the history
feat: delete record at the end in zoho
  • Loading branch information
kaioken committed Feb 11, 2024
2 parents ecb736e + 9b15df4 commit 227fa28
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Domains/Connectors/Zoho/ZohoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Exception;
use Kanvas\Connectors\Zoho\Enums\CustomFieldEnum;
use Kanvas\Guild\Agents\Models\Agent;
use Kanvas\Guild\Leads\Models\Lead;
use Webleit\ZohoCrmApi\ZohoCrm;

class ZohoService
Expand Down Expand Up @@ -78,4 +79,22 @@ public function createAgent(UserInterface $user, Agent $agentInfo, ?object $zoho

return $zohoAgent;
}

public function deleteLead(Lead $lead): void
{
$zohoLeadId = $lead->get(CustomFieldEnum::ZOHO_LEAD_ID->value);
if ($zohoLeadId) {
$this->zohoCrm->leads->delete((string) $zohoLeadId);
}
}

public function deleteAgent(Agent $agent): void
{
$zohoAgentId = $agent->users_linked_source_id;
if ($this->zohoAgentModule == self::DEFAULT_AGENT_MODULE) {
$this->zohoCrm->agents->delete($zohoAgentId);
} else {
$this->zohoCrm->vendors->delete($zohoAgentId);
}
}
}
2 changes: 1 addition & 1 deletion src/Domains/Guild/Agents/Models/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function status(): Attribute
);
}

public static function getByMemberNumber(string $memberNumber, CompanyInterface $company): self
public static function getByMemberNumber(string|int $memberNumber, CompanyInterface $company): self
{
return self::where('member_id', $memberNumber)
->fromCompany($company)
Expand Down
7 changes: 7 additions & 0 deletions tests/Connectors/Integration/Zoho/AgentActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Kanvas\Apps\Models\Apps;
use Kanvas\Connectors\Zoho\Enums\CustomFieldEnum;
use Kanvas\Connectors\Zoho\Workflows\ZohoAgentActivity;
use Kanvas\Connectors\Zoho\ZohoService;
use Kanvas\Guild\Agents\Models\Agent;
use Kanvas\Guild\Enums\FlagEnum;
use Kanvas\Guild\Leads\Models\Lead;
use Kanvas\Workflow\Models\StoredWorkflow;
Expand Down Expand Up @@ -45,6 +47,11 @@ public function testLeadCreationWorkflow(): void
$user->saveOrFail();

$result = $activity->execute($user, $app, ['company' => $company]);

$zohoService = new ZohoService($app, $company);
$agent = Agent::getByMemberNumber($result['member_id'], $company);
$zohoService->deleteAgent($agent);

$this->assertIsArray($result);
$this->assertNotEmpty($result['zohoId']);
$this->assertNotEmpty($result['member_id']);
Expand Down
5 changes: 5 additions & 0 deletions tests/Connectors/Integration/Zoho/LeadActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Kanvas\Apps\Models\Apps;
use Kanvas\Connectors\Zoho\Enums\CustomFieldEnum;
use Kanvas\Connectors\Zoho\Workflows\ZohoLeadActivity;
use Kanvas\Connectors\Zoho\ZohoService;
use Kanvas\Filesystem\Services\FilesystemServices;
use Kanvas\Guild\Enums\FlagEnum;
use Kanvas\Guild\Leads\Models\Lead;
Expand Down Expand Up @@ -50,6 +51,10 @@ public function testLeadCreationWorkflow(): void
);

$result = $activity->execute($lead, $app, []);

$zohoService = new ZohoService($app, $company);
$zohoService->deleteLead($lead);

$this->assertArrayHasKey('zohoLeadId', $result);
$this->assertArrayHasKey('zohoRequest', $result);
$this->assertArrayHasKey('leadId', $result);
Expand Down

0 comments on commit 227fa28

Please sign in to comment.