Правка бага при включенной настройке автоматической регистрации, плюс правка тестов и ci.
This commit is contained in:
parent
d52974c7d1
commit
a3d8271b1f
9 changed files with 162 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
|||
FROM php:7.1-apache
|
||||
FROM php:7.3-apache
|
||||
|
||||
RUN a2enmod rewrite
|
||||
|
||||
|
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -20,7 +20,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-version: ['7.1', '7.2', '7.3']
|
||||
php-version: ['7.3']
|
||||
bitrix-edition: ['small_business_encode', 'business_encode']
|
||||
services:
|
||||
mysql:
|
||||
|
@ -42,7 +42,7 @@ jobs:
|
|||
- name: Install Bitrix
|
||||
env:
|
||||
BITRIX_EDITION: ${{ matrix.bitrix-edition }}
|
||||
run: make bitrix_install
|
||||
run: make install_bitrix
|
||||
- name: Enable debug mode for tests
|
||||
run: php bin/enable_debugging "${{ env.BITRIX_PATH }}"
|
||||
- name: Validate composer.json and composer.lock
|
||||
|
|
15
Makefile
15
Makefile
|
@ -11,7 +11,7 @@ ifneq ($(NOT_USE_VENDOR),1)
|
|||
composer install
|
||||
endif
|
||||
|
||||
bitrix_install: download_bitrix
|
||||
install_bitrix: download_bitrix
|
||||
@echo "===== Installing Bitrix..."
|
||||
@php bin/bitrix-install db_type
|
||||
@php bin/bitrix-install requirement
|
||||
|
@ -26,8 +26,8 @@ bitrix_install: download_bitrix
|
|||
download_bitrix:
|
||||
ifeq ("$(wildcard $(BITRIX_PATH)/bitrix/php_interface/dbconn.php)","")
|
||||
wget --progress=dot -e dotbytes=10M -O /tmp/$(BITRIX_EDITION).tar.gz https://www.1c-bitrix.ru/download/$(BITRIX_EDITION).tar.gz
|
||||
mkdir -p $(BITRIX_PATH)
|
||||
chmod -R 777 $(BITRIX_PATH)
|
||||
@mkdir -p $(BITRIX_PATH)
|
||||
@chmod -R 777 $(BITRIX_PATH)
|
||||
tar -xf /tmp/$(BITRIX_EDITION).tar.gz -C $(BITRIX_PATH)
|
||||
rm /tmp/$(BITRIX_EDITION).tar.gz
|
||||
endif
|
||||
|
@ -43,11 +43,4 @@ endif
|
|||
|
||||
cleanup:
|
||||
@rm -rf $(ROOT_DIR)/release/$(CURRENT_VERSION)
|
||||
@rm $(ROOT_DIR)/release/$(CURRENT_VERSION).tar.gz
|
||||
|
||||
# docker commands
|
||||
install:
|
||||
docker-compose exec bitrix make bitrix_install
|
||||
|
||||
run_tests:
|
||||
docker-compose exec bitrix make test
|
||||
@rm $(ROOT_DIR)/release/$(CURRENT_VERSION).tar.gz
|
|
@ -19,6 +19,7 @@ services:
|
|||
volumes:
|
||||
- ./:/bitrix-module
|
||||
- ./.docker/php.ini:/usr/local/etc/php/conf.d/z-bitrix.ini
|
||||
- ./tmp:/tmp
|
||||
mysql:
|
||||
env_file:
|
||||
- .env
|
||||
|
|
|
@ -58,7 +58,6 @@ foreach ($arJsConfig as $ext => $arExt) {
|
|||
|
||||
if (empty(ConfigProvider::getSitesAvailable())) {
|
||||
$client = ClientFactory::createClientAdapter();
|
||||
|
||||
try {
|
||||
$credentials = $client->getCredentials();
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ use Intaro\RetailCrm\Component\Factory\ClientFactory;
|
|||
use Intaro\RetailCrm\Component\Json\Serializer;
|
||||
use Intaro\RetailCrm\Component\ServiceLocator;
|
||||
use Intaro\RetailCrm\Model\Api\LoyaltyAccount;
|
||||
use Intaro\RetailCrm\Model\Api\LoyaltyAccountApiFilterType;
|
||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountActivateRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountCreateRequest;
|
||||
use Intaro\RetailCrm\Model\Api\Request\Loyalty\Account\LoyaltyAccountEditRequest;
|
||||
|
@ -144,9 +146,34 @@ class LoyaltyAccountService
|
|||
'UF_EXT_REG_PL_INTARO' => $createResponse->loyaltyAccount->active === true ? 'Y' : '',
|
||||
'UF_LP_ID_INTARO' => $createResponse->loyaltyAccount->id,
|
||||
]);
|
||||
}
|
||||
|
||||
Utils::handleApiErrors($createResponse, GetMessage('REGISTER_ERROR'));
|
||||
Utils::handleApiErrors($createResponse, GetMessage('REGISTER_ERROR'));
|
||||
} elseif ($this->proveUserInLpExists($createResponse)) {
|
||||
global $USER_FIELD_MANAGER;
|
||||
|
||||
/** @var \Intaro\RetailCrm\Component\ApiClient\ClientAdapter $client */
|
||||
$client = ClientFactory::createClientAdapter();
|
||||
|
||||
$sitesAvailable = ConfigProvider::getSitesAvailable();
|
||||
|
||||
$getRequest = new LoyaltyAccountRequest();
|
||||
|
||||
$getRequest->filter = new LoyaltyAccountApiFilterType();
|
||||
$getRequest->filter->sites = $sitesAvailable;
|
||||
$getRequest->filter->customerExternalId = (string)$userId;
|
||||
|
||||
|
||||
$getResponse = $client->getLoyaltyAccounts($getRequest);
|
||||
|
||||
if ($getResponse instanceof LoyaltyAccountCreateResponse) {
|
||||
Utils::handleApiErrors($getResponse, GetMessage('REGISTER_ERROR'));
|
||||
}
|
||||
|
||||
$USER_FIELD_MANAGER->Update('USER', $userId, [
|
||||
'UF_EXT_REG_PL_INTARO' => ($getResponse->loyaltyAccounts)[0]->active === true ? 'Y' : '',
|
||||
'UF_LP_ID_INTARO' => ($getResponse->loyaltyAccounts)[0]->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -510,6 +537,20 @@ class LoyaltyAccountService
|
|||
|
||||
$errorMsg = Utils::getErrorMsg($createResponse);
|
||||
|
||||
if ($this->proveUserInLpExists($createResponse)) {
|
||||
if (
|
||||
$createResponse->loyaltyAccount->active === false
|
||||
&& $createResponse->loyaltyAccount->activatedAt === null
|
||||
) {
|
||||
return [
|
||||
'msg' => GetMessage('GO_TO_PERSONAL'),
|
||||
'error' => false
|
||||
];
|
||||
} else {
|
||||
return ['msg' => GetMessage('REG_COMPLETE'), 'error' => false];
|
||||
}
|
||||
}
|
||||
|
||||
if ($errorMsg !== null) {
|
||||
return ['msg' => $errorMsg, 'error' => true];
|
||||
}
|
||||
|
@ -617,4 +658,26 @@ class LoyaltyAccountService
|
|||
|
||||
return $resultFieldsArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse|null $createResponse
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function proveUserInLpExists(?LoyaltyAccountCreateResponse $createResponse): bool
|
||||
{
|
||||
if (
|
||||
$createResponse !== null
|
||||
&& $createResponse->success !== true
|
||||
&& isset($createResponse->errors)
|
||||
&& isset(($createResponse->errors)['loyalty'])
|
||||
&& ($createResponse->errors)['loyalty'] === 'The customer is in this loyalty program already'
|
||||
) {
|
||||
$response = true;
|
||||
} else {
|
||||
$response = false;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,12 +25,16 @@ require($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.
|
|||
global $USER;
|
||||
$USER->Authorize(1);
|
||||
|
||||
if (!IsModuleInstalled('intaro.retailcrm')) {
|
||||
RegisterModule('intaro.retailcrm');
|
||||
$retailcrmModuleId = 'intaro.retailcrm';
|
||||
|
||||
if (!IsModuleInstalled($retailcrmModuleId)) {
|
||||
RegisterModule($retailcrmModuleId);
|
||||
}
|
||||
|
||||
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
||||
CModule::IncludeModule('intaro.retailcrm');
|
||||
COption::SetOptionString($retailcrmModuleId, 'api_host', 'https://test.retailcrm.ru');
|
||||
COption::SetOptionString($retailcrmModuleId, 'api_key', 'nvwhebvwevboihbwvoijn');
|
||||
COption::SetOptionString($retailcrmModuleId, 'api_version', 'v5');
|
||||
CModule::IncludeModule($retailcrmModuleId);
|
||||
|
||||
CModule::IncludeModule("main");
|
||||
global $DB;
|
||||
|
|
|
@ -113,10 +113,9 @@ class RetailCrmOrder_v5Test extends BitrixTestCase {
|
|||
],
|
||||
'payments' => [[
|
||||
'type' => $arParams['optionsPayTypes'][$arFields['PAYMENTS'][0]['PAY_SYSTEM_ID']],
|
||||
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID']),
|
||||
'status' => 'paid',
|
||||
'paidAt' => $this->getDateTime()->format('Y-m-d H:i:s')
|
||||
]]
|
||||
'externalId' => RCrmActions::generatePaymentExternalId($arFields['PAYMENTS'][0]['ID'])
|
||||
]],
|
||||
'privilegeType' => 'none'
|
||||
],
|
||||
]];
|
||||
}
|
||||
|
|
78
tests/lib/service/LoyaltyAccountServiceTest.php
Normal file
78
tests/lib/service/LoyaltyAccountServiceTest.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
use Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse;
|
||||
use Intaro\RetailCrm\Service\LoyaltyAccountService;
|
||||
|
||||
/**
|
||||
* Class LoyaltyAccountService
|
||||
*/
|
||||
class LoyaltyAccountServiceTest extends BitrixTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
COption::SetOptionString('intaro.retailcrm', 'api_version', 'v5');
|
||||
CModule::IncludeModule('intaro.retailcrm');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoyaltyAccountCreateResponse $createResponse
|
||||
* @param bool $expected
|
||||
*
|
||||
* @dataProvider proveUserInLpExistsProvider
|
||||
*/
|
||||
public function testProveUserInLpExists(LoyaltyAccountCreateResponse $createResponse, $expected)
|
||||
{
|
||||
self::assertEquals($expected,LoyaltyAccountService::proveUserInLpExists($createResponse));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoyaltyAccountCreateResponse $createResponse
|
||||
* @param bool $expected
|
||||
*
|
||||
* @dataProvider proveNotUserInLpExistsProvider
|
||||
*/
|
||||
public function testNotProveUserInLpExists(LoyaltyAccountCreateResponse $createResponse, $expected)
|
||||
{
|
||||
self::assertEquals($expected,LoyaltyAccountService::proveUserInLpExists($createResponse));
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
]];
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue