From dbbf450ef5e43431e962ea35c0f6042c094d179a Mon Sep 17 00:00:00 2001
From: Claire <claire.github-309c@sitedethib.com>
Date: Mon, 6 Jan 2025 11:04:25 +0100
Subject: [PATCH] Fix `fediverse:creator` metadata not showing up in REST API
 (#33466)

---
 app/models/preview_card.rb                    |  2 +-
 .../rest/preview_card_serializer_spec.rb      | 19 ++++++++++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/app/models/preview_card.rb b/app/models/preview_card.rb
index f6f37c8c82..56fe483635 100644
--- a/app/models/preview_card.rb
+++ b/app/models/preview_card.rb
@@ -170,7 +170,7 @@ class PreviewCard < ApplicationRecord
   private
 
   def serialized_authors
-    if author_name? || author_url?
+    if author_name? || author_url? || author_account_id?
       PreviewCard::Author
         .new(self)
     end
diff --git a/spec/serializers/rest/preview_card_serializer_spec.rb b/spec/serializers/rest/preview_card_serializer_spec.rb
index 6dbc337865..41ba305b7c 100644
--- a/spec/serializers/rest/preview_card_serializer_spec.rb
+++ b/spec/serializers/rest/preview_card_serializer_spec.rb
@@ -21,7 +21,24 @@ RSpec.describe REST::PreviewCardSerializer do
     end
   end
 
-  context 'when preview card has author data' do
+  context 'when preview card has fediverse author data' do
+    let(:preview_card) { Fabricate.build :preview_card, author_account: Fabricate(:account) }
+
+    it 'includes populated authors array' do
+      expect(subject.deep_symbolize_keys)
+        .to include(
+          authors: be_an(Array).and(
+            contain_exactly(
+              include(
+                account: be_present
+              )
+            )
+          )
+        )
+    end
+  end
+
+  context 'when preview card has non-fediverse author data' do
     let(:preview_card) { Fabricate.build :preview_card, author_name: 'Name', author_url: 'https://host.example/123' }
 
     it 'includes populated authors array' do