-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Vahram1995/master
Creating feature tests for project
- Loading branch information
Showing
15 changed files
with
619 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="tests/bootstrap.php" | ||
colors="true" | ||
verbose="true" | ||
stopOnFailure="false"> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
verbose="true" | ||
stderr="true" | ||
processIsolation="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Quantum Test Suite"> | ||
<directory>./tests</directory> | ||
<testsuite name="Feature"> | ||
<directory suffix="Test.php">./tests/Feature</directory> | ||
</testsuite> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
<?php | ||
|
||
namespace Quantum\Tests\Feature\Api; | ||
|
||
use Quantum\Tests\Feature\AppTestCase; | ||
use Quantum\Libraries\Hasher\Hasher; | ||
use Quantum\Factory\ModelFactory; | ||
use Shared\Models\User; | ||
|
||
class AuthControllerTest extends AppTestCase | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $email = '[email protected]'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $password = 'password'; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
public function testSignInApi() | ||
{ | ||
$response = $this->request('post', '/api/en/signin', [ | ||
'email' => $this->email, | ||
'password' => $this->password | ||
]); | ||
|
||
$this->assertIsObject($response); | ||
$this->assertEquals('success', $response->get('status')); | ||
$this->assertArrayHasKey('tokens', $response->all()); | ||
} | ||
|
||
public function testSignInWithIncorrectRequestApi() | ||
{ | ||
$response = $this->request('post', '/api/en/signin', [ | ||
'email' => '[email protected]', | ||
'password' => 'password' | ||
]); | ||
|
||
$this->assertIsObject($response); | ||
$this->assertEquals('error', $response->get('status')); | ||
$this->assertEquals('Incorrect credentials', $response->get('message')); | ||
} | ||
|
||
public function testMeApi() | ||
{ | ||
$tokens = $this->signInAndReturnTokens(); | ||
|
||
$response = $this->request('get', '/api/en/me', [], ['Authorization' => 'Bearer ' . $tokens['access_token']]); | ||
|
||
$this->assertIsObject($response); | ||
$this->assertEquals('success', $response->get('status')); | ||
$this->assertIsArray($response->all()); | ||
$this->assertArrayHasKey('data', $response->all()); | ||
$this->assertIsArray($response->get('data')); | ||
$this->assertArrayHasKey('firstname', $response->get('data')); | ||
$this->assertArrayHasKey('lastname', $response->get('data')); | ||
$this->assertArrayHasKey('email', $response->get('data')); | ||
} | ||
|
||
public function testMeIncorrectApi() | ||
{ | ||
$response = $this->request('get', '/api/en/me'); | ||
|
||
$this->assertIsObject($response); | ||
$this->assertEquals('error', $response->get('status')); | ||
$this->assertEquals('Unauthorized request', $response->get('message')); | ||
} | ||
|
||
public function testSignoutApi() | ||
{ | ||
$tokens = $this->signInAndReturnTokens(); | ||
|
||
$response = $this->request('get', '/api/en/signout', [], [ | ||
'Authorization' => 'Bearer ' . $tokens['access_token'], | ||
'refresh_token' => $tokens['refresh_token'] | ||
]); | ||
|
||
$this->assertEquals('success', $response->get('status')); | ||
} | ||
|
||
public function testForgetApi() | ||
{ | ||
$response = $this->request('post', '/api/en/forget', ['email' => $this->email]); | ||
|
||
$this->assertEquals('success', $response->get('status')); | ||
$this->assertEquals('Check your email to reset your password', $response->get('message')); | ||
} | ||
|
||
public function testSignupApi() | ||
{ | ||
$response = $this->request('post', '/api/en/signup', [ | ||
'email' => '[email protected]', | ||
'password' => $this->password, | ||
'firstname' => 'firstname', | ||
'lastname' => 'lastname' | ||
]); | ||
|
||
$this->assertEquals('success', $response->get('status')); | ||
$this->assertEquals('Successfully signed up', $response->get('message')); | ||
|
||
ModelFactory::get(User::class)->findOneBy('email', '[email protected]')->delete(); | ||
} | ||
|
||
public function testSignupIncorrectApi() | ||
{ | ||
$response = $this->request('post', '/api/en/signup', [ | ||
'email' => $this->email, | ||
'password' => $this->password, | ||
'firstname' => 'firstname', | ||
'lastname' => 'lastname' | ||
]); | ||
|
||
$this->assertEquals('error', $response->get('status')); | ||
$this->assertEquals('The value of Email field is already exists in our database', $response->get('message')['email'][0]); | ||
} | ||
|
||
public function testActivateApi() | ||
{ | ||
$userModel = ModelFactory::get(User::class)->create(); | ||
$activationToken = base64_encode((new Hasher())->hash('password')); | ||
$userModel->fillObjectProps([ | ||
'email' => $this->email, | ||
'password' => (new Hasher())->hash($this->password), | ||
'firstname' => 'firstname', | ||
'lastname' => 'lastname', | ||
'activation_token' => $activationToken | ||
]); | ||
$userModel->save(); | ||
|
||
$response = $this->request('get', '/api/en/activate/' . $activationToken); | ||
|
||
$this->assertEquals('success', $response->get('status')); | ||
$this->assertEquals('Account is activated', $response->get('message')); | ||
} | ||
|
||
public function testActivateIncorrectApi() | ||
{ | ||
$response = $this->request('get', '/api/en/activate/incorrect-activation-token'); | ||
|
||
$this->assertEquals('error', $response->get('status')); | ||
$this->assertEquals('There is no record matched to token', $response->get('message')[0]); | ||
} | ||
|
||
public function testResetApi() | ||
{ | ||
$userModel = ModelFactory::get(User::class)->create(); | ||
$resetToken = base64_encode((new Hasher())->hash('password')); | ||
$userModel->fillObjectProps([ | ||
'email' => $this->email, | ||
'password' => (new Hasher())->hash($this->password), | ||
'firstname' => 'firstname', | ||
'lastname' => 'lastname', | ||
'reset_token' => $resetToken | ||
]); | ||
$userModel->save(); | ||
|
||
$response = $this->request('post', '/api/en/reset/' . $resetToken, [ | ||
'password' => $this->password, | ||
'repeat_password' => $this->password, | ||
]); | ||
|
||
$this->assertEquals('success', $response->get('status')); | ||
} | ||
|
||
public function testResetIncorrectApi() | ||
{ | ||
$response = $this->request('post', '/api/en/reset/incorrect-activation-token'); | ||
|
||
$this->assertEquals('error', $response->get('status')); | ||
$this->assertEquals('There is no record matched to token', $response->get('message')[0]); | ||
} | ||
|
||
public function testResendApi() | ||
{ | ||
|
||
$userModel = ModelFactory::get(User::class)->create(); | ||
$otpToken = base64_encode((new Hasher())->hash($this->email)); | ||
$userModel->fillObjectProps([ | ||
'email' => $this->email, | ||
'password' => (new Hasher())->hash($this->password), | ||
'firstname' => 'firstname', | ||
'lastname' => 'lastname', | ||
'otp_token' => $otpToken | ||
]); | ||
$userModel->save(); | ||
$response = $this->request('get', '/api/en/resend/' . $otpToken); | ||
|
||
$this->assertEquals('success', $response->get('status')); | ||
$this->assertArrayHasKey('code', $response->all()); | ||
$this->assertIsString($response->get('code')); | ||
} | ||
|
||
public function testResendIncorrectApi() | ||
{ | ||
$response = $this->request('get', '/api/en/resend/incorrect-otp-token'); | ||
|
||
$this->assertEquals('error', $response->get('status')); | ||
$this->assertEquals('Incorrect credentials', $response->get('message')); | ||
} | ||
|
||
public function testVerifyApi() | ||
{ | ||
$userModel = ModelFactory::get(User::class)->create(); | ||
$otpToken = base64_encode((new Hasher())->hash($this->email)); | ||
$userModel->fillObjectProps([ | ||
'email' => $this->email, | ||
'password' => (new Hasher())->hash($this->password), | ||
'firstname' => 'firstname', | ||
'lastname' => 'lastname', | ||
'otp_token' => $otpToken, | ||
'otp' => $otpToken | ||
]); | ||
$userModel->save(); | ||
|
||
$response = $this->request('post', '/api/en/verify', [ | ||
'otp' => $otpToken, | ||
'code' => $otpToken, | ||
]); | ||
|
||
$this->assertEquals('success', $response->get('status')); | ||
$this->assertArrayHasKey('tokens', $response->all()); | ||
$this->assertArrayHasKey('refresh_token', $response->get('tokens')); | ||
$this->assertArrayHasKey('access_token', $response->get('tokens')); | ||
} | ||
|
||
public function testVerifyIncorrectApi() | ||
{ | ||
$response = $this->request('post', '/api/en/verify', [ | ||
'otp' => 'incorrect-otp', | ||
'code' => 'incorrect-code', | ||
]); | ||
|
||
$this->assertEquals('error', $response->get('status')); | ||
$this->assertEquals('Incorrect verification code.', $response->get('message')); | ||
} | ||
|
||
public function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
} | ||
} |
Oops, something went wrong.