ldc-crm/tests/Unit/CrmClientV2CustomerTest.php
Jérémy Munsch 83657ef6bf - working testing env
- use php artisan serve to run test + autokill
- autodebug if envirronement is testing
2021-08-05 15:00:28 +02:00

140 lines
4.4 KiB
PHP

<?php
namespace Tests\Unit;
use App\Models\Customer as ModelsCustomer;
use Illuminate\Support\Str;
use LDC\LDCCRM\CrmApiV2;
use LDC\LDCCRM\Enums\Country;
use LDC\LDCCRM\Models\Customer;
use TypeError;
class CrmClientV2CustomerTest extends CrmClientTester
{
public function testGetter()
{
$this->expectNotToPerformAssertions();
$client = new Customer();
$client->email;
}
public function testSetter()
{
$this->expectNotToPerformAssertions();
$client = new Customer();
$client->firstname = 'toto';
$client->firstname;
}
public function testSetterFailWrongType()
{
$this->expectException(TypeError::class);
$client = new Customer();
$client->opt_in = 'toto';
}
public function testSetterFailWrongTypeCountry()
{
$this->expectException(TypeError::class);
$client = new Customer();
$client->country = 'toto';
}
public function testPropsAllSetOk()
{
$this->expectNotToPerformAssertions();
$client = new Customer();
$propTypes = [
'hashcode' => (string)Str::uuid(),
'email' => 'toto@gmail.com',
'firstname' => 'string',
'lastname' => 'string',
'password' => 'StrongPassword!7',
'birthdate' => '1992-02-03',
'phone' => '0673891630',
'address' => 'string',
'address2' => 'string',
'city' => 'string',
'postcode' => 'string',
'country' => Country::afghanistan(),
'optin' => true,
'status' => true,
];
foreach ($propTypes as $prop => $type) {
$client->{$prop} = $type;
}
}
public function testPropsAllSetNotOk()
{
$this->expectException(TypeError::class);
$client = new Customer();
$propTypes = [
'hashcode' => (string)Str::uuid(),
'email' => 'toto@gmail.com',
'firstname' => 'string',
'lastname' => 'string',
'password' => 'StrongPassword!7',
'birthdate' => '1992-02-03',
'phone' => '0673891630',
'address' => 'string',
'address2' => 'string',
'city' => 'string',
'postcode' => 'string',
'country' => Country::afghanistan()->value,
'optin' => true,
'status' => true,
];
foreach ($propTypes as $prop => $type) {
$client->{$prop} = $type;
}
}
public function testCustomerGet()
{
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew(static::$info->hashcode);
$this->assertEquals(Customer::class, get_class($customer));
$this->assertEquals($customer->firstname, static::$info->firstname);
$this->assertEquals($customer->lastname, static::$info->lastname);
$this->assertEquals($customer->birth_date, static::$info->birth_date);
$this->assertEquals($customer->address, static::$info->address);
$this->assertEquals($customer->address2, static::$info->address2);
$this->assertEquals($customer->phone, static::$info->phone);
$this->assertEquals($customer->city, static::$info->city);
$this->assertEquals($customer->postcode, static::$info->postcode);
$this->assertEquals($customer->opt_in, static::$info->opt_in);
$this->assertEquals($customer->hashcode, static::$info->hashcode);
$this->assertEquals($customer->country->label, static::$info->country);
$this->assertEquals($customer->country->value, static::$info->newcountry->value);
}
public function testCustomerActivate()
{
// Get non activated customer
/** @var \App\Models\Customer */
$customer = ModelsCustomer::whereHas('logins', function ($q) {
$q->where('status', 0)->whereHas('brand', function ($q) {
$q->whereId(static::$brand->id);
});
})->firstOrFail();
$login = $customer->logins()->where('status', 0)->first();
/** @var \App\Models\Brand */
$brand = $login->brand;
/** @var \App\Models\CustomerInfo */
$info = $customer->info($brand)->firstOrFail();
$api = new CrmApiV2();
$customer = $api->getCustomerOrNew($info->hashcode);
$this->assertTrue($customer->activate());
}
}