Add additional tests cases, implemented custom error formatter

This commit is contained in:
ErickSkrauch
2022-01-28 12:38:00 +01:00
parent 9593d1e809
commit f4fa5ad2df
3 changed files with 92 additions and 5 deletions

View File

@@ -3,15 +3,15 @@ declare(strict_types=1);
namespace api\tests\functional\mojang;
use api\tests\functional\_steps\OauthSteps;
use api\tests\FunctionalTester;
class ProfileCest {
final class ProfileCest {
public function getProfile(FunctionalTester $I): void {
$I->amAuthenticated();
$I->sendGet('/api/mojang/services/minecraft/profile');
$I->canSeeResponseCodeIs(200);
$I->canSeeResponseIsJson();
$I->canSeeResponseContainsJson([
'id' => 'df936908b2e1544d96f82977ec213022',
'name' => 'Admin',
@@ -28,7 +28,31 @@ class ProfileCest {
]);
}
// TODO: add cases for unauthenticated user
// TODO: add cases for authenticated as a service account user
public function getProfileAsServiceAccount(OauthSteps $I): void {
$accessToken = $I->getAccessTokenByClientCredentialsGrant(['internal_account_info']);
$I->amBearerAuthenticated($accessToken);
$I->sendGet('/api/mojang/services/minecraft/profile');
$I->canSeeResponseCodeIs(404);
$I->canSeeResponseContainsJson([
'path' => '/mojang/services/minecraft/profile',
'errorType' => 'NOT_FOUND',
'error' => 'NOT_FOUND',
'errorMessage' => 'The server has not found anything matching the request URI',
'developerMessage' => 'The server has not found anything matching the request URI',
]);
}
public function getProfileWithoutAuthentication(FunctionalTester $I): void {
$I->sendGet('/api/mojang/services/minecraft/profile');
$I->canSeeResponseCodeIs(401);
$I->canSeeResponseContainsJson([
'path' => '/mojang/services/minecraft/profile',
'errorType' => 'UnauthorizedOperationException',
'error' => 'UnauthorizedOperationException',
'errorMessage' => 'Unauthorized',
'developerMessage' => 'Unauthorized',
]);
}
}