Allow notes to be syndicated to Mastodon

This commit is contained in:
Jonny Barnes 2022-11-04 15:23:31 +00:00
parent ffe90b9399
commit 72cb4fd7eb
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
11 changed files with 200 additions and 5 deletions

View file

@ -0,0 +1,39 @@
<?php
namespace Tests\Unit\Jobs;
use App\Jobs\SyndicateNoteToMastodon;
use App\Models\Note;
use Faker\Factory;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class SyndicateNoteToMastodonJobTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function weSyndicateNotesToMastodon(): void
{
config(['bridgy.mastodon_token' => 'test']);
$faker = Factory::create();
$randomNumber = $faker->randomNumber();
$mock = new MockHandler([
new Response(201, ['Location' => 'https://mastodon.example/@jonny/' . $randomNumber]),
]);
$handler = HandlerStack::create($mock);
$client = new Client(['handler' => $handler]);
$note = Note::factory()->create();
$job = new SyndicateNoteToMastodon($note);
$job->handle($client);
$this->assertDatabaseHas('notes', [
'mastodon_url' => 'https://mastodon.example/@jonny/' . $randomNumber,
]);
}
}

View file

@ -113,8 +113,8 @@ class NotesTest extends TestCase
/** @test */
public function shorturlMethodReturnsExpectedValue(): void
{
Note::factory(14)->create();
$note = Note::find(14);
$note = Note::factory()->make();
$note->id = 14;
$this->assertEquals(config('app.shorturl') . '/notes/E', $note->shorturl);
}