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 <noreply@anthropic.com>
This commit is contained in:
Jonny Barnes 2026-11-01 15:29:00 +00:00
commit e8f2535cd1
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
2 changed files with 47 additions and 1 deletions

View file

@ -35,7 +35,7 @@ class EntryHandler implements MicropubHandlerInterface
$dataArray = $data->toArray(); $dataArray = $data->toArray();
$location = match (true) { $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['bookmark-of']) => resolve(BookmarkService::class)->create($dataArray)->uri,
isset($dataArray['name']) => resolve(ArticleService::class)->create($dataArray)->uri, isset($dataArray['name']) => resolve(ArticleService::class)->create($dataArray)->uri,
default => resolve(NoteService::class)->create($dataArray)->uri, default => resolve(NoteService::class)->create($dataArray)->uri,

View file

@ -9,6 +9,8 @@ use App\Jobs\SendWebMentions;
use App\Jobs\SyndicateNoteToBluesky; use App\Jobs\SyndicateNoteToBluesky;
use App\Jobs\SyndicateNoteToMastodon; use App\Jobs\SyndicateNoteToMastodon;
use App\Models\Article; use App\Models\Article;
use App\Models\Bookmark;
use App\Models\Like;
use App\Models\Media; use App\Models\Media;
use App\Models\Note; use App\Models\Note;
use App\Models\Place; use App\Models\Place;
@ -883,6 +885,50 @@ class MicropubControllerTest extends TestCase
$this->assertStringStartsWith(config('app.url').'/blog/', $response->headers->get('Location')); $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] #[Test]
public function micropub_client_api_request_creates_an_unpublished_article_when_post_status_is_draft(): void public function micropub_client_api_request_creates_an_unpublished_article_when_post_status_is_draft(): void
{ {