- Create Account model as Cashier Billable entity (stripe, plan, subscription) - Account owns workspaces and has an owner_id (User) - User belongs to one Account via account_id - Workspace belongs to Account via account_id, no longer has billing fields - Remove Brand model entirely (workspaces serve as grouping) - Rename brand_limit to workspace_limit in plans - Workspace roles simplified: admin/member/viewer (owner via Account) - Invites now belong to Account with workspaces JSON array - Pennant features scope changed from Workspace to Account - EnsureSubscribed middleware checks Account subscription - All controllers updated: BillingController, OnboardingController, WorkspaceInviteController, SocialController, StripeEventListener - Frontend: extract GoogleAuthButton component, create WorkspaceRole enum for type-safe role checks, fix all views for new architecture - All 1101 tests passing
120 lines
3.7 KiB
PHP
120 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Enums\UserWorkspace\Role;
|
|
use App\Mcp\Servers\TryPostServer;
|
|
use App\Mcp\Tools\Label\CreateLabelTool;
|
|
use App\Mcp\Tools\Label\DeleteLabelTool;
|
|
use App\Mcp\Tools\Label\ListLabelsTool;
|
|
use App\Mcp\Tools\Label\UpdateLabelTool;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Models\WorkspaceLabel;
|
|
|
|
beforeEach(function () {
|
|
$this->user = User::factory()->create();
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
|
$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
|
});
|
|
|
|
test('can list labels', function () {
|
|
WorkspaceLabel::factory()->count(2)->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(ListLabelsTool::class, []);
|
|
|
|
$response->assertOk();
|
|
});
|
|
|
|
test('can create label', function () {
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(CreateLabelTool::class, [
|
|
'name' => 'Important',
|
|
'color' => '#FF0000',
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$response->assertSee('Important');
|
|
expect($this->workspace->labels()->count())->toBe(1);
|
|
});
|
|
|
|
test('create label validates required fields', function () {
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(CreateLabelTool::class, []);
|
|
|
|
$response->assertHasErrors();
|
|
});
|
|
|
|
test('create label validates color format', function () {
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(CreateLabelTool::class, [
|
|
'name' => 'Test',
|
|
'color' => 'not-a-color',
|
|
]);
|
|
|
|
$response->assertHasErrors();
|
|
});
|
|
|
|
test('can update label', function () {
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(UpdateLabelTool::class, [
|
|
'label_id' => $label->id,
|
|
'name' => 'Updated',
|
|
'color' => '#00FF00',
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$response->assertSee('Updated');
|
|
});
|
|
|
|
test('cannot update label from another workspace', function () {
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]);
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(UpdateLabelTool::class, [
|
|
'label_id' => $label->id,
|
|
'name' => 'Hacked',
|
|
'color' => '#000000',
|
|
]);
|
|
|
|
$response->assertHasErrors(['Label not found.']);
|
|
});
|
|
|
|
test('can delete label', function () {
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $this->workspace->id]);
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(DeleteLabelTool::class, ['label_id' => $label->id]);
|
|
|
|
$response->assertOk();
|
|
expect(WorkspaceLabel::find($label->id))->toBeNull();
|
|
});
|
|
|
|
test('cannot delete label from another workspace', function () {
|
|
$otherWorkspace = Workspace::factory()->create();
|
|
$label = WorkspaceLabel::factory()->create(['workspace_id' => $otherWorkspace->id]);
|
|
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(DeleteLabelTool::class, ['label_id' => $label->id]);
|
|
|
|
$response->assertHasErrors(['Label not found.']);
|
|
});
|
|
|
|
test('update label validates required fields', function () {
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(UpdateLabelTool::class, []);
|
|
|
|
$response->assertHasErrors();
|
|
});
|
|
|
|
test('delete label validates label_id required', function () {
|
|
$response = TryPostServer::actingAs($this->user)
|
|
->tool(DeleteLabelTool::class, []);
|
|
|
|
$response->assertHasErrors();
|
|
});
|