ldc-crm/tests/Client/CrmClientSingleOptinTest.php
Alexis Gousseau 303834bbca
Crm V4
- Make all tests pass Client (V4),CRMV2,CRMV4
- Simplify client submodule path
- Move App_url to .env.testing
2023-10-06 16:37:29 +02:00

85 lines
3 KiB
PHP

<?php
namespace Tests\Client;
use App\Models\SingleOptin as ModelsSingleOptin;
use Illuminate\Support\Str;
use LDC\LDCCRM\CrmApiV4;
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 CrmClientSingleOptinTest 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::query()->where('email', 'singleoptinrandom@gmail.com')->exists());
// Set single optin again should not fail.
$this->assertTrue(CrmApiV4::setStatus('singleoptinrandom@gmail.com', true));
// Remove single optin test and check.
$this->assertTrue(SingleOptin::setStatus('singleoptinrandom@gmail.com', false));
$this->assertTrue(!ModelsSingleOptin::query()->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->value();
$this->assertTrue($customer->save());
$this->assertFalse(SingleOptin::setStatus($randomMail, true));
}
/**
* Remove single optin with hashcode test
*
* Calling multiple times single optin true should not fail.
*
* @return void
*/
public function testRemoveSingleOptinWithHashcode()
{
// Set single optin and check.
$this->assertTrue(SingleOptin::setStatus('singleoptinrandom@gmail.com', true));
$this->assertTrue(ModelsSingleOptin::query()->where('email', 'singleoptinrandom@gmail.com')->exists());
$hashcode = ModelsSingleOptin::query()
->where('email', 'singleoptinrandom@gmail.com')->sole('hashcode')->hashcode;
// Remove single optin test and check.
$this->assertTrue(SingleOptin::unsetStatusWithHashcode($hashcode));
$this->assertTrue(!ModelsSingleOptin::query()->where('email', 'singleoptinrandom@gmail.com')->exists());
}
}