2022-07-20 12:46:32 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse;
|
|
|
|
use Intaro\RetailCrm\Service\LoyaltyAccountService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class LoyaltyAccountService
|
|
|
|
*/
|
|
|
|
class LoyaltyAccountServiceTest extends BitrixTestCase
|
|
|
|
{
|
2023-03-15 11:55:04 +03:00
|
|
|
private LoyaltyAccountService $loyaltyAccountService;
|
2022-07-20 12:46:32 +03:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*/
|
2023-03-15 11:55:04 +03:00
|
|
|
public function setUp(): void
|
2022-07-20 12:46:32 +03:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
|
|
|
CModule::IncludeModule('intaro.retailcrm');
|
2023-03-15 11:55:04 +03:00
|
|
|
|
|
|
|
$this->loyaltyAccountService = new LoyaltyAccountService();
|
2022-07-20 12:46:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param LoyaltyAccountCreateResponse $createResponse
|
|
|
|
* @param bool $expected
|
|
|
|
*
|
|
|
|
* @dataProvider proveUserInLpExistsProvider
|
|
|
|
*/
|
|
|
|
public function testProveUserInLpExists(LoyaltyAccountCreateResponse $createResponse, $expected)
|
|
|
|
{
|
2023-03-15 11:55:04 +03:00
|
|
|
self::assertEquals($expected, $this->loyaltyAccountService->proveUserInLpExists($createResponse));
|
2022-07-20 12:46:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param LoyaltyAccountCreateResponse $createResponse
|
|
|
|
* @param bool $expected
|
|
|
|
*
|
|
|
|
* @dataProvider proveNotUserInLpExistsProvider
|
|
|
|
*/
|
|
|
|
public function testNotProveUserInLpExists(LoyaltyAccountCreateResponse $createResponse, $expected)
|
|
|
|
{
|
2023-03-15 11:55:04 +03:00
|
|
|
self::assertEquals($expected, $this->loyaltyAccountService->proveUserInLpExists($createResponse));
|
2022-07-20 12:46:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
public function proveUserInLpExistsProvider()
|
|
|
|
{
|
|
|
|
$createResponse = new LoyaltyAccountCreateResponse();
|
|
|
|
$createResponse->success = false;
|
|
|
|
$createResponse->errors = [
|
|
|
|
'loyalty' => 'The customer is in this loyalty program already'
|
|
|
|
];
|
|
|
|
|
|
|
|
return [[
|
|
|
|
'createResponse' => $createResponse,
|
|
|
|
'expected' => true
|
|
|
|
]];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array[]
|
|
|
|
*/
|
|
|
|
public function proveNotUserInLpExistsProvider()
|
|
|
|
{
|
|
|
|
$createResponse = new LoyaltyAccountCreateResponse();
|
|
|
|
$createResponse->success = false;
|
|
|
|
$createResponse->errors = [
|
|
|
|
'loyalty' => 'Some other failure'
|
|
|
|
];
|
|
|
|
|
|
|
|
return [[
|
|
|
|
'createResponse' => $createResponse,
|
|
|
|
'expected' => false
|
|
|
|
]];
|
|
|
|
}
|
|
|
|
}
|