ldc-crm/tests/Unit/CrmClientV1CustomerTest.php
2021-10-19 17:15:34 +02:00

449 lines
17 KiB
PHP

<?php
namespace Tests\Unit;
use App\Models\Customer as ModelsCustomer;
use LDC\LDCCRM\Enums\Country;
use LDCCRM\ApiV1;
class CrmClientV1CustomerTest extends CrmClientTester
{
public function testGetCustomerById()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->getCustomer(static::$customer->id);
$this->assertEquals($reponse->status, 'OK');
$this->assertEquals($reponse->user->crm_id, static::$customer->id);
$this->assertEquals($reponse->user->email, static::$customer->email);
$this->assertEquals($reponse->user->firstname, static::$info->firstname);
$this->assertEquals($reponse->user->lastname, static::$info->lastname);
$this->assertEquals($reponse->user->birth_date, static::$info->birth_date);
$this->assertEquals($reponse->user->address, static::$info->address);
$this->assertEquals($reponse->user->address2, static::$info->address2);
$this->assertEquals($reponse->user->phone, static::$info->phone);
$this->assertEquals($reponse->user->country, static::$info->country);
$this->assertEquals($reponse->user->city, static::$info->city);
$this->assertEquals($reponse->user->opt_in, static::$info->opt_in);
$this->assertEquals($reponse->user->hashcode, static::$info->hashcode);
$this->assertEquals($reponse->user->status, static::$login->status);
}
public function testGetCustomerByIdShouldFail()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->getCustomer(9999999);
$this->assertEquals($reponse->status, 'KO');
$this->assertEquals($reponse->code, 101);
}
public function testGetCustomerByEmail()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->getCustomerByEmail(static::$customer->email);
$this->assertEquals($reponse->status, 'OK');
$this->assertEquals($reponse->user->crm_id, static::$customer->id);
$this->assertEquals($reponse->user->email, static::$customer->email);
$this->assertEquals($reponse->user->firstname, static::$info->firstname);
$this->assertEquals($reponse->user->lastname, static::$info->lastname);
$this->assertEquals($reponse->user->birth_date, static::$info->birth_date);
$this->assertEquals($reponse->user->address, static::$info->address);
$this->assertEquals($reponse->user->address2, static::$info->address2);
$this->assertEquals($reponse->user->phone, static::$info->phone);
$this->assertEquals($reponse->user->country, static::$info->country);
$this->assertEquals($reponse->user->city, static::$info->city);
$this->assertEquals($reponse->user->opt_in, static::$info->opt_in);
$this->assertEquals($reponse->user->hashcode, static::$info->hashcode);
$this->assertEquals($reponse->user->status, static::$login->status);
}
public function testGetCustomerByEmailShouldFail()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->getCustomer('totoo@toto.fr');
$this->assertEquals($reponse->status, 'KO');
$this->assertEquals($reponse->code, 101);
}
public function testCustomerStoreProps()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->createCustomer(
'v1toto.delarogerie@gmail.com',
'Complic4tEd!P4assW0rd',
'toto',
'delarogerie',
true,
'1992-03-08',
'0673891160',
'rue des totos',
'',
'Toto ville',
'72160',
Country::france()->label
);
$this->assertEquals($reponse->status, 'OK');
$this->assertNotEmpty($reponse->user->crm_id);
$this->assertNotEmpty($reponse->user->hashcode);
$this->assertEquals($reponse->user->email, 'v1toto.delarogerie@gmail.com');
$this->assertEquals($reponse->user->firstname, 'Toto');
$this->assertEquals($reponse->user->lastname, 'Delarogerie');
$this->assertEquals($reponse->user->birth_date, '1992-03-08');
$this->assertEquals($reponse->user->address, 'rue des totos');
$this->assertEquals($reponse->user->address2, '');
$this->assertEquals($reponse->user->phone, '0673891160');
$this->assertEquals($reponse->user->country, Country::france()->label);
$this->assertEquals($reponse->user->city, 'Toto ville');
$this->assertEquals($reponse->user->opt_in, true);
$this->assertEquals($reponse->user->status, false);
}
public function testCustomerStorePropsShouldFailBecauseAlreadyExist()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->createCustomer(
'v1toto.delarogerie@gmail.com',
'Complic4tEd!P4assW0rd',
'toto',
'delarogerie',
true,
'1992-03-08',
'0673891160',
'rue des totos',
'',
'Toto ville',
'72160',
Country::france()->label
);
$this->assertEquals($reponse->status, 'KO');
$this->assertEquals($reponse->code, 103);
}
public function testCustomerStorePropsShouldFail()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->createCustomer(
'v1bistoto.delarogerie@gmail.com',
'123456',
'toto bis',
'delarogerie',
true,
'1992-08',
'0673891160',
'rue des totos',
'',
'Toto ville',
'72160',
Country::france()->label
);
$this->assertEquals($reponse->status, 'KO');
$this->assertEquals($reponse->code, 102);
}
public function testCustomerUpdateProps()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->updateCustomer(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')->firstOrFail()->id,
'toto new',
'delarogerie',
true,
'1992-03-08',
'0673891160',
'rue des totos',
'',
'Toto ville',
'72160',
Country::france()->label
);
$this->assertEquals($reponse->status, 'OK');
$this->assertNotEmpty($reponse->user->crm_id);
$this->assertNotEmpty($reponse->user->hashcode);
$this->assertEquals($reponse->user->email, 'v1toto.delarogerie@gmail.com');
$this->assertEquals($reponse->user->firstname, 'toto new');
$this->assertEquals($reponse->user->lastname, 'delarogerie');
$this->assertEquals($reponse->user->birth_date, '1992-03-08');
$this->assertEquals($reponse->user->address, 'rue des totos');
$this->assertEquals($reponse->user->address2, '');
$this->assertEquals($reponse->user->phone, '0673891160');
$this->assertEquals($reponse->user->country, Country::france()->label);
$this->assertEquals($reponse->user->city, 'Toto ville');
$this->assertEquals($reponse->user->opt_in, true);
$this->assertEquals($reponse->user->status, false);
}
public function testCustomerLoginShouldFailDontExists()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->loginCustomer('v1totso.delarogerie@gmail.com', 'Complic4tEd!P4assW0rd');
$this->assertEquals('KO', $reponse->status);
$this->assertEquals(119, $reponse->code);
}
public function testCustomerLoginShouldFailNotActivated()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->loginCustomer('v1toto.delarogerie@gmail.com', 'Complic4tEd!P4assW0rd');
$this->assertEquals('KO', $reponse->status);
$this->assertEquals(116, $reponse->code);
}
public function testCustomeActivate()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->activateCustomer(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')->firstOrFail()->id
);
$this->assertEquals('OK', $reponse->status);
}
public function testCustomerLogin()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->loginCustomer('v1toto.delarogerie@gmail.com', 'Complic4tEd!P4assW0rd');
$this->assertEquals('OK', $reponse->status);
}
public function testCustomeActivateShouldFail()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->activateCustomer(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')->firstOrFail()->id
);
$this->assertEquals('KO', $reponse->status);
$this->assertEquals(110, $reponse->code);
}
public function testCustomeToggleOptin()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->toggleOptInCustomer(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')->firstOrFail()->id
);
$this->assertEquals('OK', $reponse->status);
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->toggleOptInCustomer(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')->firstOrFail()->id
);
$this->assertEquals('OK', $reponse->status);
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->toggleOptInCustomer(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')->firstOrFail()->id
);
$this->assertEquals('OK', $reponse->status);
}
public function testCustomeRemoveOptin()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$hashcode = $api->getCustomerByEmail('v1toto.delarogerie@gmail.com')->user->hashcode;
$reponse = $api->removeOptInCustomer($hashcode);
$this->assertEquals('OK', $reponse->status);
}
public function testCustomerDelete()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->deleteCustomer(ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')
->firstOrFail()->id);
$this->assertNull($reponse);
}
public function testCreateSingleOptin()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->createSingleOptin('singlev1toto.delarogerie@gmail.com');
$this->assertEquals('OK', $reponse->status);
}
public function testCreateSingleOptinShouldFail()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->createSingleOptin('singlev1toto.delarogerie@gmail.com');
$this->assertEquals('KO', $reponse->status);
$this->assertEquals(121, $reponse->code);
}
public function testCreateArcadiaOutgoingMail()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->ArcadiaOutgoingMail(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')
->firstOrFail()->id,
[
'root' => [
[
'fieldName' => 'order_num',
//format 9 numeric characters
'fieldValue' => str_pad(12, 9, '0', \STR_PAD_LEFT),
],
[
'fieldName' => 'order_date',
//format : DD/MM/YYYY
'fieldValue' => '12/05/1992',
],
[
'fieldName' => 'state_order_cb',
// format 1 ou Null (oui Null et pas NULL)
'fieldValue' => 1,
],
[
'fieldName' => 'state_order_check',
// format 1 ou Null (oui Null et pas NULL)
'fieldValue' => 'Null'
],
[
'fieldName' => 'operation',
// mettre valeur dans .env
'fieldValue' => 16
]
],
'orderLine' => [
[
'fieldName' => 'package_unit_weight',
'fieldValue' => 200
],
[
'fieldName' => 'qty',
// forced to 1 faire un appel par produit et pour chaque quantité
'fieldValue' => '1'
],
[
'fieldName' => 'support_code',
'fieldValue' => 2
],
[
'fieldName' => 'label_type_support',
'fieldValue' => 'label supoport'
]
]
],
'default',
[
"firstname" => 'toto',
"lastname" => 'delarogerie',
"address" => 'rue des toto',
"city" => 'toto ville',
"postcode" => '72000',
"phone" => '0673891160'
]
);
$this->assertEquals('OK', $reponse->status);
}
public function testCreateArcadiaOutgoingMailGameWithEan()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->ArcadiaOutgoingMail(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')
->firstOrFail()->id,
[
'root' => [
[
'fieldName' => 'order_date',
'fieldValue' => date('d/m/Y')
],
[
'fieldName' => 'operation',
'fieldValue' => '32'
]
],
'orderLine' => [
[
'fieldName' => 'code_unique',
'fieldValue' => '2A5B416325414232'
],
[
'fieldName' => 'code_on_pack',
'fieldValue' => '2541632541423'
],
[
'fieldName' => 'support_code',
'fieldValue' => '16'
],
[
'fieldName' => 'label_type_support',
'fieldValue' => 'Gain du lot : ballon de foot en métal type "fracture"'
]
]
],
'game',
[
"firstname" => 'toto',
"lastname" => 'delarogerie',
"address" => 'rue des toto',
"city" => 'toto ville',
"postcode" => '72000',
"phone" => '0673891160'
]
);
$this->assertEquals('OK', $reponse->status);
}
public function testCreateArcadiaOutgoingMailGameWithoutEan()
{
$api = new ApiV1(config('crm.endpoint'), config('crm.token'));
$reponse = $api->ArcadiaOutgoingMail(
ModelsCustomer::where('email', 'v1toto.delarogerie@gmail.com')
->firstOrFail()->id,
[
'root' => [
[
'fieldName' => 'order_date',
'fieldValue' => date('d/m/Y')
],
[
'fieldName' => 'operation',
'fieldValue' => '32'
]
],
'orderLine' => [
[
'fieldName' => 'code_unique',
'fieldValue' => '25416325414232'
],
[
'fieldName' => 'support_code',
'fieldValue' => '16'
],
[
'fieldName' => 'label_type_support',
'fieldValue' => 'Gain du lot : ballon de foot en métal type "fracture"'
]
]
],
'game',
[
"firstname" => 'toto',
"lastname" => 'delarogerie',
"address" => 'rue des toto',
"city" => 'toto ville',
"postcode" => '72000',
"phone" => '0673891160'
]
);
$this->assertEquals('OK', $reponse->status);
}
}