Files
landing-api/tests/Feature/Panel/TaskStreamPanelTest.php
Josep Piguillem b32d6bf001
Some checks failed
Tests / test (push) Has been cancelled
Tests / test-postgres (push) Has been cancelled
Tests / mcp (push) Has been cancelled
Tests / lint (push) Has been cancelled
Open a TaskStream board from the panel's project form
A "TaskStream" section on the create form (toggle and optional key,
suggested from the slug) opens the board before saving, as the person
signed in, with the Pireon token of their session. A refusal shows on the
key field and a TaskStream outage as a notification; either way nothing is
saved. The created notification carries the link, and the edit page has
an "Open in TaskStream" button.

Documented in the user manual (and its PDF) and the README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 23:01:55 +02:00

135 lines
4.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\Panel;
use App\Filament\Resources\Projects\Pages\CreateProject;
use App\Filament\Resources\Projects\Pages\EditProject;
use App\Models\Project;
use App\Services\Pireon\AccessToken;
use App\Services\Pireon\TokenStore;
use Database\Seeders\RolePermissionSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use Livewire\Livewire;
use PHPUnit\Framework\Attributes\Test;
use Tests\FakesPireon;
use Tests\TestCase;
/**
* The panel's way to open a project's board in TaskStream: a toggle on the
* create form, as the person signed in.
*/
class TaskStreamPanelTest extends TestCase
{
use FakesPireon, RefreshDatabase;
protected string $taskstream = 'https://api.taskstream.test';
protected function setUp(): void
{
parent::setUp();
$this->seed(RolePermissionSeeder::class);
$this->actingAs($this->userWithRoles('editor'));
config([
'services.taskstream.api_url' => $this->taskstream,
'services.taskstream.web_url' => 'https://taskstream.test',
]);
// What signing in to the panel leaves in the session.
app(TokenStore::class)->put(new AccessToken('session-token', null, now()->addHour()->toImmutable()));
}
protected function fakeTaskStream(int $status = 201, array $body = []): void
{
Http::fake([
"{$this->taskstream}/api/projects" => fn (Request $request) => Http::response(
$status === 201 ? ['id' => 'ts-1', 'key' => $request['key'], 'version' => 1] : $body,
$status,
),
]);
}
#[Test]
public function the_toggle_opens_a_board_with_the_session_token(): void
{
$this->fakeTaskStream();
Livewire::test(CreateProject::class)
->fillForm([
'title' => ['es' => 'Catálogo abierto'],
'slug' => ['es' => 'catalogo'],
'taskstream' => true,
])
->assertFormFieldExists('taskstream_key')
->call('create')
->assertHasNoFormErrors()
->assertNotified();
Http::assertSent(fn (Request $request) => $request->url() === "{$this->taskstream}/api/projects"
&& $request->hasHeader('Authorization', 'Bearer session-token')
&& $request['key'] === 'CATALOGO'
&& $request['isPublic'] === true);
$project = Project::query()->sole();
$this->assertSame('CATALOGO', $project->taskstream_key);
Livewire::test(EditProject::class, ['record' => $project->getRouteKey()])
->assertActionVisible('taskstream')
->assertActionHasUrl('taskstream', 'https://taskstream.test/p/CATALOGO')
->assertFormFieldDoesNotExist('taskstream');
}
#[Test]
public function without_the_toggle_taskstream_is_left_alone(): void
{
$this->fakeTaskStream();
Livewire::test(CreateProject::class)
->fillForm(['title' => ['es' => 'Solo aquí'], 'slug' => ['es' => 'solo-aqui']])
->assertFormFieldHidden('taskstream_key')
->call('create')
->assertHasNoFormErrors();
Http::assertNothingSent();
Livewire::test(EditProject::class, ['record' => Project::query()->sole()->getRouteKey()])
->assertActionHidden('taskstream');
}
#[Test]
public function a_refusal_shows_on_the_key_and_saves_nothing(): void
{
$this->fakeTaskStream(409, ['statusCode' => 409, 'message' => 'Project key WEB is already in use']);
Livewire::test(CreateProject::class)
->fillForm([
'title' => ['es' => 'Web'],
'slug' => ['es' => 'web'],
'taskstream' => true,
'taskstream_key' => 'web',
])
->call('create')
->assertHasFormErrors(['taskstream_key']);
$this->assertSame(0, Project::withTrashed()->count());
}
#[Test]
public function taskstream_being_down_saves_nothing(): void
{
Http::fake(["{$this->taskstream}/*" => Http::failedConnection()]);
Livewire::test(CreateProject::class)
->fillForm(['title' => ['es' => 'Web'], 'slug' => ['es' => 'web'], 'taskstream' => true])
->call('create')
->assertNotified(__('rules.taskstream.unavailable'));
$this->assertSame(0, Project::withTrashed()->count());
}
}