mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Rework tests structure. Upgrade codeception to 2.5.3. Merge params configuration into app configuration.
This commit is contained in:
80
api/tests/_pages/AccountsRoute.php
Normal file
80
api/tests/_pages/AccountsRoute.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class AccountsRoute extends BasePage {
|
||||
|
||||
public function get(int $accountId) {
|
||||
$this->getActor()->sendGET("/api/v1/accounts/{$accountId}");
|
||||
}
|
||||
|
||||
public function changePassword(int $accountId, $currentPassword = null, $newPassword = null, $newRePassword = null) {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/password", [
|
||||
'password' => $currentPassword,
|
||||
'newPassword' => $newPassword,
|
||||
'newRePassword' => $newRePassword,
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeUsername(int $accountId, $currentPassword = null, $newUsername = null) {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/username", [
|
||||
'password' => $currentPassword,
|
||||
'username' => $newUsername,
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeEmailInitialize(int $accountId, $password = '') {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/email-verification", [
|
||||
'password' => $password,
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeEmailSubmitNewEmail(int $accountId, $key = null, $email = null) {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/new-email-verification", [
|
||||
'key' => $key,
|
||||
'email' => $email,
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeEmail(int $accountId, $key = null) {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/email", [
|
||||
'key' => $key,
|
||||
]);
|
||||
}
|
||||
|
||||
public function changeLanguage(int $accountId, $lang = null) {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/language", [
|
||||
'lang' => $lang,
|
||||
]);
|
||||
}
|
||||
|
||||
public function acceptRules(int $accountId) {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/rules");
|
||||
}
|
||||
|
||||
public function getTwoFactorAuthCredentials(int $accountId) {
|
||||
$this->getActor()->sendGET("/api/v1/accounts/{$accountId}/two-factor-auth");
|
||||
}
|
||||
|
||||
public function enableTwoFactorAuth(int $accountId, $totp = null, $password = null) {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/two-factor-auth", [
|
||||
'totp' => $totp,
|
||||
'password' => $password,
|
||||
]);
|
||||
}
|
||||
|
||||
public function disableTwoFactorAuth(int $accountId, $totp = null, $password = null) {
|
||||
$this->getActor()->sendDELETE("/api/v1/accounts/{$accountId}/two-factor-auth", [
|
||||
'totp' => $totp,
|
||||
'password' => $password,
|
||||
]);
|
||||
}
|
||||
|
||||
public function ban(int $accountId) {
|
||||
$this->getActor()->sendPOST("/api/v1/accounts/{$accountId}/ban");
|
||||
}
|
||||
|
||||
public function pardon(int $accountId) {
|
||||
$this->getActor()->sendDELETE("/api/v1/accounts/{$accountId}/ban");
|
||||
}
|
||||
|
||||
}
|
52
api/tests/_pages/AuthenticationRoute.php
Normal file
52
api/tests/_pages/AuthenticationRoute.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class AuthenticationRoute extends BasePage {
|
||||
|
||||
/**
|
||||
* @param string $login
|
||||
* @param string $password
|
||||
* @param string|bool|null $rememberMeOrToken
|
||||
* @param bool $rememberMe
|
||||
*/
|
||||
public function login($login = '', $password = '', $rememberMeOrToken = null, $rememberMe = false) {
|
||||
$params = [
|
||||
'login' => $login,
|
||||
'password' => $password,
|
||||
];
|
||||
|
||||
if ((is_bool($rememberMeOrToken) && $rememberMeOrToken) || $rememberMe) {
|
||||
$params['rememberMe'] = 1;
|
||||
} elseif ($rememberMeOrToken !== null) {
|
||||
$params['totp'] = $rememberMeOrToken;
|
||||
}
|
||||
|
||||
$this->getActor()->sendPOST('/api/authentication/login', $params);
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
$this->getActor()->sendPOST('/api/authentication/logout');
|
||||
}
|
||||
|
||||
public function forgotPassword($login = null, $token = null) {
|
||||
$this->getActor()->sendPOST('/api/authentication/forgot-password', [
|
||||
'login' => $login,
|
||||
'totp' => $token,
|
||||
]);
|
||||
}
|
||||
|
||||
public function recoverPassword($key = null, $newPassword = null, $newRePassword = null) {
|
||||
$this->getActor()->sendPOST('/api/authentication/recover-password', [
|
||||
'key' => $key,
|
||||
'newPassword' => $newPassword,
|
||||
'newRePassword' => $newRePassword,
|
||||
]);
|
||||
}
|
||||
|
||||
public function refreshToken($refreshToken = null) {
|
||||
$this->getActor()->sendPOST('/api/authentication/refresh-token', [
|
||||
'refresh_token' => $refreshToken,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
26
api/tests/_pages/AuthserverRoute.php
Normal file
26
api/tests/_pages/AuthserverRoute.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class AuthserverRoute extends BasePage {
|
||||
|
||||
public function authenticate($params) {
|
||||
$this->getActor()->sendPOST('/api/authserver/authentication/authenticate', $params);
|
||||
}
|
||||
|
||||
public function refresh($params) {
|
||||
$this->getActor()->sendPOST('/api/authserver/authentication/refresh', $params);
|
||||
}
|
||||
|
||||
public function validate($params) {
|
||||
$this->getActor()->sendPOST('/api/authserver/authentication/validate', $params);
|
||||
}
|
||||
|
||||
public function invalidate($params) {
|
||||
$this->getActor()->sendPOST('/api/authserver/authentication/invalidate', $params);
|
||||
}
|
||||
|
||||
public function signout($params) {
|
||||
$this->getActor()->sendPOST('/api/authserver/authentication/signout', $params);
|
||||
}
|
||||
|
||||
}
|
21
api/tests/_pages/BasePage.php
Normal file
21
api/tests/_pages/BasePage.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
use api\tests\FunctionalTester;
|
||||
|
||||
class BasePage {
|
||||
|
||||
/**
|
||||
* @var FunctionalTester
|
||||
*/
|
||||
private $actor;
|
||||
|
||||
public function __construct(FunctionalTester $I) {
|
||||
$this->actor = $I;
|
||||
}
|
||||
|
||||
public function getActor(): FunctionalTester {
|
||||
return $this->actor;
|
||||
}
|
||||
|
||||
}
|
10
api/tests/_pages/IdentityInfoRoute.php
Normal file
10
api/tests/_pages/IdentityInfoRoute.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class IdentityInfoRoute extends BasePage {
|
||||
|
||||
public function info() {
|
||||
$this->getActor()->sendGET('/api/account/v1/info');
|
||||
}
|
||||
|
||||
}
|
10
api/tests/_pages/InternalRoute.php
Normal file
10
api/tests/_pages/InternalRoute.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class InternalRoute extends BasePage {
|
||||
|
||||
public function info(string $param, string $value) {
|
||||
$this->getActor()->sendGET('/api/internal/accounts/info', [$param => $value]);
|
||||
}
|
||||
|
||||
}
|
19
api/tests/_pages/MojangApiRoute.php
Normal file
19
api/tests/_pages/MojangApiRoute.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class MojangApiRoute extends BasePage {
|
||||
|
||||
public function usernameToUuid($username, $at = null) {
|
||||
$params = $at === null ? [] : ['at' => $at];
|
||||
$this->getActor()->sendGET("/api/mojang/profiles/{$username}", $params);
|
||||
}
|
||||
|
||||
public function usernamesByUuid($uuid) {
|
||||
$this->getActor()->sendGET("/api/mojang/profiles/{$uuid}/names");
|
||||
}
|
||||
|
||||
public function uuidsByUsernames($uuids) {
|
||||
$this->getActor()->sendPOST('/api/mojang/profiles', $uuids);
|
||||
}
|
||||
|
||||
}
|
42
api/tests/_pages/OauthRoute.php
Normal file
42
api/tests/_pages/OauthRoute.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class OauthRoute extends BasePage {
|
||||
|
||||
public function validate(array $queryParams): void {
|
||||
$this->getActor()->sendGET('/api/oauth2/v1/validate', $queryParams);
|
||||
}
|
||||
|
||||
public function complete(array $queryParams = [], array $postParams = []): void {
|
||||
$this->getActor()->sendPOST('/api/oauth2/v1/complete?' . http_build_query($queryParams), $postParams);
|
||||
}
|
||||
|
||||
public function issueToken(array $postParams = []): void {
|
||||
$this->getActor()->sendPOST('/api/oauth2/v1/token', $postParams);
|
||||
}
|
||||
|
||||
public function createClient(string $type, array $postParams): void {
|
||||
$this->getActor()->sendPOST('/api/v1/oauth2/' . $type, $postParams);
|
||||
}
|
||||
|
||||
public function updateClient(string $clientId, array $params): void {
|
||||
$this->getActor()->sendPUT('/api/v1/oauth2/' . $clientId, $params);
|
||||
}
|
||||
|
||||
public function deleteClient(string $clientId): void {
|
||||
$this->getActor()->sendDELETE('/api/v1/oauth2/' . $clientId);
|
||||
}
|
||||
|
||||
public function resetClient(string $clientId, bool $regenerateSecret = false): void {
|
||||
$this->getActor()->sendPOST("/api/v1/oauth2/$clientId/reset" . ($regenerateSecret ? '?regenerateSecret' : ''));
|
||||
}
|
||||
|
||||
public function getClient(string $clientId): void {
|
||||
$this->getActor()->sendGET("/api/v1/oauth2/$clientId");
|
||||
}
|
||||
|
||||
public function getPerAccount(int $accountId): void {
|
||||
$this->getActor()->sendGET("/api/v1/accounts/$accountId/oauth2/clients");
|
||||
}
|
||||
|
||||
}
|
10
api/tests/_pages/OptionsRoute.php
Normal file
10
api/tests/_pages/OptionsRoute.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class OptionsRoute extends BasePage {
|
||||
|
||||
public function get() {
|
||||
$this->getActor()->sendGET('/api/options');
|
||||
}
|
||||
|
||||
}
|
26
api/tests/_pages/SessionServerRoute.php
Normal file
26
api/tests/_pages/SessionServerRoute.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class SessionServerRoute extends BasePage {
|
||||
|
||||
public function join($params) {
|
||||
$this->getActor()->sendPOST('/api/minecraft/session/join', $params);
|
||||
}
|
||||
|
||||
public function joinLegacy(array $params) {
|
||||
$this->getActor()->sendGET('/api/minecraft/session/legacy/join', $params);
|
||||
}
|
||||
|
||||
public function hasJoined(array $params) {
|
||||
$this->getActor()->sendGET('/api/minecraft/session/hasJoined', $params);
|
||||
}
|
||||
|
||||
public function hasJoinedLegacy(array $params) {
|
||||
$this->getActor()->sendGET('/api/minecraft/session/legacy/hasJoined', $params);
|
||||
}
|
||||
|
||||
public function profile($profileUuid) {
|
||||
$this->getActor()->sendGET("/api/minecraft/session/profile/{$profileUuid}");
|
||||
}
|
||||
|
||||
}
|
20
api/tests/_pages/SignupRoute.php
Normal file
20
api/tests/_pages/SignupRoute.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace api\tests\_pages;
|
||||
|
||||
class SignupRoute extends BasePage {
|
||||
|
||||
public function register(array $registrationData) {
|
||||
$this->getActor()->sendPOST('/api/signup', $registrationData);
|
||||
}
|
||||
|
||||
public function sendRepeatMessage($email = '') {
|
||||
$this->getActor()->sendPOST('/api/signup/repeat-message', ['email' => $email]);
|
||||
}
|
||||
|
||||
public function confirm($key = '') {
|
||||
$this->getActor()->sendPOST('/api/signup/confirm', [
|
||||
'key' => $key,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user