2026-04-14 21:31:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-04-15 01:22:04 +00:00
|
|
|
use App\Models\Account;
|
2026-04-14 21:31:13 +00:00
|
|
|
use App\Models\Plan;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
config(['trypost.self_hosted' => false]);
|
|
|
|
|
|
|
|
|
|
$this->plan = Plan::first();
|
|
|
|
|
$this->plan->update([
|
2026-04-15 01:22:04 +00:00
|
|
|
'workspace_limit' => 5,
|
2026-04-14 21:31:13 +00:00
|
|
|
'member_limit' => 5,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$this->account = Account::factory()->create(['plan_id' => $this->plan->id]);
|
|
|
|
|
$this->user = User::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
]);
|
|
|
|
|
$this->account->update(['owner_id' => $this->user->id]);
|
2026-04-14 21:31:13 +00:00
|
|
|
$this->workspace = Workspace::factory()->create([
|
2026-04-15 01:22:04 +00:00
|
|
|
'account_id' => $this->account->id,
|
2026-04-14 21:31:13 +00:00
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
2026-04-15 01:22:04 +00:00
|
|
|
$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);
|
2026-04-14 21:31:13 +00:00
|
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('can invite member within limit', function () {
|
|
|
|
|
expect($this->user->can('inviteMember', $this->workspace))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('cannot invite member beyond limit', function () {
|
2026-04-15 01:22:04 +00:00
|
|
|
$members = User::factory()->count(4)->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
]);
|
2026-04-14 21:31:13 +00:00
|
|
|
|
|
|
|
|
foreach ($members as $member) {
|
|
|
|
|
$this->workspace->members()->attach($member->id, ['role' => Role::Member->value]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 1 owner + 4 members = 5, which is the limit
|
|
|
|
|
expect($this->user->can('inviteMember', $this->workspace))->toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
test('self hosted mode bypasses workspace limit', function () {
|
2026-04-14 21:31:13 +00:00
|
|
|
config(['trypost.self_hosted' => true]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
Workspace::factory()->count(10)->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'user_id' => $this->user->id,
|
|
|
|
|
]);
|
2026-04-14 21:31:13 +00:00
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
expect($this->user->can('create', Workspace::class))->toBeTrue();
|
2026-04-14 21:31:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('self hosted mode bypasses member limit', function () {
|
|
|
|
|
config(['trypost.self_hosted' => true]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$members = User::factory()->count(10)->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
]);
|
2026-04-14 21:31:13 +00:00
|
|
|
|
|
|
|
|
foreach ($members as $member) {
|
|
|
|
|
$this->workspace->members()->attach($member->id, ['role' => Role::Member->value]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
expect($this->user->can('inviteMember', $this->workspace))->toBeTrue();
|
|
|
|
|
});
|