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

Allow wishlist share when all items are out of stock #26185

Merged

Conversation

pmclain
Copy link
Contributor

@pmclain pmclain commented Dec 26, 2019

Description (*)

Clicking Share on the wishlist view page updates and saves the wishlist
before redirecting to the share page. The redirection to the share page only
happens when the post body includes wishlist descriptions. Because qty and
comment are disabled for out of stock wishlist items these properties are not
sent with the post resulting in the share redirect being unreachable when all
items are out of stock.

This commit updates the controller flow separating the logic conditions for
saving and sharing. This allows sharing wishlist where all items are out of
stock.

Manual testing scenarios (*)

  1. Create simple product
  2. Make simple product out of stock
  3. Add product to wishlist
  4. Confirm wishlist only contains the out of stock product
  5. Click share

Expected Result With PR
You should be redirected to the share page for inputting email addresses and messages.

Current Behavior
You are redirected back to the wishlist view without any messaging.

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 are green)

Clicking `Share` on the wishlist view page updates and saves the wishlist
before redirecting to the share page. The redirection to the share page only
happens when the post body includes wishlist descriptions. Because qty and
comment are disabled for out of stock wishlist items these properties are not
sent with the post resulting in the share redirect being unreachable when all
items are out of stock.

This commit updates the controller flow separating the logic conditions for
saving and sharing. This allows sharing wishlist where all items are out of
stock.
@m2-assistant
Copy link

m2-assistant bot commented Dec 26, 2019

Hi @pmclain. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@magento-engcom-team magento-engcom-team added Partner: Something Digital partners-contribution Pull Request is created by Magento Partner labels Dec 26, 2019
Copy link
Contributor

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

Please cover the change with automated tests.

@ghost ghost assigned lbajsarowicz Dec 27, 2019
@pmclain
Copy link
Contributor Author

pmclain commented Dec 27, 2019

@lbajsarowicz This class is currently lacking unit/integration test coverage entirely. I have no desire to create a set of test cases from scratch. This PR is only open because it was faster to fix the issue myself then spending 1-2 weeks arguing with Magento support for a patch.

Copy link
Contributor

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

I feel your pain. I'll develop MFTF test for that change.

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-6527 has been created to process this Pull Request
✳️ @lbajsarowicz, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@engcom-Delta
Copy link
Contributor

✔️ QA passed

@engcom-Golf engcom-Golf added the Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests label Dec 30, 2019
@engcom-Golf engcom-Golf self-assigned this Dec 30, 2019
@engcom-Golf engcom-Golf added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Dec 30, 2019
/**
* Test for update method Wishlist controller.
*
* Check if there is not post value result redirect returned.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The controller will return an redirect regardless of the post value unless the requested wishlist does not exist, in which case a \Magento\Framework\Exception\NotFoundException is thrown. What if this test is updated for validating the logic within the controller? This may also be a better use case for an integration test over a unit test.

@pmclain
Copy link
Contributor Author

pmclain commented Dec 30, 2019

@engcom-Golf Feel free to close. I'll open a support ticket for the impacted clients.

@engcom-Golf
Copy link
Contributor

As we discussed on "slack", i will cover more cases with test

@Nazar65 Nazar65 force-pushed the hotfix/oos-share-wishlist branch 3 times, most recently from befc091 to 3c3018d Compare December 30, 2019 16:23
@Nazar65 Nazar65 added Auto-Tests: Covered All changes in Pull Request is covered by auto-tests and removed Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests labels Dec 30, 2019
@pmclain
Copy link
Contributor Author

pmclain commented Dec 31, 2019

@engcom-Golf thanks! looks good to me.

@engcom-Golf
Copy link
Contributor

Hi @lbajsarowicz could you please review new changes ?

@engcom-Golf
Copy link
Contributor

@magento run all tests

Copy link
Contributor

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

You need to:

  • extract magic numbers to const with correct names
  • replace class attributes names to be explicit when it's mock ($someClassMock) and doc blocks to add MockObject|

testUpdate is completely unreadable. Try to make it clear what it actually does. It's recommended to use 3 sections:

  • given
  • when
  • then

For example

// Given
$this->requestMock->method('getPostValue)->willReturn($postData);
...
$itemMock...

// When
$itemMock->method('load')->with(self::STUB_ITEM_ID)->willReturnSelf();

// Then
$this->messageManagerMock->expects($this->once())->method('addSuccessMessage');
$controllerActionResult = $this->updateController->execute();
$this->assertEquals($this->resultRedirectMock, $controllerActionResult);

Then it's clear what is actually mocked (given), what are our assumptions for the test case (when) and what are expectations (then).

/**
* @var Validator $formKeyValidator
*/
private $formKeyValidator;
Copy link
Contributor

Choose a reason for hiding this comment

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

formKeyValidatorMock

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

class UpdateTest extends TestCase
{
/**
* @var Validator $formKeyValidator
Copy link
Contributor

Choose a reason for hiding this comment

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

MockObject|Validator

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

private $formKeyValidator;

/**
* @var WishlistProviderInterface $wishlistProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

MockObject|WishlistProviderInterface

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

->method('getMessageManager')
->willReturn($this->messageManager);

$this->updateController = new Update(
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ObjectManager helper for building the tested object.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

[
[
'wishlist_data' => [
'id' => 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace magic numbers with const - for example STUB_PRODUCT_ID

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

* @dataProvider getWishlistDataProvider
* @return void
*/
public function testUpdate(array $wishlistDataProvider): void
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using wishlistDataProvider['wishlist_data'] and wishlistDataProvider['post_data'] just extract them as function parameters: testUpdateForPostRequest(array $wishlistDataProvider, array $postData) and introduce verification if no POST data provided: testUpdateRedirectWhenNoPostData().

private $wishlistProvider;

/**
* @var LocaleQuantityProcessor $quantityProcessor
Copy link
Contributor

Choose a reason for hiding this comment

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

MockObject|LocaleQuantityProcessor

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

/**
* @var LocaleQuantityProcessor $quantityProcessor
*/
private $quantityProcessor;
Copy link
Contributor

Choose a reason for hiding this comment

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

quantityProcessorMock

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

/**
* @var RequestInterface $requestMock
*/
private $requestMock;
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

private $resultFactory;

/**
* @var RequestInterface $requestMock
Copy link
Contributor

Choose a reason for hiding this comment

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

MockObject|RequestInterface

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

Copy link
Contributor

@lbajsarowicz lbajsarowicz left a comment

Choose a reason for hiding this comment

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

Small changes and we're ready to go!

$this->formKeyValidator,
$this->wishlistProvider,
$this->quantityProcessor
$this->updateController = (new ObjectManagerHelper($this))->getObject(
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract this to separate variable:
$objectManager = new ObjectManagerHelper($this);

Comment on lines 33 to 36
* Wishlist item id
*
* @var int
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use Docblocks for consts

*
* @var int
*/
private const ITEM_ID = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefix with STUB_ as it means that is just "stupid replacement" for actual value, that does not matter for tests.

Comment on lines 39 to 42
/**
* Product qty for wishlist
*
* @var int
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use docblocks for const

*/
private $formKeyValidator;
private const WISHLIST_PRODUCT_QTY = 21;
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefix with STUB_

@magento-engcom-team
Copy link
Contributor

Hi @lbajsarowicz, thank you for the review.
ENGCOM-6527 has been created to process this Pull Request

@m2-assistant
Copy link

m2-assistant bot commented Jan 17, 2020

Hi @pmclain, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Component: Wishlist Partner: Something Digital partners-contribution Pull Request is created by Magento Partner Progress: accept Release Line: 2.4
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants