You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Jetstream\Features;
|
|
use Laravel\Jetstream\Http\Livewire\ApiTokenManager;
|
|
use Livewire\Livewire;
|
|
use Tests\TestCase;
|
|
|
|
class CreateApiTokenTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_api_tokens_can_be_created()
|
|
{
|
|
if (! Features::hasApiFeatures()) {
|
|
return $this->markTestSkipped('API support is not enabled.');
|
|
}
|
|
|
|
$this->actingAs($user = User::factory()->withPersonalTeam()->create());
|
|
|
|
Livewire::test(ApiTokenManager::class)
|
|
->set(['createApiTokenForm' => [
|
|
'name' => 'Test Token',
|
|
'permissions' => [
|
|
'read',
|
|
'update',
|
|
],
|
|
]])
|
|
->call('createApiToken');
|
|
|
|
$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'));
|
|
}
|
|
}
|