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

[2.x] Adds support for Pest #866

Merged
merged 17 commits into from
Sep 8, 2021
Merged
Prev Previous commit
Next Next commit
Uses ->skip method
  • Loading branch information
lukeraymonddowning committed Aug 28, 2021
commit 18dcfec61c8f5b0702b3626ee79a2222e82cb0b5
24 changes: 9 additions & 15 deletions stubs/pest-tests/EmailVerificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,18 @@
use Laravel\Fortify\Features;

test('email verification screen can be rendered', function () {
if (! Features::enabled(Features::emailVerification())) {
return $this->markTestSkipped('Email verification not enabled.');
}

$user = User::factory()->withPersonalTeam()->create([
'email_verified_at' => null,
]);

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

$response->assertStatus(200);
});
})->skip(function() {
return ! Features::enabled(Features::emailVerification());
}, 'Email verification not enabled.');;

test('email can be verified', function () {
if (! Features::enabled(Features::emailVerification())) {
return $this->markTestSkipped('Email verification not enabled.');
}

Event::fake();

$user = User::factory()->create([
Expand All @@ -44,13 +38,11 @@

expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
$response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
});
})->skip(function() {
return ! Features::enabled(Features::emailVerification());
}, 'Email verification not enabled.');;

test('email can not verified with invalid hash', function () {
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved
if (! Features::enabled(Features::emailVerification())) {
return $this->markTestSkipped('Email verification not enabled.');
}

$user = User::factory()->create([
'email_verified_at' => null,
]);
Expand All @@ -64,4 +56,6 @@
$this->actingAs($user)->get($verificationUrl);

expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
});
})->skip(function() {
return ! Features::enabled(Features::emailVerification());
}, 'Email verification not enabled.');;
32 changes: 12 additions & 20 deletions stubs/pest-tests/PasswordResetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@
use Laravel\Fortify\Features;

test('reset password link screen can be rendered', function () {
if (! Features::enabled(Features::updatePasswords())) {
return $this->markTestSkipped('Password updates are not enabled.');
}

$response = $this->get('/forgot-password');

$response->assertStatus(200);
});
})->skip(function() {
return ! Features::enabled(Features::updatePasswords());
}, 'Password updates are not enabled.');

test('reset password link can be requested', function () {
if (! Features::enabled(Features::updatePasswords())) {
return $this->markTestSkipped('Password updates are not enabled.');
}

Notification::fake();

$user = User::factory()->create();
Expand All @@ -29,13 +23,11 @@
]);

Notification::assertSentTo($user, ResetPassword::class);
});
})->skip(function() {
return ! Features::enabled(Features::updatePasswords());
}, 'Password updates are not enabled.');

test('reset password screen can be rendered', function () {
if (! Features::enabled(Features::updatePasswords())) {
return $this->markTestSkipped('Password updates are not enabled.');
}

Notification::fake();

$user = User::factory()->create();
Expand All @@ -51,13 +43,11 @@

return true;
});
});
})->skip(function() {
return ! Features::enabled(Features::updatePasswords());
}, 'Password updates are not enabled.');

test('password can be reset with valid token', function () {
if (! Features::enabled(Features::updatePasswords())) {
return $this->markTestSkipped('Password updates are not enabled.');
}

Notification::fake();

$user = User::factory()->create();
Expand All @@ -78,4 +68,6 @@

return true;
});
});
})->skip(function() {
return ! Features::enabled(Features::updatePasswords());
}, 'Password updates are not enabled.');
24 changes: 9 additions & 15 deletions stubs/pest-tests/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@
use Laravel\Jetstream\Jetstream;

test('registration screen can be rendered', function () {
if (! Features::enabled(Features::registration())) {
return $this->markTestSkipped('Registration support is not enabled.');
}

$response = $this->get('/register');

$response->assertStatus(200);
});
})->skip(function() {
return ! Features::enabled(Features::registration());
}, 'Registration support is not enabled.');

test('registration screen cannot be rendered if support is disabled', function () {
if (Features::enabled(Features::registration())) {
return $this->markTestSkipped('Registration support is enabled.');
}

$response = $this->get('/register');

$response->assertStatus(404);
});
})->skip(function() {
return ! Features::enabled(Features::registration());
}, 'Registration support is not enabled.');

test('new users can register', function () {
if (! Features::enabled(Features::registration())) {
return $this->markTestSkipped('Registration support is not enabled.');
}

$response = $this->post('/register', [
'name' => 'Test User',
'email' => '[email protected]',
Expand All @@ -39,4 +31,6 @@

$this->assertAuthenticated();
$response->assertRedirect(RouteServiceProvider::HOME);
});
})->skip(function() {
return ! Features::enabled(Features::registration());
}, 'Registration support is not enabled.');
8 changes: 3 additions & 5 deletions stubs/pest-tests/inertia/ApiTokenPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
use Laravel\Jetstream\Features;

