Move request parsing into DTOs via fromRequest(), expand update handler
Each DTO now owns its own parsing logic via fromRequest(), removing the normalization layer from MicropubRequest entirely. UpdateHandler gains delete support and allows replace/add/delete to compose in a single request rather than being mutually exclusive. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ad15b36f4d
commit
1137d2a07e
8 changed files with 310 additions and 124 deletions
|
|
@ -711,6 +711,116 @@ class MicropubControllerTest extends TestCase
|
|||
$this->assertDatabaseHas('notes', ['note' => $note]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function micropub_client_api_request_can_combine_replace_and_add_in_single_update(): void
|
||||
{
|
||||
$note = Note::factory()->create();
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
[
|
||||
'action' => 'update',
|
||||
'url' => $note->uri,
|
||||
'replace' => [
|
||||
'content' => ['replaced content'],
|
||||
],
|
||||
'add' => [
|
||||
'syndication' => ['https://www.swarmapp.com/checkin/123'],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$response
|
||||
->assertJson(['response' => 'updated'])
|
||||
->assertSuccessful();
|
||||
|
||||
$note->refresh();
|
||||
$this->assertSame('replaced content', $note->content);
|
||||
$this->assertDatabaseHas('notes', [
|
||||
'swarm_url' => 'https://www.swarmapp.com/checkin/123',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function micropub_client_api_request_can_delete_entire_property(): void
|
||||
{
|
||||
$note = Note::factory()->create([
|
||||
'swarm_url' => 'https://www.swarmapp.com/checkin/123',
|
||||
'facebook_url' => 'https://www.facebook.com/post/123',
|
||||
]);
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
[
|
||||
'action' => 'update',
|
||||
'url' => $note->uri,
|
||||
'delete' => ['syndication'],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$response
|
||||
->assertJson(['response' => 'updated'])
|
||||
->assertSuccessful();
|
||||
|
||||
$note->refresh();
|
||||
$this->assertNull($note->swarm_url);
|
||||
$this->assertNull($note->facebook_url);
|
||||
$this->assertNull($note->tweet_id);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function micropub_client_api_request_can_delete_specific_syndication_value(): void
|
||||
{
|
||||
$note = Note::factory()->create([
|
||||
'swarm_url' => 'https://www.swarmapp.com/checkin/123',
|
||||
'facebook_url' => 'https://www.facebook.com/post/123',
|
||||
]);
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
[
|
||||
'action' => 'update',
|
||||
'url' => $note->uri,
|
||||
'delete' => [
|
||||
'syndication' => ['https://www.swarmapp.com/checkin/123'],
|
||||
],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$response
|
||||
->assertJson(['response' => 'updated'])
|
||||
->assertSuccessful();
|
||||
|
||||
$note->refresh();
|
||||
$this->assertNull($note->swarm_url);
|
||||
$this->assertSame('https://www.facebook.com/post/123', $note->facebook_url);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function micropub_client_api_request_can_delete_photo(): void
|
||||
{
|
||||
$note = Note::factory()->create();
|
||||
$media = new \App\Models\Media;
|
||||
$media->path = 'https://example.org/photo.jpg';
|
||||
$media->type = 'image';
|
||||
$media->save();
|
||||
$note->media()->save($media);
|
||||
|
||||
$response = $this->postJson(
|
||||
'/api/post',
|
||||
[
|
||||
'action' => 'update',
|
||||
'url' => $note->uri,
|
||||
'delete' => ['photo'],
|
||||
],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$response
|
||||
->assertJson(['response' => 'updated'])
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseMissing('media_endpoint', [
|
||||
'path' => 'https://example.org/photo.jpg',
|
||||
]);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function micropub_client_api_request_creates_articles_when_it_includes_the_name_property(): void
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue