Skip to content

Commit

Permalink
PIM-10967: Fix inconsistency on DQI completeness recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentPetard committed May 4, 2023
1 parent 259db7f commit 1939a66
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -67,6 +67,7 @@
- PIM-10814: Wysiwyg now supports languages that use right-to-left (rtl) scripts
- PIM-10956: Fix deletion of category with enriched category template
- PIM-10914: Add title and ellipsis for long labels on attribute select
- PIM-10967: Fix inconsistency on DQI completeness recommendation
- PIM-10639 : Prevent users to change his password without providing its current password

## Improvements
Expand Down
Expand Up @@ -61,8 +61,13 @@ private function completeCompletenessEvaluation(
$evaluationResultData = $criterionEvaluation->getResult()->getData();
$evaluationResultData['attributes_with_rates'] = $this->getAttributesWithRates($completenessResult);

/**
* In some cases the rates of the persisted result are different from the one just calculated (See PIM-10967)
* It can happen when the required attributes list of a family has been changed, but the impacted products have not been re-evaluated yet
* So we also need to replace the rates to be always accurate with the list of improvable attributes
*/
$completedCriterionEvaluationResult = new Read\CriterionEvaluationResult(
$criterionEvaluation->getResult()->getRates(),
$completenessResult->getRates(),
$criterionEvaluation->getResult()->getStatus(),
$evaluationResultData
);
Expand Down
Expand Up @@ -24,7 +24,6 @@
use Akeneo\Pim\Automation\DataQualityInsights\Domain\ValueObject\Rate;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Ramsey\Uuid\Uuid;

/**
* @copyright 2021 Akeneo SAS (http://www.akeneo.com)
Expand Down Expand Up @@ -57,12 +56,17 @@ public function it_completes_a_product_evaluation_with_improvable_attributes(
'mobile' => ['en_US'],
]));

$requiredAttributesCompletenessResult = new CompletenessCalculationResult();
$requiredAttributesCompletenessResult->addMissingAttributes($channelCodeEcommerce, $localeCodeEn, ['description', 'name']);
$requiredAttributesCompletenessResult->addMissingAttributes($channelCodeMobile, $localeCodeEn, []);
$requiredAttributesCompletenessResult = (new CompletenessCalculationResult())
->addRate($channelCodeEcommerce, $localeCodeEn, new Rate(80))
->addMissingAttributes($channelCodeEcommerce, $localeCodeEn, ['description', 'name'])
->addRate($channelCodeMobile, $localeCodeEn, new Rate(100))
->addMissingAttributes($channelCodeMobile, $localeCodeEn, []);

$nonRequiredAttributesCompletenessResult = new CompletenessCalculationResult();
$nonRequiredAttributesCompletenessResult->addMissingAttributes($channelCodeEcommerce, $localeCodeEn, ['title', 'meta_title']);
$nonRequiredAttributesCompletenessResult = (new CompletenessCalculationResult())
->addRate($channelCodeEcommerce, $localeCodeEn, new Rate(75))
->addMissingAttributes($channelCodeEcommerce, $localeCodeEn, ['title', 'meta_title'])
->addRate($channelCodeMobile, $localeCodeEn, new Rate(100))
->addMissingAttributes($channelCodeMobile, $localeCodeEn, []);;

$calculateRequiredAttributesCompleteness->calculate($productUuid)->willReturn($requiredAttributesCompletenessResult);
$calculateNonRequiredAttributesCompleteness->calculate($productUuid)->willReturn($nonRequiredAttributesCompletenessResult);
Expand All @@ -86,6 +90,15 @@ public function it_completes_a_product_evaluation_with_improvable_attributes(
]
]);

$completedRequiredCompletenessEvaluation->getResult()->getRates()->toArrayInt()->shouldBe([
'ecommerce' => [
'en_US' => 80
],
'mobile' => [
'en_US' =>100
],
]);

$completedRequiredCompletenessEvaluation->getProductId()->shouldBe($productUuid);
$completedRequiredCompletenessEvaluation->getStatus()->shouldBe($requiredCompletenessEvaluation->getStatus());
$completedRequiredCompletenessEvaluation->getEvaluatedAt()->shouldBe($requiredCompletenessEvaluation->getEvaluatedAt());
Expand All @@ -105,6 +118,14 @@ public function it_completes_a_product_evaluation_with_improvable_attributes(
'mobile' => ['en_US' => []],
]
]);
$completedNonRequiredCompletenessEvaluation->getResult()->getRates()->toArrayInt()->shouldBe([
'ecommerce' => [
'en_US' => 75
],
'mobile' => [
'en_US' =>100
],
]);

$spellingCriterionCode = new CriterionCode('consistency_spelling');
$completedCriteriaEvaluations->get($spellingCriterionCode)->shouldBe($criteriaEvaluations->get($spellingCriterionCode));
Expand Down Expand Up @@ -132,7 +153,7 @@ private function givenProductCriteriaEvaluationsWithCompleteness(ProductUuid $pr
$localeCodeEn = new LocaleCode('en_US');

$completenessOfRequiredAttributesRates = (new ChannelLocaleRateCollection())
->addRate($channelCodeEcommerce, $localeCodeEn, new Rate(95))
->addRate($channelCodeEcommerce, $localeCodeEn, new Rate(100))
->addRate($channelCodeMobile, $localeCodeEn, new Rate(70));

$completenessOfRequiredAttributesStatus = (new CriterionEvaluationResultStatusCollection())
Expand Down

0 comments on commit 1939a66

Please sign in to comment.