Skip to content

Commit

Permalink
Merge pull request #16 from bakaphp/SAW-2327-vehicle-info
Browse files Browse the repository at this point in the history
feat:Add vehicle interest's getByLeadId
  • Loading branch information
rwhite27 authored Dec 28, 2021
2 parents 7717404 + f010ef9 commit b66a211
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/Vehicles/Interest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);

namespace Kanvas\VinSolutions\Vehicles;

use Kanvas\VinSolutions\Client;
use Kanvas\VinSolutions\Dealers\Dealer;
use Kanvas\VinSolutions\Dealers\User;

class Interest
{
public string $href;
public int $count;
public array $items;

/**
* Initialize
*
* @param array $data
*/
public function __construct(array $data)
{
$this->href = $data['href'];
$this->count = $data['count'] ?? 0;
$this->items = $data['items'];
}

/**
* Get a contact by its ID.
*
* @param Dealer $dealer
* @param User $user
* @param int $leadsId
*
* @return Source
*/
public static function getByLeadId(Dealer $dealer, User $user, int $leadsId) : Interest
{
$client = new Client($dealer->id, $user->id);

$response = $client->get('/vehicles/interest?leadId=' . $leadsId, [
'headers' => [
'Accept' => 'application/vnd.coxauto.v1+json'
]
]);

return new Interest($response);
}
}
78 changes: 78 additions & 0 deletions tests/integration/VehicleInterestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Kanvas\VinSolutions\Tests\Integration;

use Faker\Factory;
use Kanvas\VinSolutions\Dealers\Dealer;
use Kanvas\VinSolutions\Leads\Contact;
use Kanvas\VinSolutions\Leads\Lead;
use Kanvas\VinSolutions\Vehicles\Interest;

use PhalconUnitTestCase;

class VehicleInterestTest extends PhalconUnitTestCase
{
public function testGetLeadsVehicleInfo()
{
$dealer = Dealer::getById((int) getenv('VINSOLUTIONS_DEALER_ID'));
$user = Dealer::getUser($dealer, (int) getenv('VINSOLUTIONS_USER_ID'));

$faker = Factory::create();

$contact = [
'ContactInformation' => [
'title' => $faker->title(),
'FirstName' => $faker->firstName(),
'LastName' => $faker->lastName,
'CompanyName' => $faker->company,
'CompanyType' => $faker->companySuffix,
'Emails' => [
[
'EmailId' => 0,
'EmailAddress' => $faker->email,
'EmailType' => 'primary'
]
],
'Phones' => [
[
'PhoneId' => 0,
'PhoneType' => 'Cell',
'Number' => '8093505188000'
]
]
],
'LeadInformation' => [
'CurrentSalesRepUserId' => 0,
'SplitSalesRepUserId' => 0,
'LeadSourceId' => 0,
'LeadTypeId' => 0,
'OnShowRoom' => false,
'SaleNotes' => '',
]
];

$contact = Contact::create(
$dealer,
$user,
$contact
);

$lead = [
'leadSource' => 55694,
'leadType' => 'INTERNET',
'contact' => $contact->id,
'isHot' => true
];


$newLead = Lead::create($dealer, $user, $lead);
$vehicleInterest = Interest::getByLeadId($dealer, $user, $newLead->id);

// $this->assertIsArray($vehicleInterest);
$this->assertTrue($vehicleInterest instanceof Interest);
$this->assertTrue(property_exists($vehicleInterest, 'items'));
$this->assertTrue($vehicleInterest->count > 0);
}
}

0 comments on commit b66a211

Please sign in to comment.