trypost/tests/Unit/Mail/PostPublishFailedTest.php
Paulo Castellano abe687d0fa
Fall back to display name when a published-post email has no username (#325)
* Fall back to display name when a published-post email has no username.

Facebook Pages often have no vanity username, which left the email as "Facebook Page (@)". Use username, then display name, and omit the empty parentheses when both are missing.

* Move the notification account label onto PostPlatform.

The fallback belongs on the row that always has a platform, so mail and in-app notify can call one method instead of guarding a missing social account at every call site.

* Cover the in-app published/failed notification body for Facebook Pages.

The email tests were not enough — SendNotification body is what the in-app inbox shows, and that path also goes through notificationLabel().
2026-09-03 12:51:44 -03:00

29 lines
977 B
PHP

<?php
declare(strict_types=1);
use App\Mail\PostPublishFailed;
use App\Models\Post;
use App\Models\PostPlatform;
use App\Models\SocialAccount;
use App\Models\Workspace;
test('failed email falls back to the page display name when facebook has no username', function () {
$workspace = Workspace::factory()->create(['name' => 'InboxPlacement.io']);
$account = SocialAccount::factory()->facebook()->create([
'workspace_id' => $workspace->id,
'username' => null,
'display_name' => 'InboxPlacement.io',
]);
$post = Post::factory()->failed()->create(['workspace_id' => $workspace->id]);
PostPlatform::factory()->facebook()->failed()->create([
'post_id' => $post->id,
'social_account_id' => $account->id,
'platform' => $account->platform,
]);
$mail = new PostPublishFailed($post);
$mail->assertSeeInHtml('Facebook Page (@InboxPlacement.io)');
$mail->assertDontSeeInHtml('Facebook Page (@)');
});