Change error message when request is almost empty

[MAILPOET-3469]
This commit is contained in:
Jan Lysý
2021-06-09 10:12:28 +02:00
committed by Veljko V
parent 72a3bfa35e
commit 97dd402d21
2 changed files with 11 additions and 5 deletions

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types = 1);
namespace MailPoet\API\JSON\v1; namespace MailPoet\API\JSON\v1;
@ -143,6 +143,8 @@ class DynamicSegments extends APIEndpoint {
return WPFunctions::get()->__('Please select a type for the comparison, a number of orders and a number of days.', 'mailpoet'); return WPFunctions::get()->__('Please select a type for the comparison, a number of orders and a number of days.', 'mailpoet');
case InvalidFilterException::MISSING_TOTAL_SPENT_FIELDS: case InvalidFilterException::MISSING_TOTAL_SPENT_FIELDS:
return WPFunctions::get()->__('Please select a type for the comparison, an amount and a number of days.', 'mailpoet'); return WPFunctions::get()->__('Please select a type for the comparison, an amount and a number of days.', 'mailpoet');
case InvalidFilterException::MISSING_FILTER:
return WPFunctions::get()->__('Please add at least one condition for filtering.', 'mailpoet');
default: default:
return WPFunctions::get()->__('An error occurred while saving data.', 'mailpoet'); return WPFunctions::get()->__('An error occurred while saving data.', 'mailpoet');
} }

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types = 1);
namespace MailPoet\API\JSON\v1; namespace MailPoet\API\JSON\v1;
@ -9,6 +9,7 @@ use MailPoet\Entities\DynamicSegmentFilterEntity;
use MailPoet\Entities\NewsletterEntity; use MailPoet\Entities\NewsletterEntity;
use MailPoet\Entities\NewsletterSegmentEntity; use MailPoet\Entities\NewsletterSegmentEntity;
use MailPoet\Entities\SegmentEntity; use MailPoet\Entities\SegmentEntity;
use MailPoet\Segments\DynamicSegments\Filters\UserRole;
class DynamicSegmentsTest extends \MailPoetTest { class DynamicSegmentsTest extends \MailPoetTest {
@ -42,8 +43,11 @@ class DynamicSegmentsTest extends \MailPoetTest {
$response = $this->endpoint->save([ $response = $this->endpoint->save([
'name' => 'Test dynamic', 'name' => 'Test dynamic',
'description' => 'description dynamic', 'description' => 'description dynamic',
'filters' => [[
'segmentType' => DynamicSegmentFilterData::TYPE_USER_ROLE, 'segmentType' => DynamicSegmentFilterData::TYPE_USER_ROLE,
'wordpressRole' => 'editor', 'wordpressRole' => 'editor',
'action' => UserRole::TYPE,
]],
]); ]);
expect($response)->isInstanceOf('\MailPoet\API\JSON\SuccessResponse'); expect($response)->isInstanceOf('\MailPoet\API\JSON\SuccessResponse');
expect($response->status)->equals(self::SUCCESS_RESPONSE_CODE); expect($response->status)->equals(self::SUCCESS_RESPONSE_CODE);
@ -56,7 +60,7 @@ class DynamicSegmentsTest extends \MailPoetTest {
]); ]);
expect($response)->isInstanceOf('\MailPoet\API\JSON\ErrorResponse'); expect($response)->isInstanceOf('\MailPoet\API\JSON\ErrorResponse');
expect($response->status)->equals(self::INVALID_DATA_RESPONSE_CODE); expect($response->status)->equals(self::INVALID_DATA_RESPONSE_CODE);
expect($response->errors[0]['message'])->equals('The segment type is missing.'); expect($response->errors[0]['message'])->equals('Please add at least one condition for filtering.');
} }
public function testSaverReturnsErrorOnDuplicateRecord() { public function testSaverReturnsErrorOnDuplicateRecord() {