2026-01-18 18:56:51 +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-01-18 18:56:51 +00:00
|
|
|
use App\Enums\SocialAccount\Platform;
|
|
|
|
|
use App\Enums\SocialAccount\Status;
|
2026-03-31 03:40:18 +00:00
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-01-18 18:56:51 +00:00
|
|
|
use App\Models\SocialAccount;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
2026-06-25 00:05:09 +00:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
2026-01-18 18:56:51 +00:00
|
|
|
use Laravel\Socialite\Facades\Socialite;
|
|
|
|
|
use Laravel\Socialite\Two\User as SocialiteUser;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
$this->user = User::factory()->create();
|
|
|
|
|
$this->workspace = Workspace::factory()->create(['user_id' => $this->user->id]);
|
|
|
|
|
$this->user->update(['current_workspace_id' => $this->workspace->id]);
|
2026-04-15 01:22:04 +00:00
|
|
|
$this->workspace->members()->attach($this->user->id, ['role' => Role::Member->value]);
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
/**
|
|
|
|
|
* Build a Socialite user for the LinkedIn person behind the OAuth grant.
|
|
|
|
|
*/
|
|
|
|
|
function linkedInSocialiteUser(string $id = 'person-123'): SocialiteUser
|
|
|
|
|
{
|
|
|
|
|
$socialiteUser = Mockery::mock(SocialiteUser::class);
|
|
|
|
|
$socialiteUser->shouldReceive('getId')->andReturn($id);
|
|
|
|
|
$socialiteUser->shouldReceive('getName')->andReturn('John Doe');
|
|
|
|
|
$socialiteUser->shouldReceive('getAvatar')->andReturn(null);
|
|
|
|
|
$socialiteUser->token = 'test-access-token';
|
|
|
|
|
$socialiteUser->refreshToken = 'test-refresh-token';
|
|
|
|
|
$socialiteUser->expiresIn = 5184000; // 60 days
|
|
|
|
|
$socialiteUser->approvedScopes = ['openid', 'profile', 'email', 'w_member_social'];
|
|
|
|
|
|
|
|
|
|
return $socialiteUser;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test('linkedin connect redirects to oauth provider via the openid driver', function () {
|
2026-04-14 17:44:15 +00:00
|
|
|
$driverMock = Mockery::mock();
|
|
|
|
|
$driverMock->shouldReceive('scopes')->andReturnSelf();
|
|
|
|
|
$driverMock->shouldReceive('redirect')->andReturn(Mockery::mock([
|
|
|
|
|
'getTargetUrl' => 'https://www.linkedin.com/oauth/v2/authorization?test=1',
|
|
|
|
|
]));
|
|
|
|
|
|
2026-01-18 18:56:51 +00:00
|
|
|
Socialite::shouldReceive('driver')
|
2026-06-25 00:05:09 +00:00
|
|
|
->with('linkedin-openid')
|
2026-04-14 17:44:15 +00:00
|
|
|
->andReturn($driverMock);
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)
|
|
|
|
|
->withHeader('X-Inertia', 'true')
|
2026-03-29 22:24:28 +00:00
|
|
|
->get(route('app.social.linkedin.connect'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertStatus(409); // Inertia::location returns 409 with X-Inertia header
|
|
|
|
|
|
|
|
|
|
expect(session('social_connect_workspace'))->toBe($this->workspace->id);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-10 17:56:44 +00:00
|
|
|
/**
|
2026-06-25 00:05:09 +00:00
|
|
|
* Mock the openid driver, hit connect, and return the scopes the controller asked for.
|
2026-06-10 17:56:44 +00:00
|
|
|
*
|
|
|
|
|
* @return array<int, string>
|
|
|
|
|
*/
|
2026-06-25 00:05:09 +00:00
|
|
|
function captureLinkedInConnectScopes(object $test): array
|
|
|
|
|
{
|
2026-05-28 03:54:26 +00:00
|
|
|
$captured = [];
|
|
|
|
|
|
|
|
|
|
$driverMock = Mockery::mock();
|
|
|
|
|
$driverMock->shouldReceive('scopes')
|
|
|
|
|
->withArgs(function (array $scopes) use (&$captured) {
|
|
|
|
|
$captured = $scopes;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
})
|
|
|
|
|
->andReturnSelf();
|
|
|
|
|
$driverMock->shouldReceive('redirect')->andReturn(Mockery::mock([
|
|
|
|
|
'getTargetUrl' => 'https://www.linkedin.com/oauth/v2/authorization?test=1',
|
|
|
|
|
]));
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
Socialite::shouldReceive('driver')->with('linkedin-openid')->andReturn($driverMock);
|
2026-05-28 03:54:26 +00:00
|
|
|
|
2026-06-10 17:56:44 +00:00
|
|
|
$test->actingAs($test->user)
|
2026-05-28 03:54:26 +00:00
|
|
|
->withHeader('X-Inertia', 'true')
|
|
|
|
|
->get(route('app.social.linkedin.connect'));
|
|
|
|
|
|
2026-06-10 17:56:44 +00:00
|
|
|
return $captured;
|
2026-06-25 00:05:09 +00:00
|
|
|
}
|
2026-06-10 17:56:44 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('linkedin connect requests the union of personal and organization scopes', function () {
|
2026-06-10 18:02:00 +00:00
|
|
|
config(['trypost.platforms.linkedin.scopes' => ['openid', 'profile', 'email', 'w_member_social']]);
|
2026-06-25 00:05:09 +00:00
|
|
|
config(['trypost.platforms.linkedin-page.scopes' => ['openid', 'profile', 'email', 'w_organization_social', 'r_organization_social', 'rw_organization_admin', 'w_member_social']]);
|
2026-06-10 17:56:44 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
expect(captureLinkedInConnectScopes($this))->toEqualCanonicalizing([
|
2026-05-28 03:54:26 +00:00
|
|
|
'openid', 'profile', 'email', 'w_member_social',
|
2026-06-25 00:05:09 +00:00
|
|
|
'w_organization_social', 'r_organization_social', 'rw_organization_admin',
|
2026-05-28 03:54:26 +00:00
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('connect requests only personal scopes when company pages are disabled', function () {
|
|
|
|
|
config(['trypost.platforms.linkedin.enabled' => true]);
|
|
|
|
|
config(['trypost.platforms.linkedin-page.enabled' => false]);
|
|
|
|
|
config(['trypost.platforms.linkedin.scopes' => ['openid', 'profile', 'email', 'w_member_social']]);
|
2026-05-28 03:54:26 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
expect(captureLinkedInConnectScopes($this))->toEqualCanonicalizing([
|
|
|
|
|
'openid', 'profile', 'email', 'w_member_social',
|
2026-05-28 03:54:26 +00:00
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('connect requests only organization scopes when the personal profile is disabled', function () {
|
|
|
|
|
config(['trypost.platforms.linkedin.enabled' => false]);
|
|
|
|
|
config(['trypost.platforms.linkedin-page.enabled' => true]);
|
|
|
|
|
config(['trypost.platforms.linkedin-page.scopes' => ['openid', 'w_organization_social', 'r_organization_social', 'rw_organization_admin']]);
|
|
|
|
|
|
|
|
|
|
expect(captureLinkedInConnectScopes($this))->toEqualCanonicalizing([
|
|
|
|
|
'openid', 'w_organization_social', 'r_organization_social', 'rw_organization_admin',
|
2026-01-18 18:56:51 +00:00
|
|
|
]);
|
2026-06-25 00:05:09 +00:00
|
|
|
});
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('connect is forbidden when both linkedin capabilities are disabled', function () {
|
|
|
|
|
config(['trypost.platforms.linkedin.enabled' => false]);
|
|
|
|
|
config(['trypost.platforms.linkedin-page.enabled' => false]);
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.social.linkedin.connect'))
|
|
|
|
|
->assertForbidden();
|
|
|
|
|
});
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 17:30:15 +00:00
|
|
|
test('connect redirects to workspace creation when there is no current workspace', function () {
|
|
|
|
|
// The EnsureHasWorkspace middleware guards the connect routes.
|
2026-06-25 00:05:09 +00:00
|
|
|
$this->user->update(['current_workspace_id' => null]);
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 17:30:15 +00:00
|
|
|
$this->actingAs($this->user)
|
|
|
|
|
->get(route('app.social.linkedin.connect'))
|
|
|
|
|
->assertRedirect(route('app.workspaces.create'));
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('linkedin callback stores the person and organizations then redirects to the selector', function () {
|
2026-06-22 15:53:13 +00:00
|
|
|
session(['social_connect_workspace' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
Socialite::shouldReceive('driver')
|
2026-06-25 00:05:09 +00:00
|
|
|
->with('linkedin-openid')
|
|
|
|
|
->andReturn(Mockery::mock(['user' => linkedInSocialiteUser()]));
|
2026-06-22 15:53:13 +00:00
|
|
|
|
|
|
|
|
Http::fake([
|
2026-06-25 00:05:09 +00:00
|
|
|
config('trypost.platforms.linkedin.api').'/v2/me*' => Http::response(['id' => 'person-123', 'vanityName' => 'johndoe'], 200),
|
|
|
|
|
config('trypost.platforms.linkedin.api').'/v2/organizationAcls*' => Http::response([
|
|
|
|
|
'elements' => [
|
|
|
|
|
['organization~' => ['id' => 123456, 'localizedName' => 'Test Company', 'vanityName' => 'testcompany']],
|
|
|
|
|
],
|
2026-06-22 15:53:13 +00:00
|
|
|
], 200),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
$response->assertRedirect(route('app.social.linkedin.select-identity'));
|
2026-06-22 15:53:13 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
expect(session('linkedin_pending.person.id'))->toBe('person-123');
|
|
|
|
|
expect(session('linkedin_pending.person.vanity_name'))->toBe('johndoe');
|
|
|
|
|
expect(session('linkedin_pending.organizations'))->toHaveCount(1);
|
2026-06-22 15:53:13 +00:00
|
|
|
});
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('linkedin callback still redirects to the selector when the member administers no organizations', function () {
|
fix(linkedin,pinterest): split CSV/space-joined OAuth scopes before saving
LinkedIn and Pinterest's OAuth providers return the granted scope list
joined by comma (LinkedIn) or space-in-one-element (Pinterest), but
Socialite's scope splitter doesn't match either, so 'approvedScopes'
lands as a single-element array containing the whole list:
LinkedIn: ['email,openid,profile,r_basicprofile,w_member_social']
Pinterest: ['boards:read boards:write pins:read pins:write user_accounts:read']
That breaks the publish-time scope check in PublishToSocialPlatform
(array_diff does exact string compare), surfacing as
'Missing permissions: w_member_social. Please reconnect your account'
even though the scopes were actually granted at the provider.
Fix is inline at each callback — re-split before saving. Each provider
has its own quirk (LinkedIn = comma, Pinterest = space), so each
controller handles its own separator.
Tests added: callback splits the joined approvedScopes into individual
tokens for both providers.
2026-05-14 13:55:53 +00:00
|
|
|
session(['social_connect_workspace' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
Socialite::shouldReceive('driver')
|
2026-06-25 00:05:09 +00:00
|
|
|
->with('linkedin-openid')
|
|
|
|
|
->andReturn(Mockery::mock(['user' => linkedInSocialiteUser()]));
|
fix(linkedin,pinterest): split CSV/space-joined OAuth scopes before saving
LinkedIn and Pinterest's OAuth providers return the granted scope list
joined by comma (LinkedIn) or space-in-one-element (Pinterest), but
Socialite's scope splitter doesn't match either, so 'approvedScopes'
lands as a single-element array containing the whole list:
LinkedIn: ['email,openid,profile,r_basicprofile,w_member_social']
Pinterest: ['boards:read boards:write pins:read pins:write user_accounts:read']
That breaks the publish-time scope check in PublishToSocialPlatform
(array_diff does exact string compare), surfacing as
'Missing permissions: w_member_social. Please reconnect your account'
even though the scopes were actually granted at the provider.
Fix is inline at each callback — re-split before saving. Each provider
has its own quirk (LinkedIn = comma, Pinterest = space), so each
controller handles its own separator.
Tests added: callback splits the joined approvedScopes into individual
tokens for both providers.
2026-05-14 13:55:53 +00:00
|
|
|
|
|
|
|
|
Http::fake([
|
2026-06-25 00:05:09 +00:00
|
|
|
config('trypost.platforms.linkedin.api').'/v2/me*' => Http::response(['vanityName' => 'johndoe'], 200),
|
|
|
|
|
config('trypost.platforms.linkedin.api').'/v2/organizationAcls*' => Http::response(['elements' => []], 200),
|
fix(linkedin,pinterest): split CSV/space-joined OAuth scopes before saving
LinkedIn and Pinterest's OAuth providers return the granted scope list
joined by comma (LinkedIn) or space-in-one-element (Pinterest), but
Socialite's scope splitter doesn't match either, so 'approvedScopes'
lands as a single-element array containing the whole list:
LinkedIn: ['email,openid,profile,r_basicprofile,w_member_social']
Pinterest: ['boards:read boards:write pins:read pins:write user_accounts:read']
That breaks the publish-time scope check in PublishToSocialPlatform
(array_diff does exact string compare), surfacing as
'Missing permissions: w_member_social. Please reconnect your account'
even though the scopes were actually granted at the provider.
Fix is inline at each callback — re-split before saving. Each provider
has its own quirk (LinkedIn = comma, Pinterest = space), so each
controller handles its own separator.
Tests added: callback splits the joined approvedScopes into individual
tokens for both providers.
2026-05-14 13:55:53 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
fix(linkedin,pinterest): split CSV/space-joined OAuth scopes before saving
LinkedIn and Pinterest's OAuth providers return the granted scope list
joined by comma (LinkedIn) or space-in-one-element (Pinterest), but
Socialite's scope splitter doesn't match either, so 'approvedScopes'
lands as a single-element array containing the whole list:
LinkedIn: ['email,openid,profile,r_basicprofile,w_member_social']
Pinterest: ['boards:read boards:write pins:read pins:write user_accounts:read']
That breaks the publish-time scope check in PublishToSocialPlatform
(array_diff does exact string compare), surfacing as
'Missing permissions: w_member_social. Please reconnect your account'
even though the scopes were actually granted at the provider.
Fix is inline at each callback — re-split before saving. Each provider
has its own quirk (LinkedIn = comma, Pinterest = space), so each
controller handles its own separator.
Tests added: callback splits the joined approvedScopes into individual
tokens for both providers.
2026-05-14 13:55:53 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
$response->assertRedirect(route('app.social.linkedin.select-identity'));
|
|
|
|
|
expect(session('linkedin_pending.organizations'))->toBe([]);
|
fix(linkedin,pinterest): split CSV/space-joined OAuth scopes before saving
LinkedIn and Pinterest's OAuth providers return the granted scope list
joined by comma (LinkedIn) or space-in-one-element (Pinterest), but
Socialite's scope splitter doesn't match either, so 'approvedScopes'
lands as a single-element array containing the whole list:
LinkedIn: ['email,openid,profile,r_basicprofile,w_member_social']
Pinterest: ['boards:read boards:write pins:read pins:write user_accounts:read']
That breaks the publish-time scope check in PublishToSocialPlatform
(array_diff does exact string compare), surfacing as
'Missing permissions: w_member_social. Please reconnect your account'
even though the scopes were actually granted at the provider.
Fix is inline at each callback — re-split before saving. Each provider
has its own quirk (LinkedIn = comma, Pinterest = space), so each
controller handles its own separator.
Tests added: callback splits the joined approvedScopes into individual
tokens for both providers.
2026-05-14 13:55:53 +00:00
|
|
|
});
|
|
|
|
|
|
2026-01-18 18:56:51 +00:00
|
|
|
test('linkedin callback fails with expired session', function () {
|
2026-03-29 22:24:28 +00:00
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('message', 'Session expired. Please try again.'));
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('linkedin callback handles oauth errors gracefully', function () {
|
|
|
|
|
session(['social_connect_workspace' => $this->workspace->id]);
|
|
|
|
|
|
|
|
|
|
$mock = Mockery::mock();
|
|
|
|
|
$mock->shouldReceive('user')->andThrow(new Exception('OAuth error'));
|
2026-06-22 12:26:31 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
Socialite::shouldReceive('driver')->with('linkedin-openid')->andReturn($mock);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.callback'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('message', 'Error connecting account. Please try again.'));
|
2026-06-25 00:05:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('select-identity screen renders the person and organizations', function () {
|
|
|
|
|
session(['linkedin_pending' => [
|
2026-01-18 18:56:51 +00:00
|
|
|
'workspace_id' => $this->workspace->id,
|
2026-06-25 00:05:09 +00:00
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'profile', 'email', 'w_member_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [
|
|
|
|
|
['id' => 123456, 'name' => 'Test Company', 'vanity_name' => 'testcompany', 'logo' => null],
|
|
|
|
|
],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.select-identity'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page
|
|
|
|
|
->component('accounts/LinkedInSelect')
|
|
|
|
|
->where('person.name', 'John Doe')
|
|
|
|
|
->has('organizations', 1)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('select-identity hides the personal profile when that capability is disabled', function () {
|
|
|
|
|
config(['trypost.platforms.linkedin.enabled' => false]);
|
|
|
|
|
config(['trypost.platforms.linkedin-page.enabled' => true]);
|
|
|
|
|
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'w_organization_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => null],
|
|
|
|
|
'organizations' => [
|
|
|
|
|
['id' => 123456, 'name' => 'Test Company', 'vanity_name' => 'testcompany', 'logo' => null],
|
|
|
|
|
],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.select-identity'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page
|
|
|
|
|
->component('accounts/LinkedInSelect')
|
|
|
|
|
->where('person', null)
|
|
|
|
|
->has('organizations', 1)
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selecting the person is rejected when the personal profile capability is disabled', function () {
|
|
|
|
|
config(['trypost.platforms.linkedin.enabled' => false]);
|
|
|
|
|
config(['trypost.platforms.linkedin-page.enabled' => true]);
|
|
|
|
|
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'w_organization_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => null],
|
|
|
|
|
'organizations' => [],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'person',
|
2026-01-18 18:56:51 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
2026-06-25 00:05:09 +00:00
|
|
|
$this->assertDatabaseMissing('social_accounts', ['platform_user_id' => 'person-123']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selecting an organization is rejected when company pages are disabled', function () {
|
|
|
|
|
config(['trypost.platforms.linkedin.enabled' => true]);
|
|
|
|
|
config(['trypost.platforms.linkedin-page.enabled' => false]);
|
|
|
|
|
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'profile', 'email', 'w_member_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'organization',
|
|
|
|
|
'organization_id' => 123456,
|
2026-01-18 18:56:51 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
2026-06-25 00:05:09 +00:00
|
|
|
$this->assertDatabaseMissing('social_accounts', ['platform_user_id' => 123456]);
|
|
|
|
|
});
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('select-identity returns the popup callback when the session expired', function () {
|
|
|
|
|
// Rendered inside the OAuth popup, so a redirect would strand it — it must
|
|
|
|
|
// answer with the self-closing callback view instead.
|
|
|
|
|
$response = $this->actingAs($this->user)->get(route('app.social.linkedin.select-identity'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->component('accounts/PopupCallback'));
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
2026-06-25 00:05:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selecting the person creates a linkedin account', function () {
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'profile', 'email', 'w_member_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'person',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->component('accounts/PopupCallback'));
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', true));
|
2026-06-25 00:05:09 +00:00
|
|
|
|
|
|
|
|
$this->assertDatabaseHas('social_accounts', [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform' => Platform::LinkedIn->value,
|
|
|
|
|
'platform_user_id' => 'person-123',
|
|
|
|
|
'username' => 'johndoe',
|
|
|
|
|
'display_name' => 'John Doe',
|
|
|
|
|
'status' => Status::Connected->value,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
expect(session('linkedin_pending'))->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selecting the person downloads and stores the avatar', function () {
|
|
|
|
|
Storage::fake();
|
|
|
|
|
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'profile', 'email', 'w_member_social'],
|
|
|
|
|
'person' => ['id' => 'person-avatar', 'name' => 'John Doe', 'avatar' => 'https://media.example.com/avatar.jpg', 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [],
|
|
|
|
|
]]);
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
Http::fake([
|
2026-06-25 00:05:09 +00:00
|
|
|
'https://media.example.com/avatar.jpg' => Http::response('fake-image-bytes', 200, ['Content-Type' => 'image/jpeg']),
|
2026-01-18 18:56:51 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
$this->actingAs($this->user)->post(route('app.social.linkedin.select'), ['type' => 'person']);
|
|
|
|
|
|
|
|
|
|
// The avatar download (uploadFromUrl) ran and a stored path was persisted.
|
|
|
|
|
Http::assertSent(fn ($request) => $request->url() === 'https://media.example.com/avatar.jpg');
|
|
|
|
|
|
|
|
|
|
$account = SocialAccount::where('platform_user_id', 'person-avatar')->first();
|
|
|
|
|
expect($account->getRawOriginal('avatar_url'))->not->toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selecting an organization creates a linkedin-page account with the admin recorded in meta', function () {
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'profile', 'email', 'w_organization_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [
|
|
|
|
|
['id' => 123456, 'name' => 'Test Company', 'vanity_name' => 'testcompany', 'logo' => null],
|
|
|
|
|
],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'organization',
|
|
|
|
|
'organization_id' => 123456,
|
|
|
|
|
]);
|
2026-01-18 18:56:51 +00:00
|
|
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', true));
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
$account = SocialAccount::where('platform', Platform::LinkedInPage->value)
|
|
|
|
|
->where('platform_user_id', 123456)
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
expect($account)->not->toBeNull();
|
|
|
|
|
expect($account->display_name)->toBe('Test Company');
|
|
|
|
|
expect($account->username)->toBe('testcompany');
|
|
|
|
|
expect($account->meta['admin_user_id'])->toBe('person-123');
|
|
|
|
|
expect($account->meta['admin_name'])->toBe('John Doe');
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|
|
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('selecting an organization the member does not administer is rejected', function () {
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'w_organization_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [
|
|
|
|
|
['id' => 111, 'name' => 'My Company', 'vanity_name' => 'myco', 'logo' => null],
|
|
|
|
|
],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
// 999 is not in the admin-verified list — a tampered POST must not connect it.
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'organization',
|
|
|
|
|
'organization_id' => 999,
|
2026-01-18 18:56:51 +00:00
|
|
|
]);
|
|
|
|
|
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
2026-06-25 00:05:09 +00:00
|
|
|
$this->assertDatabaseMissing('social_accounts', ['platform_user_id' => 999]);
|
|
|
|
|
});
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
test('selecting an organization splits comma-separated approvedScopes before saving', function () {
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
// Socialite returns LinkedIn scopes CSV-joined into a single element.
|
|
|
|
|
'approved_scopes' => ['email,openid,profile,w_organization_social,r_organization_social,rw_organization_admin,w_member_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [
|
|
|
|
|
['id' => 999888, 'name' => 'Scope Company', 'vanity_name' => 'scopeco', 'logo' => null],
|
|
|
|
|
],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'organization',
|
|
|
|
|
'organization_id' => 999888,
|
|
|
|
|
]);
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
$account = SocialAccount::where('platform_user_id', 999888)->first();
|
|
|
|
|
expect($account->scopes)->toEqualCanonicalizing([
|
|
|
|
|
'email', 'openid', 'profile',
|
|
|
|
|
'w_organization_social', 'r_organization_social',
|
|
|
|
|
'rw_organization_admin', 'w_member_social',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('select rejects an invalid identity type without stranding the popup', function () {
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => [],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), ['type' => 'bogus']);
|
2026-01-18 18:56:51 +00:00
|
|
|
|
2026-06-25 00:05:09 +00:00
|
|
|
// A redirect-back would strand the popup; it must answer with the self-closing callback view.
|
2026-01-18 18:56:51 +00:00
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->component('accounts/PopupCallback'));
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
2026-06-25 00:05:09 +00:00
|
|
|
$this->assertDatabaseMissing('social_accounts', ['platform_user_id' => 'person-123']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('select fails with expired session', function () {
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'person',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('message', 'Session expired. Please try again.'));
|
2026-06-25 00:05:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('selecting the person shows network_taken when a linkedin page already occupies the network', function () {
|
|
|
|
|
config()->set('trypost.self_hosted', false);
|
|
|
|
|
|
|
|
|
|
SocialAccount::factory()->linkedinPage()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform_user_id' => 'existing-linkedin-page',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'test-access-token',
|
|
|
|
|
'refresh_token' => 'test-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'profile', 'email', 'w_member_social'],
|
|
|
|
|
'person' => ['id' => 'new-person', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'person',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', false));
|
|
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('message', __('accounts.popup_callback.network_taken')));
|
2026-06-25 00:05:09 +00:00
|
|
|
|
|
|
|
|
$this->assertDatabaseMissing('social_accounts', [
|
|
|
|
|
'platform' => Platform::LinkedIn->value,
|
|
|
|
|
'platform_user_id' => 'new-person',
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('user can connect multiple linkedin organizations in self-hosted mode', function () {
|
|
|
|
|
config()->set('trypost.self_hosted', true);
|
|
|
|
|
|
|
|
|
|
SocialAccount::factory()->linkedinPage()->create([
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'platform_user_id' => '123456',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
session(['linkedin_pending' => [
|
|
|
|
|
'workspace_id' => $this->workspace->id,
|
|
|
|
|
'token' => 'new-access-token',
|
|
|
|
|
'refresh_token' => 'new-refresh-token',
|
|
|
|
|
'expires_in' => 5184000,
|
|
|
|
|
'approved_scopes' => ['openid', 'profile', 'email', 'w_organization_social'],
|
|
|
|
|
'person' => ['id' => 'person-123', 'name' => 'John Doe', 'avatar' => null, 'vanity_name' => 'johndoe'],
|
|
|
|
|
'organizations' => [
|
|
|
|
|
['id' => 789012, 'name' => 'Another Company', 'vanity_name' => 'anothercompany', 'logo' => null],
|
|
|
|
|
],
|
|
|
|
|
]]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($this->user)->post(route('app.social.linkedin.select'), [
|
|
|
|
|
'type' => 'organization',
|
|
|
|
|
'organization_id' => 789012,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
2026-06-25 16:54:16 +00:00
|
|
|
$response->assertInertia(fn (Assert $page) => $page->where('success', true));
|
2026-06-25 00:05:09 +00:00
|
|
|
|
|
|
|
|
expect($this->workspace->socialAccounts()->where('platform', Platform::LinkedInPage)->count())->toBe(2);
|
2026-01-18 18:56:51 +00:00
|
|
|
});
|