89 lines
2.3 KiB
PHP
89 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Client;
|
|
|
|
use App\Models\Customer;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
|
use LDC\LDCCRM\CrmApiV2;
|
|
use Tests\CreatesApplication;
|
|
|
|
abstract class CrmClientTester extends BaseTestCase
|
|
{
|
|
use CreatesApplication;
|
|
|
|
/** @var \App\Models\Customer */
|
|
protected static $customer;
|
|
|
|
/** @var \App\Models\Brand */
|
|
protected static $brand;
|
|
|
|
/** @var \App\Models\Service */
|
|
protected static $service;
|
|
|
|
/** @var \App\Models\Info */
|
|
protected static $info;
|
|
|
|
/** @var \App\Models\Login */
|
|
protected static $login;
|
|
|
|
/**
|
|
* Setup the test environment.
|
|
*
|
|
* @return void
|
|
* @throws \ErrorException If env is not testing.
|
|
*/
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
if (!self::$customer) {
|
|
extract(self::getCustomer());
|
|
self::$customer = $customer;
|
|
self::$brand = $brand;
|
|
self::$service = $service;
|
|
self::$login = $login;
|
|
self::$info = $info;
|
|
}
|
|
new CrmApiV2(
|
|
config('app.url'),
|
|
self::$service->bearer_token,
|
|
Crypt::decryptString(self::$service->bearer_pwd)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Get customer
|
|
*
|
|
* @param boolean $status
|
|
* @return array
|
|
*/
|
|
protected static function getCustomer(bool $status = true): array
|
|
{
|
|
/** @var \App\Models\Costumer $customer */
|
|
$customer = Customer::whereHas('logins', function ($q) use ($status) {
|
|
$q->where('status', $status);
|
|
})->inRandomOrder()->firstOrFail();
|
|
/** @var \App\Models\Brand $brand */
|
|
$login = $customer->logins()->where('status', $status)->firstOrFail();
|
|
/** @var \App\Models\CustomerLogin $login */
|
|
$brand = $login->brand;
|
|
/** @var \App\Models\Service $service */
|
|
$service = $brand->services()->firstOrFail();
|
|
|
|
// Get customer info.
|
|
$info = $customer->info($brand, Customer::FIRST_OR_FAIL);
|
|
|
|
return compact('customer', 'service', 'brand', 'login', 'info');
|
|
}
|
|
|
|
/**
|
|
* Parse routes.json and return routes list
|
|
*
|
|
* @return array
|
|
*/
|
|
protected function getClientRoutes(): array
|
|
{
|
|
return \json_decode(\file_get_contents(__DIR__ . '/../../clients/V2/src/routes.json'), true);
|
|
}
|
|
}
|