Skip to content

Commit

Permalink
Merge pull request #2 from bakaphp/master
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken authored Oct 12, 2021
2 parents 09180a2 + dd26a0f commit 013b05f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Leads/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ public function __construct(array $data)
$this->leadInformation = $data['leadInformation'] ?? [];
}

/**
* Get all the leads for the given dealer.
*
* @param Dealer $dealer
* @param User $user
* @param array $params
*
* @return array
*/
public static function getAll(Dealer $dealer, User $user, string $search, array $params = []) : array
{
$client = new Client($dealer->id, $user->id);
$client->useDigitalShowRoomKey();

$data = [];
$data['DealerId'] = $dealer->id;
$data['UserId'] = $user->id;

$params = http_build_query($params);

$response = $client->get(
'/gateway/v1/contact?dealerId=' . $dealer->id . '&userId=' . $user->id . '&searchText=' . $search . '&' . $params,
);

return $response;
}

/**
* Get a contact by its ID.
*
Expand Down
27 changes: 27 additions & 0 deletions src/Leads/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ public function __construct(array $data)
$this->isOnShowroom = isset($data['IsOnShowroom']) ? (int) $data['IsOnShowroom'] : 0;
}

/**
* Get all the leads for the given dealer.
*
* @param Dealer $dealer
* @param User $user
* @param array $params
*
* @return array
*/
public static function getAll(Dealer $dealer, User $user, array $params = []) : array
{
$client = new Client($dealer->id, $user->id);
$client->useDigitalShowRoomKey();

$data = [];
$data['DealerId'] = $dealer->id;
$data['UserId'] = $user->id;

$params = http_build_query($params);

$response = $client->get(
'/gateway/v1/lead?dealerId=' . $dealer->id . '&userId=' . $user->id . '&' . $params,
);

return $response;
}

/**
* Get a contact by its ID.
*
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,35 @@ public function testUpdateContact()
$this->assertEquals($contactInfo->information['LastName'], $contactInfoNew->information['LastName']);
$this->assertEquals($contactInfo->emails[0]['EmailAddress'], $contactInfoNew->emails[0]['EmailAddress']);
}

public function testGetAllContacts()
{
$dealer = Dealer::getById(1);
$user = Dealer::getUser($dealer, 9);
$contacts = LeadsContact::getAll($dealer, $user, 'gmail');

$this->assertIsArray($contacts);
$this->assertTrue(count($contacts) > 0);
}

public function testGetAllContactsWithParams()
{
$dealer = Dealer::getById(1);
$user = Dealer::getUser($dealer, 9);

$params = [
'pageNumber' => 2,
'pageSize' => 50,
];

$contacts = LeadsContact::getAll(
$dealer,
$user,
'gmail',
$params,
);

$this->assertIsArray($contacts);
$this->assertTrue(count($contacts) === $params['pageSize']);
}
}
29 changes: 29 additions & 0 deletions tests/integration/LeadsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,33 @@ public function testGetTradeVehicles()
$this->assertIsArray($tradeIn);
$this->assertTrue(count($tradeIn) > 0);
}

public function testGetAllLeads()
{
$dealer = Dealer::getById(1);
$user = Dealer::getUser($dealer, 9);
$leads = Lead::getAll($dealer, $user);

$this->assertIsArray($leads);
$this->assertTrue(count($leads) > 0);
}

public function testGetAllLeadsPagination()
{
$dealer = Dealer::getById(1);
$user = Dealer::getUser($dealer, 9);

$params = [
'leadStatusTypeId' => 1,
'pageNumber' => 2,
'pageSize' => 50,
];

$leads = Lead::getAll($dealer, $user, $params);

$this->assertIsArray($leads);
$this->assertTrue(count($leads) > 0);
$this->assertTrue($leads['PagingInfo']['PageSize'] === $params['pageSize']);
$this->assertTrue($leads['PagingInfo']['PageNumber'] === $params['pageNumber']);
}
}

0 comments on commit 013b05f

Please sign in to comment.