From 6f6abae25841bf63552022bd5aebeb44b80de647 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sun, 6 Nov 2022 10:16:18 +0000 Subject: [PATCH] When posting to Mastodon send the original markdown --- app/Jobs/SyndicateNoteToMastodon.php | 2 +- .../Jobs/SyndicateNoteToMastodonJobTest.php | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/Jobs/SyndicateNoteToMastodon.php b/app/Jobs/SyndicateNoteToMastodon.php index 12b9b308..87050413 100644 --- a/app/Jobs/SyndicateNoteToMastodon.php +++ b/app/Jobs/SyndicateNoteToMastodon.php @@ -54,7 +54,7 @@ class SyndicateNoteToMastodon implements ShouldQueue 'json' => [ 'type' => ['h-entry'], 'properties' => [ - 'content' => [$this->note->note], + 'content' => [$this->note->getRawOriginal('note')], ], ], ] diff --git a/tests/Unit/Jobs/SyndicateNoteToMastodonJobTest.php b/tests/Unit/Jobs/SyndicateNoteToMastodonJobTest.php index be7bf6d2..d90261e7 100644 --- a/tests/Unit/Jobs/SyndicateNoteToMastodonJobTest.php +++ b/tests/Unit/Jobs/SyndicateNoteToMastodonJobTest.php @@ -8,6 +8,7 @@ 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; @@ -36,4 +37,33 @@ class SyndicateNoteToMastodonJobTest extends TestCase 'mastodon_url' => 'https://mastodon.example/@jonny/' . $randomNumber, ]); } + + /** @test */ + public function weSyndicateTheOriginalMarkdown(): void + { + config(['bridgy.mastodon_token' => 'test']); + $faker = Factory::create(); + $randomNumber = $faker->randomNumber(); + + $container = []; + $history = Middleware::history($container); + $mock = new MockHandler([ + new Response(201, ['Location' => 'https://mastodon.example/@jonny/' . $randomNumber]), + ]); + $handler = HandlerStack::create($mock); + $handler->push($history); + $client = new Client(['handler' => $handler]); + + $note = Note::factory()->create(['note' => 'This is a **test**']); + $job = new SyndicateNoteToMastodon($note); + $job->handle($client); + + $this->assertDatabaseHas('notes', [ + 'mastodon_url' => 'https://mastodon.example/@jonny/' . $randomNumber, + ]); + + $expectedRequestContent = '{"type":["h-entry"],"properties":{"content":["This is a **test**"]}}'; + + $this->assertEquals($expectedRequestContent, $container[0]['request']->getBody()->getContents()); + } }