fix failing bridge tests

This commit is contained in:
qfrery
2018-07-17 13:03:50 +01:00
parent 7b4e63c8c5
commit 3a2ee709eb
2 changed files with 62 additions and 8 deletions

View File

@ -2,6 +2,7 @@
namespace MailPoet\API\JSON\v1;
use MailPoet\Analytics\Analytics;
use MailPoet\API\JSON\Endpoint as APIEndpoint;
use MailPoet\API\JSON\Error as APIError;
use MailPoet\Config\AccessControl;

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 {
@ -264,31 +265,83 @@ class ServicesTest extends \MailPoetTest {
expect($response->errors[0]['message'])->equals('test');
}
function testItRespondsContainsPublicIdForMSS() {
function testItRespondsWithPublicIdForMSS() {
$fake_public_id = 'a-fake-public_id';
Setting::deleteValue('public_id');
Setting::deleteValue('new_public_id');
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkMSSKey' => array('state' => Bridge::KEY_VALID),
'checkMSSKey' => array(
'state' => Bridge::KEY_VALID,
'data' => array( 'public_id' => $fake_public_id )
),
'storeMSSKeyAndState' => Expected::once()
),
$this
);
$response = $this->services_endpoint->checkMSSKey($this->data);
expect(isset($response->data['public_id']))->true();
expect($response->data['public_id'])->notEmpty();
expect(Setting::getValue('public_id'))->equals($fake_public_id);
expect(Setting::getValue('new_public_id'))->equals('true');
}
function testItRespondsContainsPublicIdForPremium() {
function testItRespondsWithoutPublicIdForMSS() {
Setting::deleteValue('public_id');
Setting::deleteValue('new_public_id');
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkPremiumKey' => array('state' => Bridge::KEY_VALID),
'checkMSSKey' => array( 'state' => Bridge::KEY_VALID ),
'storeMSSKeyAndState' => Expected::once()
),
$this
);
$response = $this->services_endpoint->checkMSSKey($this->data);
expect(Setting::getValue('public_id', null))->null();
expect(Setting::getValue('new_public_id', null))->null();
}
function testItRespondsWithPublicIdForPremium() {
$fake_public_id = 'another-fake-public_id';
Setting::deleteValue('public_id');
Setting::deleteValue('new_public_id');
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkPremiumKey' => array(
'state' => Bridge::KEY_VALID,
'data' => array( 'public_id' => $fake_public_id )
),
'storePremiumKeyAndState' => Expected::once()
),
$this
);
$response = $this->services_endpoint->checkPremiumKey($this->data);
expect(isset($response->data['public_id']))->true();
expect($response->data['public_id'])->notEmpty();
expect(Setting::getValue('public_id'))->equals($fake_public_id);
expect(Setting::getValue('new_public_id'))->equals('true');
}
function testItRespondsWithoutPublicIdForPremium() {
Setting::deleteValue('public_id');
Setting::deleteValue('new_public_id');
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkPremiumKey' => array('state' => Bridge::KEY_VALID),
'storePremiumKeyAndState' => Expected::once()
),
$this
);
$response = $this->services_endpoint->checkPremiumKey($this->data);
expect(Setting::getValue('public_id', null))->null();
expect(Setting::getValue('new_public_id', null))->null();
}
}