Setup support for syndicating to Bluesky
This commit is contained in:
parent
5d6d611707
commit
cbbe87e23c
9 changed files with 204 additions and 9 deletions
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\SendWebMentions;
|
||||
use App\Jobs\SyndicateNoteToBluesky;
|
||||
use App\Jobs\SyndicateNoteToMastodon;
|
||||
use App\Models\Media;
|
||||
use App\Models\Note;
|
||||
|
@ -123,18 +124,18 @@ class MicropubControllerTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function micropubClientCanRequestTheNewNoteIsSyndicatedToTwitterAndMastodon(): void
|
||||
public function micropubClientCanRequestTheNewNoteIsSyndicatedToMastodonAndBluesky(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://twitter.com/jonnybarnes',
|
||||
'service_name' => 'Twitter',
|
||||
]);
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://mastodon.social/@jonnybarnes',
|
||||
'service_name' => 'Mastodon',
|
||||
]);
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://bsky.app/profile/jonnybarnes.uk',
|
||||
'service_name' => 'Bluesky',
|
||||
]);
|
||||
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
|
@ -145,6 +146,7 @@ class MicropubControllerTest extends TestCase
|
|||
'content' => $note,
|
||||
'mp-syndicate-to' => [
|
||||
'https://mastodon.social/@jonnybarnes',
|
||||
'https://bsky.app/profile/jonnybarnes.uk',
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
|
@ -152,6 +154,7 @@ class MicropubControllerTest extends TestCase
|
|||
$response->assertJson(['response' => 'created']);
|
||||
$this->assertDatabaseHas('notes', ['note' => $note]);
|
||||
Queue::assertPushed(SyndicateNoteToMastodon::class);
|
||||
Queue::assertPushed(SyndicateNoteToBluesky::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -249,6 +252,10 @@ class MicropubControllerTest extends TestCase
|
|||
'uid' => 'https://mastodon.social/@jonnybarnes',
|
||||
'service_name' => 'Mastodon',
|
||||
]);
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://bsky.app/profile/jonnybarnes.uk',
|
||||
'service_name' => 'Bluesky',
|
||||
]);
|
||||
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
|
@ -261,6 +268,7 @@ class MicropubControllerTest extends TestCase
|
|||
'in-reply-to' => ['https://aaronpk.localhost'],
|
||||
'mp-syndicate-to' => [
|
||||
'https://mastodon.social/@jonnybarnes',
|
||||
'https://bsky.app/profile/jonnybarnes.uk',
|
||||
],
|
||||
'photo' => [config('filesystems.disks.s3.url') . '/test-photo.jpg'],
|
||||
],
|
||||
|
@ -272,6 +280,7 @@ class MicropubControllerTest extends TestCase
|
|||
->assertJson(['response' => 'created']);
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
Queue::assertPushed(SyndicateNoteToMastodon::class);
|
||||
Queue::assertPushed(SyndicateNoteToBluesky::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
69
tests/Unit/Jobs/SyndicateNoteToBlueskyJobTest.php
Normal file
69
tests/Unit/Jobs/SyndicateNoteToBlueskyJobTest.php
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Jobs;
|
||||
|
||||
use App\Jobs\SyndicateNoteToBluesky;
|
||||
use App\Models\Note;
|
||||
use Faker\Factory;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Handler\MockHandler;
|
||||
use GuzzleHttp\HandlerStack;
|
||||
use GuzzleHttp\Middleware;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SyndicateNoteToBlueskyJobTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
/** @test */
|
||||
public function weSyndicateNotesToBluesky(): void
|
||||
{
|
||||
config(['bridgy.bluesky_token' => 'test']);
|
||||
$faker = Factory::create();
|
||||
$randomNumber = $faker->randomNumber();
|
||||
$mock = new MockHandler([
|
||||
new Response(201, ['Location' => 'https://bsky.app/profile/jonnybarnes.uk/' . $randomNumber]),
|
||||
]);
|
||||
$handler = HandlerStack::create($mock);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
|
||||
$note = Note::factory()->create();
|
||||
$job = new SyndicateNoteToBluesky($note);
|
||||
$job->handle($client);
|
||||
|
||||
$this->assertDatabaseHas('notes', [
|
||||
'bluesky_url' => 'https://bsky.app/profile/jonnybarnes.uk/' . $randomNumber,
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function weSyndicateTheOriginalMarkdownToBluesky(): void
|
||||
{
|
||||
config(['bridgy.bluesky_token' => 'test']);
|
||||
$faker = Factory::create();
|
||||
$randomNumber = $faker->randomNumber();
|
||||
|
||||
$container = [];
|
||||
$history = Middleware::history($container);
|
||||
$mock = new MockHandler([
|
||||
new Response(201, ['Location' => 'https://bsky.app/profile/jonnybarnes.uk/' . $randomNumber]),
|
||||
]);
|
||||
$handler = HandlerStack::create($mock);
|
||||
$handler->push($history);
|
||||
$client = new Client(['handler' => $handler]);
|
||||
|
||||
$note = Note::factory()->create(['note' => 'This is a **test**']);
|
||||
$job = new SyndicateNoteToBluesky($note);
|
||||
$job->handle($client);
|
||||
|
||||
$this->assertDatabaseHas('notes', [
|
||||
'bluesky_url' => 'https://bsky.app/profile/jonnybarnes.uk/' . $randomNumber,
|
||||
]);
|
||||
|
||||
$expectedRequestContent = '{"type":["h-entry"],"properties":{"content":["This is a **test**"]}}';
|
||||
|
||||
$this->assertEquals($expectedRequestContent, $container[0]['request']->getBody()->getContents());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue