Added trial and blocking to billing contract, fixed bug in running time tracker command

This commit is contained in:
Constantin Graf
2024-07-29 18:04:45 +02:00
committed by Constantin Graf
parent 7c593f8f87
commit 5b7df869ad
33 changed files with 629 additions and 187 deletions

View File

@@ -1,43 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
use Tests\TestCase;
class ApiTokenPermissionsTest extends TestCase
{
use RefreshDatabase;
public function test_api_token_permissions_can_be_updated(): void
{
if (! Features::hasApiFeatures()) {
$this->markTestSkipped('API support is not enabled.');
}
$this->actingAs($user = User::factory()->withPersonalOrganization()->create());
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
]);
$response = $this->put('/user/api-tokens/'.$token->id, [
'name' => $token->name,
'permissions' => [
'delete',
'missing-permission',
],
]);
$this->assertTrue($user->fresh()->tokens->first()->can('delete'));
$this->assertFalse($user->fresh()->tokens->first()->can('read'));
$this->assertFalse($user->fresh()->tokens->first()->can('missing-permission'));
}
}

View File

@@ -1,37 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Jetstream\Features;
use Tests\TestCase;
class CreateApiTokenTest extends TestCase
{
use RefreshDatabase;
public function test_api_tokens_can_be_created(): void
{
if (! Features::hasApiFeatures()) {
$this->markTestSkipped('API support is not enabled.');
}
$this->actingAs($user = User::factory()->withPersonalOrganization()->create());
$response = $this->post('/user/api-tokens', [
'name' => 'Test Token',
'permissions' => [
'read',
'update',
],
]);
$this->assertCount(1, $user->fresh()->tokens);
$this->assertEquals('Test Token', $user->fresh()->tokens->first()->name);
$this->assertTrue($user->fresh()->tokens->first()->can('read'));
$this->assertFalse($user->fresh()->tokens->first()->can('delete'));
}
}

View File

@@ -5,22 +5,26 @@ declare(strict_types=1);
namespace Tests\Feature;
use App\Enums\Role;
use App\Events\AfterCreateOrganization;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Tests\TestCase;
class CreateTeamTest extends TestCase
class CreateOrganizationTest extends TestCase
{
use RefreshDatabase;
public function test_teams_can_be_created(): void
public function test_organizations_can_be_created(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
$this->actingAs($user);
sleep(1);
Event::fake([
AfterCreateOrganization::class,
]);
// Act
$response = $this->post('/teams', [
@@ -28,6 +32,7 @@ class CreateTeamTest extends TestCase
]);
// Assert
$response->assertStatus(302);
/** @var Organization|null $newOrganization */
$ownedTeams = $user->fresh()->ownedTeams;
$this->assertCount(2, $ownedTeams);
@@ -36,5 +41,8 @@ class CreateTeamTest extends TestCase
/** @var Member $member */
$member = Member::query()->whereBelongsTo($user, 'user')->whereBelongsTo($newOrganization, 'organization')->firstOrFail();
$this->assertSame(Role::Owner->value, $member->role);
Event::assertDispatched(AfterCreateOrganization::class, function (AfterCreateOrganization $event) use ($newOrganization): bool {
return $event->organization->is($newOrganization);
});
}
}

View File

@@ -1,35 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Laravel\Jetstream\Features;
use Tests\TestCase;
class DeleteApiTokenTest extends TestCase
{
use RefreshDatabase;
public function test_api_tokens_can_be_deleted(): void
{
if (! Features::hasApiFeatures()) {
$this->markTestSkipped('API support is not enabled.');
}
$this->actingAs($user = User::factory()->withPersonalOrganization()->create());
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
]);
$response = $this->delete('/user/api-tokens/'.$token->id);
$this->assertCount(0, $user->fresh()->tokens);
}
}

View File

@@ -11,11 +11,11 @@ use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DeleteTeamTest extends TestCase
class DeleteOrganizationTest extends TestCase
{
use RefreshDatabase;
public function test_teams_can_be_deleted_and_users_of_the_organization_that_have_no_organization_get_a_new_one(): void
public function test_organizations_can_be_deleted_and_users_of_the_organization_that_have_no_organization_get_a_new_one(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();
@@ -40,7 +40,7 @@ class DeleteTeamTest extends TestCase
$this->assertFalse($otherUser->fresh()->teams->first()->is($organization));
}
public function test_personal_teams_can_be_deleted_but_user_gets_an_new_one_if_this_is_the_only_one_left(): void
public function test_personal_organizations_can_be_deleted_but_user_gets_an_new_one_if_this_is_the_only_one_left(): void
{
// Arrange
$user = User::factory()->withPersonalOrganization()->create();

View File

@@ -36,7 +36,9 @@ class EmailVerificationTest extends TestCase
$this->markTestSkipped('Email verification not enabled.');
}
Event::fake();
Event::fake([
Verified::class,
]);
$user = User::factory()->unverified()->create();

View File

@@ -33,17 +33,6 @@ class RegistrationTest extends TestCase
$response->assertStatus(200);
}
public function test_registration_screen_cannot_be_rendered_if_support_is_disabled(): void
{
if (Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration support is enabled.');
}
$response = $this->get('/register');
$response->assertStatus(404);
}
public function test_new_users_can_register(): void
{
// Arrange