Add API endpoint to delete a setting

[MAILPOET-4814]
This commit is contained in:
Rodrigo Primo
2023-01-18 15:10:30 -03:00
committed by Aschepikov
parent 8a4f5c13da
commit ad4247a241
2 changed files with 44 additions and 0 deletions

View File

@ -5,7 +5,9 @@ namespace MailPoet\Test\API\JSON\v1;
use Codeception\Stub\Expected;
use Codeception\Util\Fixtures;
use MailPoet\API\JSON\Error as APIError;
use MailPoet\API\JSON\ErrorResponse;
use MailPoet\API\JSON\Response as APIResponse;
use MailPoet\API\JSON\SuccessResponse;
use MailPoet\API\JSON\v1\Settings;
use MailPoet\Config\ServicesChecker;
use MailPoet\Cron\Workers\InactiveSubscribers;
@ -296,6 +298,21 @@ class SettingsTest extends \MailPoetTest {
expect($response->meta['showNotice'])->equals(false);
}
public function testItCanDeleteSetting() {
$this->settings->set('setting_to_be_deleted', true);
$response = $this->endpoint->delete('setting_to_be_deleted');
expect($response)->isInstanceOf(SuccessResponse::class);
expect($this->settings->get('setting_to_be_deleted'))->null();
}
public function testDeleteReturnErrorForEmptySettingName() {
expect($this->endpoint->delete(''))->isInstanceOf(ErrorResponse::class);
}
public function testDeleteReturnErrorIfSettingDoesntExist() {
expect($this->endpoint->delete('unexistent_setting'))->isInstanceOf(ErrorResponse::class);
}
private function createNewsletter(string $type, string $status = NewsletterEntity::STATUS_DRAFT, $parent = null): NewsletterEntity {
$newsletter = new NewsletterEntity();
$newsletter->setType($type);