add tests

This commit is contained in:
qfrery
2018-07-15 22:19:51 +01:00
parent 2851fa3a4a
commit 0d461c2e30
2 changed files with 48 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ use Codeception\Stub\Expected;
use MailPoet\API\JSON\v1\Services;
use MailPoet\API\JSON\Response as APIResponse;
use MailPoet\Config\Installer;
use MailPoet\Models\Setting;
use MailPoet\Services\Bridge;
class ServicesTest extends \MailPoetTest {
@@ -263,4 +264,32 @@ class ServicesTest extends \MailPoetTest {
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
expect($response->errors[0]['message'])->equals('test');
}
function testItRespondsContainsPublicIdForMSS() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkMSSKey' => array('state' => Bridge::KEY_VALID),
'storeMSSKeyAndState' => Expected::once()
),
$this
);
$response = $this->services_endpoint->checkMSSKey($this->data);
expect($response->data['public_id'])->notEmpty();
expect($response->data['public_id'])->equals(Setting::getValue('public_id'););
}
function testItRespondsContainsPublicIdForPremium() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkPremiumKey' => array('state' => Bridge::KEY_VALID),
'storeMSSKeyAndState' => Expected::once()
),
$this
);
$response = $this->services_endpoint->checkMSSKey($this->data);
expect($response->data['public_id'])->notEmpty();
expect($response->data['public_id'])->equals(Setting::getValue('public_id'););
}
}

View File

@@ -102,4 +102,22 @@ class AnalyticsTest extends \MailPoetTest {
expect($analytics->generateAnalytics())->equals($data);
}
function testSetPublicId() {
$analytics = new Analytics(new Reporter());
$fakePublicId = 'alk-ded-egrg-zaz-fvf-rtr-zdef';
Setting::setValue('new_public_id', 'true');
$analytics->setPublicId($fakePublicId);
expect(Setting::getValue('public_id'))->equals($fakePublicId);
// When we update public_id it's marked as new
expect(Setting::getValue('new_public_id'))->equals('true');
expect(Setting::isPublicIdNew())->true();
$analytics->setPublicId($fakePublicId);
expect(Setting::getValue('public_id'))->equals($fakePublicId);
// We tried to update public_id with the same value, so it's not marked as new
expect(Setting::getValue('new_public_id'))->equals('false');
expect(Setting::isPublicIdNew())->false();
}
}