From 5501b9368610ad140a4e4674573e5a614f49ccd8 Mon Sep 17 00:00:00 2001 From: Doar Mihai Date: Sun, 19 Jul 2026 16:51:15 +0300 Subject: [PATCH] feat: expose cms_type/WordPress credentials and published_url in API responses --- app/Http/Resources/PostResource.php | 1 + app/Http/Resources/SiteResource.php | 5 ++++- tests/Feature/Api/PostsApiTest.php | 8 ++++++++ tests/Feature/Api/SitesApiTest.php | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/Http/Resources/PostResource.php b/app/Http/Resources/PostResource.php index b10ebd0..8981fa0 100644 --- a/app/Http/Resources/PostResource.php +++ b/app/Http/Resources/PostResource.php @@ -18,6 +18,7 @@ class PostResource extends JsonResource 'body' => $this->body, 'status' => $this->status, 'scheduled_at' => $this->scheduled_at, + 'published_url' => $this->published_url, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; diff --git a/app/Http/Resources/SiteResource.php b/app/Http/Resources/SiteResource.php index 2319a5a..a59131d 100644 --- a/app/Http/Resources/SiteResource.php +++ b/app/Http/Resources/SiteResource.php @@ -14,8 +14,11 @@ class SiteResource extends JsonResource 'name' => $this->name, 'url' => $this->url, 'description' => $this->description, + 'cms_type' => $this->cms_type, + 'wp_username' => $this->wp_username, + 'wp_app_password' => $this->wp_app_password, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]; } -} +} \ No newline at end of file diff --git a/tests/Feature/Api/PostsApiTest.php b/tests/Feature/Api/PostsApiTest.php index 0328c9a..25101ce 100644 --- a/tests/Feature/Api/PostsApiTest.php +++ b/tests/Feature/Api/PostsApiTest.php @@ -134,3 +134,11 @@ test('it deletes a post', function () { $response->assertNoContent(); expect(Post::find($post->id))->toBeNull(); }); + +test('it includes published_url in the post response', function () { + $post = Post::factory()->create(['published_url' => 'https://example.com/my-post']); + + $response = $this->getJson("/api/posts/{$post->id}"); + + $response->assertOk()->assertJsonPath('data.published_url', 'https://example.com/my-post'); +}); diff --git a/tests/Feature/Api/SitesApiTest.php b/tests/Feature/Api/SitesApiTest.php index 720f9c0..e434686 100644 --- a/tests/Feature/Api/SitesApiTest.php +++ b/tests/Feature/Api/SitesApiTest.php @@ -32,3 +32,17 @@ test('it shows a single site', function () { test('it returns 404 for a missing site', function () { $this->getJson('/api/sites/999')->assertNotFound(); }); + +test('it includes WordPress fields in the site response', function () { + $site = Site::factory()->wordpress()->create([ + 'wp_username' => 'admin', + 'wp_app_password' => 'abcd 1234 efgh 5678', + ]); + + $response = $this->getJson("/api/sites/{$site->id}"); + + $response->assertOk() + ->assertJsonPath('data.cms_type', 'wordpress') + ->assertJsonPath('data.wp_username', 'admin') + ->assertJsonPath('data.wp_app_password', 'abcd 1234 efgh 5678'); +});