2018-02-28 03:57:35 +05:30
|
|
|
<?php
|
2019-09-18 04:44:05 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace api\tests\functional\dev\applications;
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\_pages\OauthRoute;
|
|
|
|
use api\tests\FunctionalTester;
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2022-12-10 07:21:47 +05:30
|
|
|
final class CreateClientCest {
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2022-12-10 07:21:47 +05:30
|
|
|
private OauthRoute $route;
|
2018-02-28 03:57:35 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function _before(FunctionalTester $I): void {
|
2018-02-28 03:57:35 +05:30
|
|
|
$this->route = new OauthRoute($I);
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testCreateApplication(FunctionalTester $I): void {
|
2018-02-28 03:57:35 +05:30
|
|
|
$I->amAuthenticated('admin');
|
|
|
|
$this->route->createClient('application', [
|
|
|
|
'name' => 'My admin application',
|
|
|
|
'description' => 'Application description.',
|
|
|
|
'redirectUri' => 'http://some-site.com/oauth/ely',
|
|
|
|
'websiteUrl' => 'http://some-site.com',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => true,
|
|
|
|
'data' => [
|
|
|
|
'clientId' => 'my-admin-application',
|
|
|
|
'name' => 'My admin application',
|
|
|
|
'description' => 'Application description.',
|
|
|
|
'websiteUrl' => 'http://some-site.com',
|
|
|
|
'countUsers' => 0,
|
|
|
|
'redirectUri' => 'http://some-site.com/oauth/ely',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.clientSecret');
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.createdAt');
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testCreateMinecraftServer(FunctionalTester $I): void {
|
2018-02-28 03:57:35 +05:30
|
|
|
$I->amAuthenticated('admin');
|
|
|
|
$this->route->createClient('minecraft-server', [
|
|
|
|
'name' => 'My amazing server',
|
|
|
|
'websiteUrl' => 'http://some-site.com',
|
|
|
|
'minecraftServerIp' => 'hypixel.com:25565',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => true,
|
|
|
|
'data' => [
|
|
|
|
'clientId' => 'my-amazing-server',
|
|
|
|
'name' => 'My amazing server',
|
|
|
|
'websiteUrl' => 'http://some-site.com',
|
|
|
|
'minecraftServerIp' => 'hypixel.com:25565',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.clientSecret');
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.data.createdAt');
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function testCreateApplicationWithTheSameNameAsDeletedApp(FunctionalTester $I): void {
|
2018-11-11 16:18:23 +05:30
|
|
|
$I->wantTo('create application with the same name as the recently deleted application');
|
|
|
|
$I->amAuthenticated('admin');
|
|
|
|
$this->route->createClient('application', [
|
|
|
|
'name' => 'Deleted OAuth Client',
|
|
|
|
'description' => '',
|
|
|
|
'redirectUri' => 'http://some-site.com/oauth/ely',
|
|
|
|
'websiteUrl' => 'http://some-site.com',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => true,
|
|
|
|
'data' => [
|
|
|
|
'clientId' => 'deleted-oauth-client1',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-12-10 07:21:47 +05:30
|
|
|
public function testCreateApplicationWithWrongParams(FunctionalTester $I): void {
|
|
|
|
$I->amAuthenticated('admin');
|
|
|
|
|
|
|
|
$this->route->createClient('application', []);
|
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'success' => false,
|
|
|
|
'errors' => [
|
|
|
|
'name' => 'error.name_required',
|
|
|
|
'redirectUri' => 'error.redirectUri_required',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-02-28 03:57:35 +05:30
|
|
|
}
|