From e8f2535cd15117d610ac3f60b77640d6c773557a Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sun, 1 Nov 2026 15:29:00 +0000 Subject: [PATCH] Return our permalink in the Micropub Location header for likes Likes returned `url`, which is the liked post rather than our page. Use `uri` instead. Bookmarks already asked for `uri`, which didn't exist until the previous commit, so their Location header was empty. Neither case had a test, so assert the header value for both. Refs #148 Co-Authored-By: Claude Opus 5.5 --- .../Micropub/Handlers/EntryHandler.php | 2 +- tests/Feature/MicropubControllerTest.php | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/app/Services/Micropub/Handlers/EntryHandler.php b/app/Services/Micropub/Handlers/EntryHandler.php index d79a0418..6b68b88c 100644 --- a/app/Services/Micropub/Handlers/EntryHandler.php +++ b/app/Services/Micropub/Handlers/EntryHandler.php @@ -35,7 +35,7 @@ class EntryHandler implements MicropubHandlerInterface $dataArray = $data->toArray(); $location = match (true) { - isset($dataArray['like-of']) => resolve(LikeService::class)->create($dataArray)->url, + isset($dataArray['like-of']) => resolve(LikeService::class)->create($dataArray)->uri, isset($dataArray['bookmark-of']) => resolve(BookmarkService::class)->create($dataArray)->uri, isset($dataArray['name']) => resolve(ArticleService::class)->create($dataArray)->uri, default => resolve(NoteService::class)->create($dataArray)->uri, diff --git a/tests/Feature/MicropubControllerTest.php b/tests/Feature/MicropubControllerTest.php index 3fd8b515..5ff59844 100644 --- a/tests/Feature/MicropubControllerTest.php +++ b/tests/Feature/MicropubControllerTest.php @@ -9,6 +9,8 @@ use App\Jobs\SendWebMentions; use App\Jobs\SyndicateNoteToBluesky; use App\Jobs\SyndicateNoteToMastodon; use App\Models\Article; +use App\Models\Bookmark; +use App\Models\Like; use App\Models\Media; use App\Models\Note; use App\Models\Place; @@ -883,6 +885,50 @@ class MicropubControllerTest extends TestCase $this->assertStringStartsWith(config('app.url').'/blog/', $response->headers->get('Location')); } + #[Test] + public function micropub_client_api_request_for_a_like_returns_our_permalink_in_the_location_header(): void + { + Queue::fake(); + + $response = $this->postJson( + '/api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'like-of' => ['https://example.org/liked-post'], + ], + ], + ['HTTP_Authorization' => 'Bearer '.$this->getToken()] + ); + + $like = Like::where('url', 'https://example.org/liked-post')->sole(); + $response + ->assertStatus(201) + ->assertHeader('Location', config('app.url').'/likes/'.$like->id); + } + + #[Test] + public function micropub_client_api_request_for_a_bookmark_returns_our_permalink_in_the_location_header(): void + { + Queue::fake(); + + $response = $this->postJson( + '/api/post', + [ + 'type' => ['h-entry'], + 'properties' => [ + 'bookmark-of' => ['https://example.org/bookmarked-page'], + ], + ], + ['HTTP_Authorization' => 'Bearer '.$this->getToken()] + ); + + $bookmark = Bookmark::where('url', 'https://example.org/bookmarked-page')->sole(); + $response + ->assertStatus(201) + ->assertHeader('Location', config('app.url').'/bookmarks/'.$bookmark->id); + } + #[Test] public function micropub_client_api_request_creates_an_unpublished_article_when_post_status_is_draft(): void {