test('api token permissions can be updated', function () {
if (! Features::hasApiFeatures()) {
return $this->markTestSkipped('API support is not enabled.');
}

if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
Expand All @@ -32,4 +28,6 @@
expect($user->fresh()->tokens->first()->can('delete'))->toBeTrue();
expect($user->fresh()->tokens->first()->can('read'))->toBeFalse();
expect($user->fresh()->tokens->first()->can('missing-permission'))->toBeFalse();
});
})->skip(function() {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
8 changes: 3 additions & 5 deletions stubs/pest-tests/inertia/CreateApiTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
use Laravel\Jetstream\Features;

test('api tokens can be created', function () {
if (! Features::hasApiFeatures()) {
return $this->markTestSkipped('API support is not enabled.');
}

if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
Expand All @@ -26,4 +22,6 @@
expect($user->fresh()->tokens->first()->name)->toEqual('Test Token');
expect($user->fresh()->tokens->first()->can('read'))->toBeTrue();
expect($user->fresh()->tokens->first()->can('delete'))->toBeFalse();
});
})->skip(function() {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
16 changes: 6 additions & 10 deletions stubs/pest-tests/inertia/DeleteAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@
use Laravel\Jetstream\Features;

test('user accounts can be deleted', function () {
if (! Features::hasAccountDeletionFeatures()) {
return $this->markTestSkipped('Account deletion is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$response = $this->delete('/user', [
'password' => 'password',
]);

expect($user->fresh())->toBeNull();
});
})->skip(function() {
return ! Features::hasAccountDeletionFeatures();
}, 'Account deletion is not enabled.');

test('correct password must be provided before account can be deleted', function () {
if (! Features::hasAccountDeletionFeatures()) {
return $this->markTestSkipped('Account deletion is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$response = $this->delete('/user', [
'password' => 'wrong-password',
]);

expect($user->fresh())->not->toBeNull();
});
})->skip(function() {
return ! Features::hasAccountDeletionFeatures();
}, 'Account deletion is not enabled.');
8 changes: 3 additions & 5 deletions stubs/pest-tests/inertia/DeleteApiTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
use Laravel\Jetstream\Features;

test('api tokens can be deleted', function () {
if (! Features::hasApiFeatures()) {
return $this->markTestSkipped('API support is not enabled.');
}

if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
Expand All @@ -24,4 +20,6 @@
$response = $this->delete('/user/api-tokens/'.$token->id);

expect($user->fresh()->tokens)->toHaveCount(0);
});
})->skip(function() {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
8 changes: 3 additions & 5 deletions stubs/pest-tests/livewire/ApiTokenPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
use Livewire\Livewire;

test('api token permissions can be updated', function () {
if (! Features::hasApiFeatures()) {
return $this->markTestSkipped('API support is not enabled.');
}

if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
Expand All @@ -36,4 +32,6 @@
expect($user->fresh()->tokens->first()->can('delete'))->toBeTrue();
expect($user->fresh()->tokens->first()->can('read'))->toBeFalse();
expect($user->fresh()->tokens->first()->can('missing-permission'))->toBeFalse();
});
})->skip(function() {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
8 changes: 3 additions & 5 deletions stubs/pest-tests/livewire/CreateApiTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
use Livewire\Livewire;

test('api tokens can be created', function () {
if (! Features::hasApiFeatures()) {
return $this->markTestSkipped('API support is not enabled.');
}

if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
Expand All @@ -30,4 +26,6 @@
expect($user->fresh()->tokens->first()->name)->toEqual('Test Token');
expect($user->fresh()->tokens->first()->can('read'))->toBeTrue();
expect($user->fresh()->tokens->first()->can('delete'))->toBeFalse();
});
})->skip(function() {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');
16 changes: 6 additions & 10 deletions stubs/pest-tests/livewire/DeleteAccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,18 @@
use Livewire\Livewire;

test('user accounts can be deleted', function () {
if (! Features::hasAccountDeletionFeatures()) {
return $this->markTestSkipped('Account deletion is not enabled.');
}

$this->actingAs($user = User::factory()->create());

$component = Livewire::test(DeleteUserForm::class)
->set('password', 'password')
->call('deleteUser');

expect($user->fresh())->toBeNull();
});
})->skip(function() {
return ! Features::hasAccountDeletionFeatures();
}, 'Account deletion is not enabled.');

test('correct_password_must_be_provided_before_account_can_be_deleted', function () {
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved
if (! Features::hasAccountDeletionFeatures()) {
return $this->markTestSkipped('Account deletion is not enabled.');
}

$this->actingAs($user = User::factory()->create());

Livewire::test(DeleteUserForm::class)
Expand All @@ -32,4 +26,6 @@
->assertHasErrors(['password']);

expect($user->fresh())->not->toBeNull();
});
})->skip(function() {
return ! Features::hasAccountDeletionFeatures();
}, 'Account deletion is not enabled.');
8 changes: 3 additions & 5 deletions stubs/pest-tests/livewire/DeleteApiTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

test('api tokens can be deleted', function ()
{
if (! Features::hasApiFeatures()) {
return $this->markTestSkipped('API support is not enabled.');
}

if (Features::hasTeamFeatures()) {
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
} else {
Expand All @@ -29,4 +25,6 @@
->call('deleteApiToken');

expect($user->fresh()->tokens)->toHaveCount(0);
});
})->skip(function() {
return ! Features::hasApiFeatures();
}, 'API support is not enabled.');