Add Settings::setAuthorizedFromAddress() API integration tests
[MAILPOET-2804]
This commit is contained in:
@ -6,8 +6,11 @@ use Codeception\Stub\Expected;
|
||||
use MailPoet\API\JSON\Error as APIError;
|
||||
use MailPoet\API\JSON\Response as APIResponse;
|
||||
use MailPoet\API\JSON\v1\Settings;
|
||||
use MailPoet\Config\ServicesChecker;
|
||||
use MailPoet\Cron\Workers\InactiveSubscribers;
|
||||
use MailPoet\Mailer\MailerLog;
|
||||
use MailPoet\Models\ScheduledTask;
|
||||
use MailPoet\Newsletter\NewslettersRepository;
|
||||
use MailPoet\Services\AuthorizedEmailsController;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\Settings\SettingsController;
|
||||
@ -33,7 +36,8 @@ class SettingsTest extends \MailPoetTest {
|
||||
$this->settings,
|
||||
new Bridge,
|
||||
$this->make(AuthorizedEmailsController::class, ['onSettingsSave' => true ]),
|
||||
$this->make(TransactionalEmails::class)
|
||||
$this->make(TransactionalEmails::class),
|
||||
$this->make(ServicesChecker::class)
|
||||
);
|
||||
}
|
||||
|
||||
@ -65,7 +69,8 @@ class SettingsTest extends \MailPoetTest {
|
||||
$this->settings,
|
||||
$this->make(Bridge::class, ['onSettingsSave' => Expected::once()]),
|
||||
$this->make(AuthorizedEmailsController::class, ['onSettingsSave' => Expected::once()]),
|
||||
$this->make(TransactionalEmails::class)
|
||||
$this->make(TransactionalEmails::class),
|
||||
$this->make(ServicesChecker::class)
|
||||
);
|
||||
|
||||
$response = $this->endpoint->set(/* missing data */);
|
||||
@ -82,6 +87,44 @@ class SettingsTest extends \MailPoetTest {
|
||||
expect($response->data['some']['new_setting'])->true();
|
||||
}
|
||||
|
||||
public function testItSetsAuthorizedFromAddressAndResumesSending() {
|
||||
$bridgeMock = $this->make(Bridge::class, ['getAuthorizedEmailAddresses' => Expected::once(['authorized@email.com'])]);
|
||||
$this->endpoint = new Settings(
|
||||
$this->settings,
|
||||
$bridgeMock,
|
||||
new AuthorizedEmailsController($this->settings, $bridgeMock, $this->diContainer->get(NewslettersRepository::class)),
|
||||
$this->make(TransactionalEmails::class),
|
||||
$this->make(ServicesChecker::class, ['isMailPoetAPIKeyPendingApproval' => false])
|
||||
);
|
||||
|
||||
MailerLog::pauseSending(MailerLog::getMailerLog());
|
||||
$this->settings->set('sender.address', '');
|
||||
$response = $this->endpoint->setAuthorizedFromAddress(['address' => 'authorized@email.com']);
|
||||
expect($response->status)->same(200);
|
||||
expect($this->settings->get('sender.address'))->same('authorized@email.com');
|
||||
expect(MailerLog::isSendingPaused())->false();
|
||||
}
|
||||
|
||||
public function testItRejectsUnauthorizedFromAddress() {
|
||||
$bridgeMock = $this->make(Bridge::class, ['getAuthorizedEmailAddresses' => Expected::once(['authorized@email.com'])]);
|
||||
$this->endpoint = new Settings(
|
||||
$this->settings,
|
||||
$bridgeMock,
|
||||
new AuthorizedEmailsController($this->settings, $bridgeMock, $this->diContainer->get(NewslettersRepository::class)),
|
||||
$this->make(TransactionalEmails::class),
|
||||
$this->make(ServicesChecker::class)
|
||||
);
|
||||
|
||||
$this->settings->set('sender.address', '');
|
||||
$response = $this->endpoint->setAuthorizedFromAddress(['address' => 'invalid@email.com']);
|
||||
expect($response->status)->same(400);
|
||||
expect($response->getData()['errors'][0])->same([
|
||||
'error' => 'unauthorized',
|
||||
'message' => 'Can’t use this email yet! Please authorize it first.',
|
||||
]);
|
||||
expect($this->settings->get('sender.address'))->same('');
|
||||
}
|
||||
|
||||
public function testItSchedulesInactiveSubscribersCheckIfIntervalSettingChanges() {
|
||||
$this->settings->set('deactivate_subscriber_after_inactive_days', 30);
|
||||
$settings = ['deactivate_subscriber_after_inactive_days' => 30];
|
||||
|
Reference in New Issue
Block a user