Add unit tests [PREMIUM-4]
This commit is contained in:
@@ -11,13 +11,13 @@ class ServicesTest extends MailPoetTest {
|
||||
$this->data = array('key' => '1234567890abcdef');
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfNoKeyIsGiven() {
|
||||
function testItRespondsWithErrorIfNoMSSKeyIsGiven() {
|
||||
$response = $this->services_endpoint->verifyMailPoetKey(array('key' => ''));
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals('Please specify a key.');
|
||||
}
|
||||
|
||||
function testItRespondsWithSuccessIfKeyIsValid() {
|
||||
function testItRespondsWithSuccessIfMSSKeyIsValid() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkKey' => array('state' => Bridge::MAILPOET_KEY_VALID)),
|
||||
@@ -27,7 +27,7 @@ class ServicesTest extends MailPoetTest {
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfKeyIsInvalid() {
|
||||
function testItRespondsWithErrorIfMSSKeyIsInvalid() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkKey' => array('state' => Bridge::MAILPOET_KEY_INVALID)),
|
||||
@@ -37,7 +37,7 @@ class ServicesTest extends MailPoetTest {
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfKeyIsExpiring() {
|
||||
function testItRespondsWithErrorIfMSSKeyIsExpiring() {
|
||||
$date = new DateTime;
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
@@ -52,7 +52,7 @@ class ServicesTest extends MailPoetTest {
|
||||
expect($response->data['message'])->contains($date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfServiceIsUnavailable() {
|
||||
function testItRespondsWithErrorIfServiceIsUnavailableDuringMSSCheck() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
|
||||
@@ -62,4 +62,88 @@ class ServicesTest extends MailPoetTest {
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains((string)Bridge::CHECK_ERROR_UNAVAILABLE);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfMSSCheckThrowsAnException() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkKey' => function() { throw new \Exception('test'); }),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->verifyMailPoetKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->equals('test');
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfNoPremiumKeyIsGiven() {
|
||||
$response = $this->services_endpoint->verifyPremiumKey(array('key' => ''));
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals('Please specify a key.');
|
||||
}
|
||||
|
||||
function testItRespondsWithSuccessIfPremiumKeyIsValid() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkPremiumKey' => array('state' => Bridge::PREMIUM_KEY_VALID)),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->verifyPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfPremiumKeyIsInvalid() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkPremiumKey' => array('state' => Bridge::PREMIUM_KEY_INVALID)),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->verifyPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfPremiumKeyIsUsed() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkPremiumKey' => array('state' => Bridge::PREMIUM_KEY_USED)),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->verifyPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfPremiumKeyIsExpiring() {
|
||||
$date = new DateTime;
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkPremiumKey' => array(
|
||||
'state' => Bridge::PREMIUM_KEY_EXPIRING,
|
||||
'data' => array('expire_at' => $date->format('c'))
|
||||
)),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->verifyPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data['message'])->contains($date->format('Y-m-d'));
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfServiceIsUnavailableDuringPremiumCheck() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkPremiumKey' => array('code' => Bridge::CHECK_ERROR_UNAVAILABLE)),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->verifyPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains((string)Bridge::CHECK_ERROR_UNAVAILABLE);
|
||||
}
|
||||
|
||||
function testItRespondsWithErrorIfPremiumCheckThrowsAnException() {
|
||||
$this->services_endpoint->bridge = Stub::make(
|
||||
new Bridge(),
|
||||
array('checkPremiumKey' => function() { throw new \Exception('test'); }),
|
||||
$this
|
||||
);
|
||||
$response = $this->services_endpoint->verifyPremiumKey($this->data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->equals('test');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user