65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Client;
|
||
|
|
|
||
|
|
use App\Models\SingleOptin as ModelsSingleOptin;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
use LDC\LDCCRM\CrmApiV2;
|
||
|
|
use LDC\LDCCRM\Enums\ApiError;
|
||
|
|
use LDC\LDCCRM\Enums\Country;
|
||
|
|
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
||
|
|
use LDC\LDCCRM\Models\Customer;
|
||
|
|
use LDC\LDCCRM\Models\SingleOptin;
|
||
|
|
|
||
|
|
class CrmClientV2SingleOptinTest extends CrmClientTester
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Create and remove single optin test
|
||
|
|
*
|
||
|
|
* Calling multiple times single optin true should not fail.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function testCreateAndRemoveSingleOptin()
|
||
|
|
{
|
||
|
|
// Set single optin and check.
|
||
|
|
$this->assertTrue(SingleOptin::setStatus('singleoptinrandom@gmail.com', true));
|
||
|
|
$this->assertTrue(ModelsSingleOptin::where('email', 'singleoptinrandom@gmail.com')->exists());
|
||
|
|
|
||
|
|
// Set single optin again should not fail.
|
||
|
|
$this->assertTrue(CrmApiV2::setStatus('singleoptinrandom@gmail.com', true));
|
||
|
|
|
||
|
|
// Remove single optin test and check.
|
||
|
|
$this->assertTrue(SingleOptin::setStatus('singleoptinrandom@gmail.com', false));
|
||
|
|
$this->assertTrue(!ModelsSingleOptin::where('email', 'singleoptinrandom@gmail.com')->exists());
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Test create single optin should fail if a customer exists.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function testCreateSingleOptinShouldFailBecauseCustomerExists()
|
||
|
|
{
|
||
|
|
$this->expectException(ApiErrorException::class);
|
||
|
|
$this->expectExceptionMessage(ApiError::singleOptinCustomerExists()->label);
|
||
|
|
$customer = new Customer();
|
||
|
|
|
||
|
|
$randomMail = Str::uuid() . 'totosingleoptin.delarogerie@gmail.com';
|
||
|
|
|
||
|
|
$customer->firstname = 'toto singleoptin';
|
||
|
|
$customer->lastname = 'delarogerie';
|
||
|
|
$customer->email = $randomMail;
|
||
|
|
$customer->password = 'Complic4tEd!P4assW0rd';
|
||
|
|
$customer->birth_date = '1992-03-08';
|
||
|
|
$customer->phone = '0673891160';
|
||
|
|
$customer->address = 'rue des totos';
|
||
|
|
$customer->city = 'Toto ville';
|
||
|
|
$customer->postcode = '72160';
|
||
|
|
$customer->country = Country::france();
|
||
|
|
|
||
|
|
$this->assertTrue($customer->save());
|
||
|
|
$this->assertFalse(SingleOptin::setStatus($randomMail, true));
|
||
|
|
}
|
||
|
|
}
|