Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckoutAgreements getList refactoring #13221

Merged
merged 6 commits into from
Jan 22, 2018

Conversation

sidolov
Copy link
Contributor

@sidolov sidolov commented Jan 16, 2018

Description

Introduced new listing interface for Checkout Agreements with ability to set search criteria.

Manual testing scenarios

  1. Covered with api-functional tests
  2. Verify main cases with agreements on checkout flow

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

Copy link
Contributor

@ishakhsuvarov ishakhsuvarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using aliases instead of long class names where possible.

*
* @api
*/
interface CheckoutAgreementsListingInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to rename this to CheckoutAgreementsListInterface

* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return \Magento\CheckoutAgreements\Api\Data\AgreementInterface[]
*/
public function getListing(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria) : array;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To remain consistent with the rest of the codebase it would make sense to rename method to getList

namespace Magento\CheckoutAgreements\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;

class StoreFilter implements
\Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using alias for this long name.

\Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface $collectionProcessor
) {
$this->collectionFactory = $collectionFactory;
$this->extAttributesJoinProcessor = $extensionAttributesJoinProcessor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid shortened names like extAttributes as it may be unclear what it is supposed to do

namespace Magento\CheckoutAgreements\Api;

/**
* Interface CheckoutAgreementsListingInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to include background for such kind of interface

@@ -13,4 +13,10 @@
<resource ref="Magento_Sales::sales" />
</resources>
</route>
<route url="/V1/carts/licence/listing" method="GET">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest renaming route to list.
Please refer to Magento\Catalog\Api\CategoryListInterface to remain consistent with it.

) {
$this->agreementsValidator = $agreementsValidator;
$this->scopeConfiguration = $scopeConfiguration;
$this->checkoutAgreementsRepository = $checkoutAgreementsRepository;
$this->checkoutAgreementsList = $checkoutAgreementsList ?: ObjectManager::getInstance()->get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugins are not covered by backward compatibility policy. You may add dependencies as required parameters here.

@@ -117,7 +158,21 @@ private function isAgreementEnabled()
AgreementsProvider::PATH_ENABLED,
ScopeInterface::SCOPE_STORE
);
$agreementsList = $isAgreementsEnabled ? $this->checkoutAgreementsRepository->getList() : [];
$storeFilter = $this->filterBuilder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece of code occurs multiple times in this PR along with 3 dependencies to support it.
It would make sense to extract it to a separate service.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just workflow with searchCriteria mechanism, I think it will be useless create new service only for couple of filters

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introducing this many boilerplate code creates a challenge in maintenance of it.
It is much easier to fix/update only 1 service instead of searching all over the module in the future.

) {
$this->agreementsValidator = $agreementsValidator;
$this->scopeConfiguration = $scopeConfiguration;
$this->checkoutAgreementsRepository = $checkoutAgreementsRepository;
$this->checkoutAgreementsList = $checkoutAgreementsList ?: ObjectManager::getInstance()->get(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugins are not covered by BC policy. See above.

@@ -74,7 +115,7 @@ public function beforeSavePaymentInformationAndPlaceOrder(
* @param string $email
* @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod
* @param \Magento\Quote\Api\Data\AddressInterface|null $billingAddress
* @return void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method still seems to return void.


namespace Magento\CheckoutAgreements\Model;

class CheckoutAgreementsList implements \Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class description or inheritdoc would be worth adding here.

$storeFilterMock = $this->createMock(\Magento\Framework\Api\Filter::class);
$activeFilterMock = $this->createMock(\Magento\Framework\Api\Filter::class);

$this->filterBuilderMock->expects($this->at(0))->method('setField')->with('store_id')->willReturnSelf();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of test looks like it is intended to freeze code state but not ensure quality.
I would suggest using other approaches or even test types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic also covered with integration test \Magento\CheckoutAgreements\Model\Checkout\Plugin\GuestValidationTest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unit test may be redundant in this case. You may remove it or leave as is.

@ishakhsuvarov ishakhsuvarov self-assigned this Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants