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

Cannot merge company with itself #13578

Open
wants to merge 11 commits into
base: 5.x
Choose a base branch
from

Conversation

nishant-s7
Copy link

Q A
Bug fix? (use the a.b branch) [x]
New feature/enhancement? (use the a.x branch) [ ]
Deprecations? [ ]
BC breaks? (use the c.x branch) [ ]
Automated tests included? [ ]
Related user documentation PR URL mautic/mautic-documentation#...
Related developer documentation PR URL mautic/developer-documentation#...
Issue(s) addressed Fixes #12599

Description:

This PR blocks the possibility of merging a company with itself by not showing the company in the merge list.
image

Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs here)
  2. Go to Companies and click on any company.
  3. Click on Merge (available in the header options).
  4. In the Search options, verify whether the currently viewed company is present or not.

@andersonjeccel andersonjeccel requested review from escopecz, a team, code5rick and Mike-Dropsolid and removed request for a team April 2, 2024 18:01
@andersonjeccel andersonjeccel added bug Issues or PR's relating to bugs user-experience Anything related to related to workflows, feedback, and navigation companies Anything related to companies labels Apr 2, 2024
@nishant-s7 nishant-s7 force-pushed the fix-merge-company-with-itself branch from b49a218 to bd4e484 Compare April 3, 2024 03:13
app/bundles/LeadBundle/Entity/CompanyRepository.php Outdated Show resolved Hide resolved
app/bundles/LeadBundle/Model/CompanyModel.php Outdated Show resolved Hide resolved
app/bundles/LeadBundle/Model/CompanyModel.php Outdated Show resolved Hide resolved
@RCheesley RCheesley added the T1 Low difficulty to fix (issue) or test (PR) label Apr 4, 2024
RCheesley
RCheesley previously approved these changes Apr 4, 2024
Copy link
Sponsor Member

@RCheesley RCheesley left a comment

Choose a reason for hiding this comment

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

Works great - I don't see the current company in the list of available companies to merge into:

screenshot-mautic ddev site-2024 04 04-10_11_19

Thanks for the PR @nishant-s7 and welcome to the community! 🚀

@RCheesley RCheesley added code-review-passed PRs which have passed code review pending-test-confirmation PR's that require one test before they can be merged and removed code-review-passed PRs which have passed code review labels Apr 4, 2024
@RCheesley
Copy link
Sponsor Member

Looks like there's still some issues which need to be addressed with the automated tests here @nishant-s7 - I've marked this for a second user test, please shout if you need help with addressing the test failures.

@nishant-s7
Copy link
Author

nishant-s7 commented Apr 4, 2024

I think the tests are failing because I added

'model_lookup_method' => 'getSimpleLookupResults',
                'lookup_arguments'    => fn (Options $options): array => [
                    'type'     => 'lead.company',
                    'exclude'  => $options['main_entity'],
                ],

to CompanyListType.php, so for each case it is using getSimpleLookupResults instead of getLookupResults (which is desired). So I think I need to pass an optional parameter CompanyController.php's mergeAction function. I will proceed with this approach, but if anyone has a better approach, please let me know.

Thanks!

Copy link

@PatrickJenkner PatrickJenkner left a comment

Choose a reason for hiding this comment

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

Worked as described when tested 👍

@PatrickJenkner PatrickJenkner added code-review-needed PR's that require a code review before merging user-testing-passed PRs which have been successfully tested by the required number of people. and removed pending-test-confirmation PR's that require one test before they can be merged labels Apr 5, 2024
Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 73.80952% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 61.31%. Comparing base (4039055) to head (504292f).

❗ Current head 504292f differs from pull request most recent head 1ded149. Consider uploading reports for the commit 1ded149 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##                5.x   #13578      +/-   ##
============================================
- Coverage     61.38%   61.31%   -0.07%     
+ Complexity    34024    34012      -12     
============================================
  Files          2238     2238              
  Lines        101685   101679       -6     
============================================
- Hits          62420    62349      -71     
- Misses        39265    39330      +65     
Files Coverage Δ
...dle/Form/ChoiceLoader/EntityLookupChoiceLoader.php 83.49% <100.00%> (-9.65%) ⬇️
.../bundles/CoreBundle/Form/Type/EntityLookupType.php 97.56% <100.00%> (ø)
...undles/LeadBundle/Controller/CompanyController.php 51.65% <100.00%> (+3.59%) ⬆️
...pp/bundles/LeadBundle/Entity/CompanyRepository.php 58.40% <100.00%> (+0.55%) ⬆️
...p/bundles/LeadBundle/Form/Type/CompanyListType.php 100.00% <100.00%> (ø)
.../bundles/LeadBundle/Form/Type/CompanyMergeType.php 100.00% <100.00%> (+100.00%) ⬆️
app/bundles/LeadBundle/Model/CompanyModel.php 69.80% <56.00%> (-0.92%) ⬇️

... and 19 files with indirect coverage changes

@nishant-s7 nishant-s7 force-pushed the fix-merge-company-with-itself branch from 2b69b91 to eb5a3ac Compare April 5, 2024 12:59
@nishant-s7
Copy link
Author

Hello! How do I address this test failure?

Error: Codecov: Failed to properly upload: The process '/home/runner/work/_actions/codecov/codecov-action/v3/dist/codecov' failed with exit code 255

@escopecz
Copy link
Sponsor Member

escopecz commented Apr 8, 2024

It's a network issue. I restarted the failed job

Copy link
Contributor

@LordRembo LordRembo left a comment

Choose a reason for hiding this comment

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

Looking good! Tests failing again though. Seems to be happening on other PR's as well since couple of days.

@escopecz
Copy link
Sponsor Member

escopecz commented Apr 9, 2024

It's usually just a temporary issue. I re-triggered it again. @nishant-s7 by the rule book each PR should have a test covering the change functions as it should so it won't get broken with future changes and the whole platform is more stable. Do you know how to write a functional test? There are many examples of such test in each bundle. If you'll need help, feel free to ask here for on Slack.

@escopecz escopecz added the needs-automated-tests PR's that need automated tests before they can be merged label Apr 9, 2024
@nishant-s7
Copy link
Author

I've never written any functional tests, but I'll try to do so by referring to the examples👍
Thanks!

@escopecz
Copy link
Sponsor Member

escopecz commented Apr 9, 2024

@nishant-s7 thanks! You can check for example https://github.com/mautic/mautic/blob/5.x/app/bundles/LeadBundle/Tests/Functional/Controller/LeadControllerTest.php#L38

The test should:

  1. Create 2 companies
  2. Make a GET request to load the form to merge companies
  3. Assert that only the other company is present in the HTML output, not the one from the request.

@nishant-s7
Copy link
Author

Hello!
How do I run a specific test? As mentioned here, I tried running

bin/phpunit --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --filter "/::testVariantEmailWeightsAreAppropriateForMultipleContacts( .*)?$/" Mautic\EmailBundle\Tests\EmailModelTest app/bundles/EmailBundle/Tests/Model/EmailModelTest.php

but it throws this error Cannot open file "MauticEmailBundleTestsEmailModelTest".

@shinde-rahul
Copy link
Contributor

@nishant-s7, Use this bin/phpunit --bootstrap vendor/autoload.php --configuration app/phpunit.xml.dist --filter testVariantEmailWeightsAreAppropriateForMultipleContacts instead. I have never tried the way it is documented.

@nishant-s7
Copy link
Author

Hi @shinde-rahul , on trying this, i got this error: Error: Undefined constant "Mautic\EmailBundle\MonitoredEmail\SORTARRIVAL". I tried for another simple test which I wrote, and it gave Error: Class "PDO" not found. I checked modules using php -m and PDO is present. Is there any procedure that I have to follow before testing?

@escopecz
Copy link
Sponsor Member

I usually run specific tests with

composer test -- --filter testVariantEmailWeightsAreAppropriateForMultipleContacts

Those are weird failures. Do you have the right PHP version and composer dependencies installed? If you use DDEV or other container setup for development, you have to run the test from the container. So in case of DDEV you'd firstly ddev ssh into the container and then run the test.

@nishant-s7 nishant-s7 force-pushed the fix-merge-company-with-itself branch from eb5a3ac to d84d8bd Compare April 13, 2024 06:55
Copy link
Sponsor Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

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

Nice test! Thanks! Please check my question and a suggestion.

app/bundles/CoreBundle/Form/Type/EntityLookupType.php Outdated Show resolved Hide resolved
app/bundles/LeadBundle/Entity/CompanyRepository.php Outdated Show resolved Hide resolved
@nishant-s7 nishant-s7 force-pushed the fix-merge-company-with-itself branch from 504292f to b3e268c Compare April 23, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs code-review-needed PR's that require a code review before merging companies Anything related to companies needs-automated-tests PR's that need automated tests before they can be merged T1 Low difficulty to fix (issue) or test (PR) user-experience Anything related to related to workflows, feedback, and navigation user-testing-passed PRs which have been successfully tested by the required number of people.
Projects
Status: 🚨 Developer revision needed
Development

Successfully merging this pull request may close these issues.

Should not be able to merge a company with itself!
7 participants