Skip to content

Commit

Permalink
Merge pull request #58 from irsyadadl/bump
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
irsyadadl authored Apr 26, 2024
2 parents 91f9227 + ce00069 commit 641bc73
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 51 deletions.
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost
APP_URL=http://inertia.ts.test

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
Expand Down
Binary file removed app/.DS_Store
Binary file not shown.
Binary file removed app/Models/.DS_Store
Binary file not shown.
Binary file removed config/.DS_Store
Binary file not shown.
Binary file removed database/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class UserFactory extends Factory
public function definition(): array
{
return [
'username' => fake()->userName(),
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function up(): void
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('username')->unique()->nullable();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
Expand Down
21 changes: 0 additions & 21 deletions tests/CreatesApplication.php

This file was deleted.

12 changes: 10 additions & 2 deletions tests/Feature/Auth/AuthenticationTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use App\Models\User;
use App\Providers\RouteServiceProvider;

test('login screen can be rendered', function () {
$response = $this->get('/login');
Expand All @@ -18,7 +17,7 @@
]);

$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
$response->assertRedirect(route('dashboard', absolute: false));
});

test('users can not authenticate with invalid password', function () {
Expand All @@ -31,3 +30,12 @@

$this->assertGuest();
});

test('users can logout', function () {
$user = User::factory()->create();

$response = $this->actingAs($user)->post('/logout');

$this->assertGuest();
$response->assertRedirect('/');
});
15 changes: 4 additions & 11 deletions tests/Feature/Auth/EmailVerificationTest.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
<?php

use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;

test('email verification screen can be rendered', function () {
$user = User::factory()->create([
'email_verified_at' => null,
]);
$user = User::factory()->unverified()->create();

$response = $this->actingAs($user)->get('/verify-email');

$response->assertStatus(200);
});

test('email can be verified', function () {
$user = User::factory()->create([
'email_verified_at' => null,
]);
$user = User::factory()->unverified()->create();

Event::fake();

Expand All @@ -33,13 +28,11 @@

Event::assertDispatched(Verified::class);
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
$response->assertRedirect(RouteServiceProvider::HOME . '?verified=1');
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
});

test('email is not verified with invalid hash', function () {
$user = User::factory()->create([
'email_verified_at' => null,
]);
$user = User::factory()->unverified()->create();

$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
Expand Down
6 changes: 4 additions & 2 deletions tests/Feature/Auth/PasswordResetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$this->post('/forgot-password', ['email' => $user->email]);

Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
$response = $this->get('/reset-password/' . $notification->token);
$response = $this->get('/reset-password/'.$notification->token);

$response->assertStatus(200);

Expand All @@ -51,7 +51,9 @@
'password_confirmation' => 'password',
]);

$response->assertSessionHasNoErrors();
$response
->assertSessionHasNoErrors()
->assertRedirect(route('login'));

return true;
});
Expand Down
5 changes: 1 addition & 4 deletions tests/Feature/Auth/RegistrationTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use App\Providers\RouteServiceProvider;

test('registration screen can be rendered', function () {
$response = $this->get('/register');

Expand All @@ -11,12 +9,11 @@
test('new users can register', function () {
$response = $this->post('/register', [
'name' => 'Test User',
'terms' => true,
'email' => '[email protected]',
'password' => 'password',
'password_confirmation' => 'password',
]);

$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
$response->assertRedirect(route('dashboard', absolute: false));
});
18 changes: 9 additions & 9 deletions tests/Feature/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

$response = $this
->actingAs($user)
->get(route('profile.edit'));
->get('/profile/edit');

$response->assertOk();
});
Expand All @@ -18,7 +18,7 @@
$response = $this
->actingAs($user)
->patch('/profile', [
'username' => 'testuser',
'username' => 'test_username',
'name' => 'Test User',
'email' => '[email protected]',
]);
Expand All @@ -39,15 +39,15 @@

$response = $this
->actingAs($user)
->patch(route('profile.update'), [
'username' => 'testuser',
->patch('/profile', [
'username' => 'test_username',
'name' => 'Test User',
'email' => $user->email,
]);

$response
->assertSessionHasNoErrors()
->assertRedirect(route('profile.edit'));
->assertRedirect('/profile/edit');

$this->assertNotNull($user->refresh()->email_verified_at);
});
Expand All @@ -57,7 +57,7 @@

$response = $this
->actingAs($user)
->delete(route('profile.destroy'), [
->delete('/profile', [
'password' => 'password',
]);

Expand All @@ -74,14 +74,14 @@

$response = $this
->actingAs($user)
->from(route('profile.edit'))
->delete(route('profile.destroy'), [
->from('/profile')
->delete('/profile', [
'password' => 'wrong-password',
]);

$response
->assertSessionHasErrors('password')
->assertRedirect(route('profile.edit'));
->assertRedirect('/profile');

$this->assertNotNull($user->fresh());
});
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
//
}

0 comments on commit 641bc73

Please sign in to comment.