Merge pull request #525 from jonnybarnes/develop

MTM Post Markdown content to Mastodon
This commit is contained in:
Jonny Barnes 2022-11-06 10:32:03 +00:00 committed by GitHub
commit 52ac67ba7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -54,7 +54,7 @@ class SyndicateNoteToMastodon implements ShouldQueue
'json' => [
'type' => ['h-entry'],
'properties' => [
'content' => [$this->note->note],
'content' => [$this->note->getRawOriginal('note')],
],
],
]

View file

@ -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());
}
}