Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: test oauth login #2188

Merged
merged 14 commits into from Jan 26, 2019
17 changes: 13 additions & 4 deletions .circleci/config.yml
Expand Up @@ -52,11 +52,18 @@ aliases:
- &seed-test-db
run:
name: Seed database
command: php artisan db:seed --no-interaction -vvv
command: |
php artisan db:seed --no-interaction -vvv
php artisan passport:keys --no-interaction -vvv
- &http-server-cc
run:
name: Run http server
command: php -S localhost:8000 -t public scripts/tests/server-cc.php
background: true
- &http-server
run:
name: Run http server
command: php -S localhost:8000 -t public scripts/tests/server-cc.php 2>/dev/null
command: php artisan serve
background: true
- &wait-for-server
run:
Expand Down Expand Up @@ -207,6 +214,8 @@ jobs:
- *remove-xdebug
- *prepare-db
- *seed-test-db
- *http-server
- *wait-for-server
- *unit-tests
- store_test_results:
path: results/junit
Expand Down Expand Up @@ -247,7 +256,7 @@ jobs:
- *prepare-db
- *seed-test-db
- *selenium
- *http-server
- *http-server-cc
- *wait-for-server
- *browser-tests
- *fix-coverage
Expand Down Expand Up @@ -279,7 +288,7 @@ jobs:
- *restore_node
- *yarn-install
- *prepare-db
- *http-server
- *http-server-cc
- *wait-for-server
- *browser-cypress
- *fix-coverage2
Expand Down
Binary file modified .circleci/config.yml.sig
Binary file not shown.
67 changes: 67 additions & 0 deletions tests/Api/Auth/AuthControllerTest.php
@@ -0,0 +1,67 @@
<?php

namespace Tests\Api\Auth;

use Tests\ApiTestCase;
use App\Models\User\User;
use Laravel\Passport\ClientRepository;

class AuthControllerTest extends ApiTestCase
{
public function setUp()
{
parent::setUp();

if ($this->getActualConnection() != 'testing') {
$this->markTestSkipped("Set DB_CONNECTION on 'testing' to run this test.");
}
}

private function getActualConnection()
{
$handle = fopen('.env', 'r');
if (! $handle) {
return;
}
while (($line = fgets($handle)) !== false) {
if (preg_match('/DB_CONNECTION=(.{1,})/', $line, $matches)) {
fclose($handle);

return $matches[1];
}
}

fclose($handle);
}

protected $jsonStructureOAuthLogin = [
'access_token',
'expires_in',
];

public function test_oauth_login()
{
$client = (new ClientRepository())->createPasswordGrantClient(
null, config('app.name'), config('app.url')
);

config([
'monica.mobile_client_id' => $client->id,
'monica.mobile_client_secret' => $client->secret,
]);

$userPassword = 'password';
$user = factory(User::class)->create([
'password' => bcrypt($userPassword),
]);

$response = $this->json('POST', '/oauth/login', [
'email' => $user->email,
'password' => $userPassword,
]);

$response->assertStatus(200);

$response->assertJsonStructure($this->jsonStructureOAuthLogin);
}
}