Allow notes to be syndicated to Mastodon
This commit is contained in:
parent
ffe90b9399
commit
72cb4fd7eb
11 changed files with 200 additions and 5 deletions
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Tests\Feature;
|
||||
|
||||
use App\Jobs\SendWebMentions;
|
||||
use App\Jobs\SyndicateNoteToMastodon;
|
||||
use App\Jobs\SyndicateNoteToTwitter;
|
||||
use App\Models\Media;
|
||||
use App\Models\Note;
|
||||
|
@ -123,7 +124,7 @@ class MicropubControllerTest extends TestCase
|
|||
}
|
||||
|
||||
/** @test */
|
||||
public function micropubClientCanRequestTheNewNoteIsSyndicatedToTwitter(): void
|
||||
public function micropubClientCanRequestTheNewNoteIsSyndicatedToTwitterAndMastodon(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
|
@ -131,6 +132,10 @@ class MicropubControllerTest extends TestCase
|
|||
'uid' => 'https://twitter.com/jonnybarnes',
|
||||
'service_name' => 'Twitter',
|
||||
]);
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://mastodon.social/@jonnybarnes',
|
||||
'service_name' => 'Mastodon',
|
||||
]);
|
||||
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
|
@ -139,13 +144,17 @@ class MicropubControllerTest extends TestCase
|
|||
[
|
||||
'h' => 'entry',
|
||||
'content' => $note,
|
||||
'mp-syndicate-to' => 'https://twitter.com/jonnybarnes',
|
||||
'mp-syndicate-to' => [
|
||||
'https://twitter.com/jonnybarnes',
|
||||
'https://mastodon.social/@jonnybarnes',
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$response->assertJson(['response' => 'created']);
|
||||
$this->assertDatabaseHas('notes', ['note' => $note]);
|
||||
Queue::assertPushed(SyndicateNoteToTwitter::class);
|
||||
Queue::assertPushed(SyndicateNoteToMastodon::class);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -243,6 +252,10 @@ class MicropubControllerTest extends TestCase
|
|||
'uid' => 'https://twitter.com/jonnybarnes',
|
||||
'service_name' => 'Twitter',
|
||||
]);
|
||||
SyndicationTarget::factory()->create([
|
||||
'uid' => 'https://mastodon.social/@jonnybarnes',
|
||||
'service_name' => 'Mastodon',
|
||||
]);
|
||||
|
||||
$faker = Factory::create();
|
||||
$note = $faker->text;
|
||||
|
@ -255,6 +268,7 @@ class MicropubControllerTest extends TestCase
|
|||
'in-reply-to' => ['https://aaronpk.localhost'],
|
||||
'mp-syndicate-to' => [
|
||||
'https://twitter.com/jonnybarnes',
|
||||
'https://mastodon.social/@jonnybarnes',
|
||||
],
|
||||
'photo' => [config('filesystems.disks.s3.url') . '/test-photo.jpg'],
|
||||
],
|
||||
|
@ -266,6 +280,7 @@ class MicropubControllerTest extends TestCase
|
|||
->assertJson(['response' => 'created']);
|
||||
Queue::assertPushed(SendWebMentions::class);
|
||||
Queue::assertPushed(SyndicateNoteToTwitter::class);
|
||||
Queue::assertPushed(SyndicateNoteToMastodon::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
39
tests/Unit/Jobs/SyndicateNoteToMastodonJobTest.php
Normal file
39
tests/Unit/Jobs/SyndicateNoteToMastodonJobTest.php
Normal 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,
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue