This removes api authentification with token in favor of signature method. Refactorize code and clean up. It add more unit test plus code coverage in test/converage. - Added config.api.timestampTimeout - Added Helper::signRequest This calculates the request signature - Added more unit tests and extend code coverage. - Added rate limiter for web routes - Added RemoveSpaces Sanitizer on api requests - Added stress test suite - Changed AuthServiceProvider api-token to api-hmac - Changed CustomerSeeder to have at least of customer activated (for unit tests) - Changed used transation for saveing multiple models - Changed, in ServiceController generateApiToken to generateServicePassword - Changed, timestamp has to be send in request with a DateTime format, it also has to a UTC value - Composer added brianium/paratest - Composer update - Fixed case where removing single optin could be the wrong one (not for the good service) - Fixed customer delete - Fixed customer would not be resolved by brand. - Fixed Really check that request is json checking body content, preventing sending malformed requests - Remove ApiError::needAuth - Removed api_token - Removed ApiController::authenticate - Removed config.api.tokenTimeout - Removed Header check or usage because of HAProxy doing weird stuff - Removed lock files from gitignore - Removed memcached dependency - Removed unused questions resources api routes - Removed workspace file Migrations - Added unique index on services.bearer_token - Changed customer_id on customer_answer is nullable - Changed services.bearer_pwd length to 312 (the size of the token) - Dropped services.api_token and service.api_token_date
64 lines
2.2 KiB
PHP
64 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));
|
|
}
|
|
}
|