34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
|
|
use App\Domains\Link\Models\Link;
|
|
use App\Domains\Workspace\Models\Workspace;
|
|
use App\Models\User;
|
|
|
|
it('lists links for authenticated workspace', function () {
|
|
$user = User::factory()->create();
|
|
$workspace = (new \App\Domains\Workspace\Actions\CreateWorkspace)->handle($user, ['name' => 'Test']);
|
|
Link::factory()->count(3)->create(['workspace_id' => $workspace->id]);
|
|
|
|
$token = $user->createToken('api-test')->plainTextToken;
|
|
|
|
$response = $this->withToken($token)
|
|
->getJson("/api/v1/workspaces/{$workspace->ulid}/links");
|
|
|
|
$response->assertOk()
|
|
->assertJsonCount(3, 'data');
|
|
});
|
|
|
|
it('creates link via API', function () {
|
|
$user = User::factory()->create();
|
|
$workspace = (new \App\Domains\Workspace\Actions\CreateWorkspace)->handle($user, ['name' => 'Test']);
|
|
$token = $user->createToken('api-test')->plainTextToken;
|
|
|
|
$response = $this->withToken($token)
|
|
->postJson("/api/v1/workspaces/{$workspace->ulid}/links", [
|
|
'target_url' => 'https://example.com',
|
|
]);
|
|
|
|
$response->assertCreated()
|
|
->assertJsonPath('data.target_url', 'https://example.com');
|
|
});
|