2026-01-20 19:53:54 +00:00
|
|
|
<?php
|
|
|
|
|
|
refactor: settings redesign, Spanish translations, language system, strict_types
Settings pages:
- Redesign layout to match Sendkit (max-w-4xl, space-y-12, Separator sections)
- Merge Members page into Workspace settings with Table, invite Dialog, ConfirmDeleteModal
- Add workspace logo upload/delete routes and controller methods
- Translate all hardcoded strings in Workspace.vue modals
Language system:
- Drop languages table, replace language_id FK with locale string column on users
- Create config/languages.php for available languages and default locale
- Add Spanish (es) translations (13 files)
- Simplify HandleInertiaRequests, ProfileController, RegisteredUserController
Code quality:
- Add declare(strict_types=1) to all PHP files
- Fix MastodonPublisher using wrong attribute (filename -> original_filename)
- Fix HasMediaTest for new has_photo/photo_url accessors
- Fix PublishToSocialPlatformTest type error revealed by strict_types
- Remove orphaned Language model from AppServiceProvider morph map
- Update User TypeScript interface (has_photo, photo_url, locale)
- Eager load media relation on workspaces to prevent N+1
- Add 8 new tests for workspace logo upload/delete
- Update workspace settings test to assert members/invitations props
All 710 tests passing.
2026-03-30 03:20:43 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-06-22 17:24:19 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-04-15 01:22:04 +00:00
|
|
|
use App\Models\Account;
|
|
|
|
|
use App\Models\Invite;
|
2026-01-20 19:53:54 +00:00
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2026-04-15 01:22:04 +00:00
|
|
|
$this->account = Account::factory()->create();
|
|
|
|
|
$this->owner = User::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
]);
|
|
|
|
|
$this->account->update(['owner_id' => $this->owner->id]);
|
|
|
|
|
$this->workspace = Workspace::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'user_id' => $this->owner->id,
|
|
|
|
|
]);
|
2026-01-20 19:53:54 +00:00
|
|
|
});
|
|
|
|
|
|
2026-05-19 14:45:16 +00:00
|
|
|
test('show invite displays invite details for guest when not self_hosted', function () {
|
|
|
|
|
config()->set('trypost.self_hosted', false);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
'email' => 'newuser@example.com',
|
2026-04-15 01:22:04 +00:00
|
|
|
'workspaces' => [$this->workspace->id],
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->get(route('app.invites.show', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('auth/AcceptInvite', false)
|
|
|
|
|
->has('invite')
|
|
|
|
|
->where('invite.id', $invite->id)
|
|
|
|
|
->where('invite.email', 'newuser@example.com')
|
2026-04-15 01:22:04 +00:00
|
|
|
->where('invite.account.name', $this->account->name)
|
2026-01-20 19:53:54 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-19 14:45:16 +00:00
|
|
|
test('show invite displays invite details for guest when self_hosted (page renders, gate happens on /register)', function () {
|
|
|
|
|
config()->set('trypost.self_hosted', true);
|
|
|
|
|
|
|
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
|
|
|
|
'email' => 'newuser@example.com',
|
|
|
|
|
'workspaces' => [$this->workspace->id],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->get(route('app.invites.show', $invite));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('auth/AcceptInvite', false)
|
|
|
|
|
->has('invite')
|
|
|
|
|
->where('invite.id', $invite->id)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-20 19:53:54 +00:00
|
|
|
test('show invite displays invite details for authenticated user', function () {
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'invitee@example.com',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
'email' => 'invitee@example.com',
|
2026-04-15 01:22:04 +00:00
|
|
|
'workspaces' => [$this->workspace->id],
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($user)->get(route('app.invites.show', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn ($page) => $page
|
|
|
|
|
->component('auth/AcceptInvite', false)
|
|
|
|
|
->has('invite')
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('show invite returns 404 for non-existent invite', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->get(route('app.invites.show', 'non-existent-uuid'));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
|
|
|
|
$response->assertNotFound();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('accept invite requires authentication', function () {
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->post(route('app.invites.accept', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
test('accept invite adds user to account and workspaces', function () {
|
2026-01-20 19:53:54 +00:00
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'invitee@example.com',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
'email' => 'invitee@example.com',
|
2026-04-15 01:22:04 +00:00
|
|
|
'workspaces' => [$this->workspace->id],
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($user)->post(route('app.invites.accept', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response->assertRedirect(route('app.calendar'));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
// User should be added to the account
|
|
|
|
|
$user->refresh();
|
|
|
|
|
expect($user->account_id)->toBe($this->account->id);
|
2026-01-20 19:53:54 +00:00
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
// User should be member of workspace
|
|
|
|
|
expect($this->workspace->members()->where('user_id', $user->id)->exists())->toBeTrue();
|
2026-01-20 19:53:54 +00:00
|
|
|
|
|
|
|
|
// User's current workspace should be updated
|
|
|
|
|
expect($user->current_workspace_id)->toBe($this->workspace->id);
|
2026-04-15 01:22:04 +00:00
|
|
|
|
|
|
|
|
// Invite should be marked as accepted
|
|
|
|
|
$invite->refresh();
|
|
|
|
|
expect($invite->accepted_at)->not->toBeNull();
|
2026-01-20 19:53:54 +00:00
|
|
|
});
|
|
|
|
|
|
2026-06-22 17:24:19 +00:00
|
|
|
test('accept invite assigns the exact role from the invite', function (Role $role) {
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'invitee@example.com',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
|
|
|
|
'email' => 'invitee@example.com',
|
|
|
|
|
'workspaces' => [$this->workspace->id],
|
|
|
|
|
'role' => $role,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($user)
|
|
|
|
|
->post(route('app.invites.accept', $invite))
|
|
|
|
|
->assertRedirect(route('app.calendar'));
|
|
|
|
|
|
|
|
|
|
$member = $this->workspace->members()->where('user_id', $user->id)->first();
|
|
|
|
|
|
|
|
|
|
expect($member)->not->toBeNull();
|
|
|
|
|
expect($member->pivot->role)->toBe($role->value);
|
|
|
|
|
})->with([
|
|
|
|
|
'viewer' => Role::Viewer,
|
|
|
|
|
'admin' => Role::Admin,
|
|
|
|
|
'member' => Role::Member,
|
|
|
|
|
]);
|
|
|
|
|
|
2026-01-20 19:53:54 +00:00
|
|
|
test('accept invite fails for wrong email', function () {
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'different@example.com',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
'email' => 'invitee@example.com',
|
2026-04-15 01:22:04 +00:00
|
|
|
'workspaces' => [$this->workspace->id],
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($user)->post(route('app.invites.accept', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response->assertRedirect(route('app.calendar'));
|
2026-01-20 19:53:54 +00:00
|
|
|
$response->assertSessionHas('flash.bannerStyle', 'danger');
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
// Invite should NOT be accepted
|
|
|
|
|
$invite->refresh();
|
|
|
|
|
expect($invite->accepted_at)->toBeNull();
|
2026-01-20 19:53:54 +00:00
|
|
|
});
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
test('accept invite handles already member of account', function () {
|
2026-01-20 19:53:54 +00:00
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'invitee@example.com',
|
2026-04-15 01:22:04 +00:00
|
|
|
'account_id' => $this->account->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
'email' => 'invitee@example.com',
|
2026-04-15 01:22:04 +00:00
|
|
|
'workspaces' => [$this->workspace->id],
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($user)->post(route('app.invites.accept', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response->assertRedirect(route('app.calendar'));
|
2026-01-20 19:53:54 +00:00
|
|
|
$response->assertSessionHas('flash.bannerStyle', 'info');
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
// Invite should be marked as accepted
|
|
|
|
|
$invite->refresh();
|
|
|
|
|
expect($invite->accepted_at)->not->toBeNull();
|
2026-01-20 19:53:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('decline invite requires authentication', function () {
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->post(route('app.invites.decline', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
|
|
|
|
$response->assertRedirect(route('login'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('decline invite deletes the invite', function () {
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'invitee@example.com',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
'email' => 'invitee@example.com',
|
2026-04-15 01:22:04 +00:00
|
|
|
'workspaces' => [$this->workspace->id],
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($user)->post(route('app.invites.decline', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response->assertRedirect(route('app.calendar'));
|
2026-01-20 19:53:54 +00:00
|
|
|
$response->assertSessionHas('flash.bannerStyle', 'info');
|
|
|
|
|
|
|
|
|
|
// Invite should be deleted
|
2026-04-15 01:22:04 +00:00
|
|
|
expect(Invite::find($invite->id))->toBeNull();
|
2026-01-20 19:53:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('decline invite fails for wrong email', function () {
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
|
'email' => 'different@example.com',
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-15 01:22:04 +00:00
|
|
|
$invite = Invite::factory()->create([
|
|
|
|
|
'account_id' => $this->account->id,
|
|
|
|
|
'invited_by' => $this->owner->id,
|
2026-01-20 19:53:54 +00:00
|
|
|
'email' => 'invitee@example.com',
|
2026-04-15 01:22:04 +00:00
|
|
|
'workspaces' => [$this->workspace->id],
|
2026-01-20 19:53:54 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($user)->post(route('app.invites.decline', $invite));
|
2026-01-20 19:53:54 +00:00
|
|
|
|
2026-03-29 22:24:28 +00:00
|
|
|
$response->assertRedirect(route('app.calendar'));
|
2026-01-20 19:53:54 +00:00
|
|
|
$response->assertSessionHas('flash.bannerStyle', 'danger');
|
|
|
|
|
|
|
|
|
|
// Invite should NOT be deleted
|
2026-04-15 01:22:04 +00:00
|
|
|
expect(Invite::find($invite->id))->not->toBeNull();
|
2026-01-20 19:53:54 +00:00
|
|
|
});
|