Make key check error messages more descriptive [MAILPOET-990]

This commit is contained in:
stoletniy
2017-07-07 12:44:38 +03:00
committed by pavel-mailpoet
parent 3499de05e8
commit 91ff008485
2 changed files with 94 additions and 6 deletions

View File

@ -74,7 +74,43 @@ class ServicesTest extends MailPoetTest {
);
$response = $this->services_endpoint->checkMSSKey($this->data);
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
expect($response->errors[0]['message'])->contains((string)Bridge::CHECK_ERROR_UNAVAILABLE);
expect($response->errors[0]['message'])->contains(
$this->invokeMethod(
$this->services_endpoint, 'getErrorDescriptionByCode', array(Bridge::CHECK_ERROR_UNAVAILABLE)
)
);
}
function testItRespondsWithErrorIfServiceDidNotReturnAResponseCodeDuringMSSCheck() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkMSSKey' => null,
'storeMSSKeyAndState' => Stub::once()
),
$this
);
$response = $this->services_endpoint->checkMSSKey($this->data);
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
expect($response->errors[0]['message'])->contains(
$this->invokeMethod(
$this->services_endpoint, 'getErrorDescriptionByCode', array(Bridge::CHECK_ERROR_UNKNOWN)
)
);
}
function testItPrintsErrorCodeIfServiceReturnedAnUnexpectedResponseCodeDuringMSSCheck() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkMSSKey' => array('code' => 404),
'storeMSSKeyAndState' => Stub::once()
),
$this
);
$response = $this->services_endpoint->checkMSSKey($this->data);
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
expect($response->errors[0]['message'])->contains('404');
}
function testItRespondsWithErrorIfMSSCheckThrowsAnException() {
@ -171,7 +207,43 @@ class ServicesTest extends MailPoetTest {
);
$response = $this->services_endpoint->checkPremiumKey($this->data);
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
expect($response->errors[0]['message'])->contains((string)Bridge::CHECK_ERROR_UNAVAILABLE);
expect($response->errors[0]['message'])->contains(
$this->invokeMethod(
$this->services_endpoint, 'getErrorDescriptionByCode', array(Bridge::CHECK_ERROR_UNAVAILABLE)
)
);
}
function testItRespondsWithErrorIfServiceDidNotReturnAResponseCodeDuringPremiumCheck() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkPremiumKey' => null,
'storePremiumKeyAndState' => Stub::once()
),
$this
);
$response = $this->services_endpoint->checkPremiumKey($this->data);
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
expect($response->errors[0]['message'])->contains(
$this->invokeMethod(
$this->services_endpoint, 'getErrorDescriptionByCode', array(Bridge::CHECK_ERROR_UNKNOWN)
)
);
}
function testItPrintsErrorCodeIfServiceReturnedAnUnexpectedResponseCodeDuringPremiumCheck() {
$this->services_endpoint->bridge = Stub::make(
new Bridge(),
array(
'checkPremiumKey' => array('code' => 404),
'storePremiumKeyAndState' => Stub::once()
),
$this
);
$response = $this->services_endpoint->checkPremiumKey($this->data);
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
expect($response->errors[0]['message'])->contains('404');
}
function testItRespondsWithErrorIfPremiumCheckThrowsAnException() {