Integration tests for provisioning
[MAILPOET-5131]
This commit is contained in:
committed by
Aschepikov
parent
fc8837e03c
commit
c0eed5b919
@ -38,7 +38,7 @@ class DotcomLicenseProvisioner {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isAtomicPlatform(): bool {
|
||||
public function isAtomicPlatform(): bool {
|
||||
return defined('IS_ATOMIC') && IS_ATOMIC && defined('ATOMIC_CLIENT_ID') && (ATOMIC_CLIENT_ID === '2');
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ class DotcomLicenseProvisioner {
|
||||
* @param string $apiKey
|
||||
* @return true|WP_Error
|
||||
*/
|
||||
private function activateMSS(string $apiKey) {
|
||||
public function activateMSS(string $apiKey) {
|
||||
$response = $this->settings->setupMSS($apiKey);
|
||||
if ($response instanceof ErrorResponse) {
|
||||
$this->loggerFactory->getLogger(LoggerFactory::TOPIC_PROVISIONING)->error(
|
||||
|
@ -313,6 +313,35 @@ class SettingsTest extends \MailPoetTest {
|
||||
expect($this->endpoint->delete('unexistent_setting'))->isInstanceOf(ErrorResponse::class);
|
||||
}
|
||||
|
||||
public function testItSetsUpMSSWithProvidedKey() {
|
||||
$newKey = 'some-new-key';
|
||||
$this->endpoint = new Settings(
|
||||
$this->settings,
|
||||
$this->make(Bridge::class, ['onSettingsSave' => Expected::once()]),
|
||||
$this->make(AuthorizedEmailsController::class, ['onSettingsSave' => Expected::once()]),
|
||||
$this->diContainer->get(AuthorizedSenderDomainController::class),
|
||||
$this->make(TransactionalEmails::class),
|
||||
WPFunctions::get(),
|
||||
$this->diContainer->get(EntityManager::class),
|
||||
$this->diContainer->get(NewslettersRepository::class),
|
||||
$this->diContainer->get(StatisticsOpensRepository::class),
|
||||
$this->diContainer->get(ScheduledTasksRepository::class),
|
||||
$this->diContainer->get(FormMessageController::class),
|
||||
$this->make(ServicesChecker::class, ['isMailPoetAPIKeyPendingApproval' => false]),
|
||||
$this->diContainer->get(SegmentsRepository::class),
|
||||
$this->diContainer->get(SettingsChangeHandler::class),
|
||||
$this->diContainer->get(SubscribersCountsController::class),
|
||||
$this->diContainer->get(TrackingConfig::class),
|
||||
$this->diContainer->get(ConfirmationEmailCustomizer::class)
|
||||
);
|
||||
|
||||
expect($this->endpoint->setupMSS($newKey))->isInstanceOf(SuccessResponse::class);
|
||||
expect($this->settings->get('mta.mailpoet_api_key'))->equals($newKey);
|
||||
expect($this->settings->get('mta_group'))->equals('mailpoet');
|
||||
expect($this->settings->get('mta.method'))->equals('MailPoet');
|
||||
expect($this->settings->get('signup_confirmation.enabled'))->equals(1);
|
||||
}
|
||||
|
||||
private function createNewsletter(string $type, string $status = NewsletterEntity::STATUS_DRAFT, $parent = null): NewsletterEntity {
|
||||
$newsletter = new NewsletterEntity();
|
||||
$newsletter->setType($type);
|
||||
|
@ -0,0 +1,113 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace MailPoet\WPCOM;
|
||||
|
||||
use MailPoet\API\JSON\ErrorResponse;
|
||||
use MailPoet\API\JSON\SuccessResponse;
|
||||
use MailPoet\API\JSON\v1\Services;
|
||||
use MailPoet\API\JSON\v1\Settings;
|
||||
use MailPoet\Logging\LoggerFactory;
|
||||
use MailPoet\Logging\LogRepository;
|
||||
use MailPoet\Settings\SettingsRepository;
|
||||
|
||||
class DotcomLicenseProvisionerTest extends \MailPoetTest {
|
||||
/** @var DotcomLicenseProvisioner */
|
||||
private $provisioner;
|
||||
|
||||
public function _before() {
|
||||
parent::_before();
|
||||
$this->provisioner = $this->construct(
|
||||
DotcomLicenseProvisioner::class,
|
||||
[
|
||||
$this->diContainer->get(LoggerFactory::class),
|
||||
$this->make(Settings::class),
|
||||
$this->make(Services::class),
|
||||
],
|
||||
['isAtomicPlatform' => true]);
|
||||
}
|
||||
|
||||
public function testItReturnsResultIfNotAtomic() {
|
||||
$result = false;
|
||||
$payload = ['apiKey' => 'some-key'];
|
||||
$provisioner = $this->construct(
|
||||
DotcomLicenseProvisioner::class,
|
||||
[
|
||||
$this->make(LoggerFactory::class),
|
||||
$this->make(Settings::class),
|
||||
$this->make(Services::class),
|
||||
],
|
||||
['isAtomicPlatform' => false]);
|
||||
expect($provisioner->provisionLicense($result, $payload, DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE))->equals($result);
|
||||
}
|
||||
|
||||
public function testItReturnsResultIfWrongEvent() {
|
||||
$result = false;
|
||||
$payload = ['apiKey' => 'some-key'];
|
||||
$eventType = 'wrong-event';
|
||||
expect($this->provisioner->provisionLicense($result, $payload, $eventType))->equals($result);
|
||||
}
|
||||
|
||||
public function testItReturnsWPErrorIfMissingKey() {
|
||||
$result = false;
|
||||
$payload = [];
|
||||
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
|
||||
$error = $this->provisioner->provisionLicense($result, $payload, $eventType);
|
||||
$this->assertInstanceOf(\WP_Error::class, $error);
|
||||
expect($error->get_error_message())->equals('Invalid license payload: Missing API key.');
|
||||
}
|
||||
|
||||
public function testItReturnsWPErrorIfErrorOnSettingUpMSS() {
|
||||
$result = false;
|
||||
$payload = ['apiKey' => 'some-key'];
|
||||
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
|
||||
$provisioner = $this->construct(
|
||||
DotcomLicenseProvisioner::class,
|
||||
[
|
||||
$this->diContainer->get(LoggerFactory::class),
|
||||
$this->make(Settings::class, ['setupMSS' => new ErrorResponse(['error' => 'some-error'])]),
|
||||
$this->make(Services::class, ['refreshMSSKeyStatus' => new SuccessResponse()]),
|
||||
],
|
||||
['isAtomicPlatform' => true]);
|
||||
$error = $provisioner->provisionLicense($result, $payload, $eventType);
|
||||
$this->assertInstanceOf(\WP_Error::class, $error);
|
||||
expect($error->get_error_message())->equals('some-error ');
|
||||
}
|
||||
|
||||
public function testItReturnsTrueIfCouldNotRefreshKey() {
|
||||
$result = false;
|
||||
$payload = ['apiKey' => 'some-key'];
|
||||
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
|
||||
$provisioner = $this->construct(
|
||||
DotcomLicenseProvisioner::class,
|
||||
[
|
||||
$this->diContainer->get(LoggerFactory::class),
|
||||
$this->make(Settings::class, ['setupMSS' => new SuccessResponse()]),
|
||||
$this->make(Services::class, ['refreshMSSKeyStatus' => new ErrorResponse(['error' => 'some-error'])]),
|
||||
],
|
||||
['isAtomicPlatform' => true]);
|
||||
$error = $provisioner->provisionLicense($result, $payload, $eventType);
|
||||
$this->assertInstanceOf(\WP_Error::class, $error);
|
||||
expect($error->get_error_message())->equals('some-error ');
|
||||
}
|
||||
|
||||
public function testItReturnsTrueIfKeyProvidedMSSActivatedAndRefreshed() {
|
||||
$result = false;
|
||||
$payload = ['apiKey' => 'some-key'];
|
||||
$eventType = DotcomLicenseProvisioner::EVENT_TYPE_PROVISION_LICENSE;
|
||||
$provisioner = $this->construct(
|
||||
DotcomLicenseProvisioner::class,
|
||||
[
|
||||
$this->diContainer->get(LoggerFactory::class),
|
||||
$this->make(Settings::class, ['setupMSS' => new SuccessResponse()]),
|
||||
$this->make(Services::class, ['refreshMSSKeyStatus' => new SuccessResponse()]),
|
||||
],
|
||||
['isAtomicPlatform' => true]);
|
||||
$result = $provisioner->provisionLicense($result, $payload, $eventType);
|
||||
expect($result)->equals(true);
|
||||
}
|
||||
|
||||
public function _after() {
|
||||
$this->diContainer->get(SettingsRepository::class)->truncate();
|
||||
$this->diContainer->get(LogRepository::class)->truncate();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user