Skip to content

Commit

Permalink
feat: tried solved test error in the pipeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
victore13 committed Sep 18, 2024
1 parent dca2b94 commit f91872c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: run-tests
name: Pest

on:
push:
Expand All @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
php: [8.3, 8.2]
laravel: [11.*, 10.*]
stability: [prefer-lowest, prefer-stable]
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"autoload-dev": {
"psr-4": {
"Raiolanetworks\\OAuth\\Tests\\": "tests/",
"Raiolanetworks\\OAuth\\Tests\\Database\\Factories\\": "tests/database/factories/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
Expand Down
7 changes: 2 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
<testsuite name="Raiola Networks - Development Team">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/OAuthCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ protected function setConfigVariables(): void
);

$loginRoute = text(
label: 'Login route:',
placeholder: 'E.g. /login',
default: '/login',
label: 'Login route name:',
placeholder: 'E.g. login',
default: 'login',
);

config()->set('oauth.user_model_name', $modelName);
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$this->artisan('oauth:install')
->expectsQuestion('Model name Authenticatable:', TestUser::class)
->expectsQuestion('Main guard name:', 'web')
->expectsQuestion('Login route:', '/login')
->expectsQuestion('Login route name:', 'login')
->expectsQuestion('Oauth base url:', 'https://asgard.your.company')
->expectsQuestion('Oauth client ID:', 'CLIENTID')
->expectsQuestion('Oauth client secret key:', 'SECRETKEY')
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,37 @@
// Temporal route
Route::get('/login', function () {
return 'Login Page';
})->name(config()->string('oauth.login_route_name'));
})->name(config('oauth.login_route_name'));

Session::put('oauth2-state', 'correct_state');

$response = $this->get(route('oauth.callback'), [
'state' => 'correct_state',
]);

$response->assertRedirect(route(config()->string('oauth.login_route_name')))
$response->assertRedirect(route(config('oauth.login_route_name')))
->assertSessionHas('message', 'Authentication failed. Please try again.');
});

it('handles invalid state in callback', function () {
// Temporal route
Route::get('/login', function () {
return 'Login Page';
})->name(config()->string('oauth.login_route_name'));
})->name(config('oauth.login_route_name'));

$response = $this->get(route('oauth.callback', [
'code' => 'valid_code',
]));

$response->assertRedirect(route(config()->string('oauth.login_route_name')))
$response->assertRedirect(route(config('oauth.login_route_name')))
->assertSessionHas('message', 'Authentication failed. Please try again.');
});

it('logs in the user after a successful OAuth callback', function () {
// Temporal route
Route::get('/login', function () {
return 'Login Page';
})->name(config()->string('oauth.login_route_name'));
})->name(config('oauth.login_route_name'));

$mockOAuthService = Mockery::mock(OAuthService::class);

Expand Down Expand Up @@ -196,7 +196,7 @@
// Temporal route
Route::get('/login', function () {
return 'Login Page';
})->name(config()->string('oauth.login_route_name'));
})->name(config('oauth.login_route_name'));

$mockOAuthService = Mockery::mock(OAuthService::class);

Expand Down Expand Up @@ -230,6 +230,6 @@
expect($mockUser->oauth_token_expires_at)->toBeNull();

expect($response->getStatusCode())->toBe(302);
expect($response->headers->get('Location'))->toBe(route(config()->string('oauth.login_route_name')));
expect($response->headers->get('Location'))->toBe(route(config('oauth.login_route_name')));
expect(session('message'))->toBe('Your session has expired. Please log in again.');
});

0 comments on commit f91872c

Please sign in to comment.