ldc-crm/tests/Feature/ApiV2/SingleOptinTest.php
Jérémy Munsch 787ee5a4c5 - tag 2.0.1
- Add Questions segementation
- Fix Customer delete Tests
2021-08-11 17:37:59 +02:00

73 lines
2.4 KiB
PHP

<?php
namespace Tests\Feature\ApiV2;
use App\Enums\ApiError;
use App\Enums\ApiStatus;
use App\Enums\Country;
use App\Models\Service;
use App\Models\SingleOptin;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\CreatesApplication;
class SingleOptinTest extends ApiBase
{
use CreatesApplication;
use DatabaseTransactions;
/**
* route: apiV2.optin
*/
public function testSingleOptin()
{
$service = Service::firstOrFail();
$response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [
'email' => 'warthogdj@hotmail.fr',
'opt_in' => 1
]);
$json = $response->decodeResponseJson();
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
$response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [
'email' => 'warthogdj@hotmail.fr',
'opt_in' => 0
]);
$json = $response->decodeResponseJson();
$this->assertApiResponseStatusIs($json, ApiStatus::OK());
$this->assertNull(SingleOptin::where('email', 'warthogdj@hotmail.fr')->first());
}
public function testSingleOptinOnCustomerExsits()
{
$service = Service::firstOrFail();
$this->storeCustomer($service);
$response = $this->callApiWithToken($service, 'post', route('apiV2.optin'), [
'email' => 'warthogdj@hotmail.fr',
'opt_in' => 1
]);
$json = $response->decodeResponseJson();
$this->assertApiResponseStatusIs($json, ApiStatus::KO());
$this->assertEquals(ApiError::singleOptinCustomerExists()->value, $json->json('data.code'));
$this->assertEquals(ApiError::singleOptinCustomerExists()->label, $json->json('data.message'));
}
private function storeCustomer(Service $service)
{
$data = [
'firstname' => 'Jean<html></html>',
'lastname' => 'Bond',
'birth_date' => \date('1992-03-08'),
'address' => '10 impasse Maryse Bastié',
'email' => 'warthogdj@hotmail.fr',
'password' => '123.Mot.De.P4sse',
'phone' => '+33654821562',
'country' => (string)Country::france(),
'city' => 'Connerré',
'postcode' => '72160',
'opt_in' => true
];
$this->callApiWithToken($service, 'post', route('apiV2.customers.store'), $data);
}
}