jonnybarnes.uk/tests/Unit/Jobs/SyndicateNoteToBlueskyJobTest.php
Jonny Barnes e08763c526
Migrate outbound HTTP calls from Guzzle to the Http facade
Replaces every raw GuzzleHttp\Client usage (Nominatim, web.archive.org,
webmention fetch/discover/send, Bridgy syndication, IndieAuth client_id
lookup, contact avatar/h-card fetch, profile image download, and the
CloudConvert screenshot pipeline) with Illuminate\Support\Facades\Http,
and enables Http::preventStrayRequests() globally in tests so any
un-faked outbound call now fails loudly instead of silently hitting the
network.

The CloudConvert retry-until-finished middleware in AppServiceProvider
is replaced by a plain polling loop in SaveScreenshot, which also fixes
a latent bug where the old middleware decoded a response object instead
of its body. Bridgy syndication jobs keep their tries=1/no-retry
semantics unchanged to avoid duplicate publishes. Guzzle's PSR-7 helpers
(Header, UriResolver, Utils) stay in SendWebMentions since Http has no
equivalent for them.

Every affected test file's Guzzle MockHandler/HandlerStack boilerplate
is replaced with Http::fake()/Http::sequence().

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P8j7cJhCiYDsGUgB7obKNQ
2026-07-26 09:12:01 +01:00

84 lines
2.3 KiB
PHP

<?php
namespace Tests\Unit\Jobs;
use App\Jobs\SyndicateNoteToBluesky;
use App\Models\Note;
use Faker\Factory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Facades\Http;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class SyndicateNoteToBlueskyJobTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function we_syndicate_notes_to_bluesky(): void
{
$faker = Factory::create();
$randomNumber = $faker->randomNumber();
$blueskyUrl = 'https://bsky.app/profile/jonnybarnes.uk/'.$randomNumber;
Http::fake([
'brid.gy/*' => Http::response([
'url' => $blueskyUrl,
'id' => (string) $randomNumber,
'type' => ['h-entry'],
], 201),
]);
$note = Note::factory()->create();
$job = new SyndicateNoteToBluesky($note);
$job->handle();
$this->assertDatabaseHas('notes', [
'bluesky_url' => $blueskyUrl,
]);
}
#[Test]
public function we_post_the_correct_source_and_target(): void
{
Http::fake([
'brid.gy/*' => Http::response([
'url' => 'https://bsky.app/profile/jonnybarnes.uk/1',
], 201),
]);
$note = Note::factory()->create(['note' => 'This is a **test**']);
$job = new SyndicateNoteToBluesky($note);
$job->handle();
Http::assertSent(function (Request $request) use ($note) {
return $request->url() === 'https://brid.gy/publish/webmention'
&& $request['source'] === $note->uri
&& $request['target'] === 'https://brid.gy/publish/bluesky';
});
}
#[Test]
public function a_bridgy_failure_throws_and_does_not_set_bluesky_url(): void
{
Http::fake([
'brid.gy/*' => Http::response([
'error' => 'Could not find target link',
], 400),
]);
$note = Note::factory()->create();
$job = new SyndicateNoteToBluesky($note);
$this->expectException(\RuntimeException::class);
try {
$job->handle();
} finally {
$this->assertDatabaseHas('notes', [
'id' => $note->id,
'bluesky_url' => null,
]);
}
}
}