split out common bsky post creation logic into Bluesky::ProcessPostHelper

This commit is contained in:
Dylan Knutson
2025-08-14 17:55:17 +00:00
parent cfffe50541
commit e9ac97be29
11 changed files with 300 additions and 341 deletions

View File

@@ -96,7 +96,7 @@ RSpec.describe Tasks::Bluesky::Monitor do
:count,
).by(1).and change(Domain::PostFile::BlueskyPostFile, :count).by(2)
post = Domain::Post::BlueskyPost.last
post = Domain::Post::BlueskyPost.find_by(rkey: "test123")
expect(post.at_uri).to eq(
"at://#{test_did}/app.bsky.feed.post/test123",
)
@@ -136,9 +136,16 @@ RSpec.describe Tasks::Bluesky::Monitor do
end
it "enqueues download jobs for the media files" do
expect(Domain::StaticFileJob).to receive(:perform_later).twice
monitor.handle_message(commit_message)
post = Domain::Post::BlueskyPost.find_by(rkey: "test123")
job_args = SpecUtil.enqueued_job_args(Domain::StaticFileJob)
expect(job_args.count).to eq(2)
expect(job_args).to match(
[
hash_including(post_file: post.files.first),
hash_including(post_file: post.files.second),
],
)
end
end
@@ -190,7 +197,7 @@ RSpec.describe Tasks::Bluesky::Monitor do
:count,
).by(1).and change(Domain::PostFile::BlueskyPostFile, :count).by(1)
post = Domain::Post::BlueskyPost.last
post = Domain::Post::BlueskyPost.find_by(rkey: "quote123")
file = post.files.first
expect(file.alt_text).to eq("Quote post image")
@@ -228,19 +235,10 @@ RSpec.describe Tasks::Bluesky::Monitor do
)
end
it "creates a post with thumbnail file" do
expect { monitor.handle_message(commit_message) }.to change(
it "does not create a post" do
expect { monitor.handle_message(commit_message) }.to not_change(
Domain::Post::BlueskyPost,
:count,
).by(1).and change(Domain::PostFile::BlueskyPostFile, :count).by(1)
post = Domain::Post::BlueskyPost.last
file = post.files.first
expect(file.blob_ref).to eq("bafkreithumb123")
expect(file.file_order).to eq(0)
expect(file.url_str).to eq(
"https://bsky.social/xrpc/com.atproto.sync.getBlob?did=#{test_did}&cid=bafkreithumb123",
)
end
end
@@ -409,35 +407,6 @@ RSpec.describe Tasks::Bluesky::Monitor do
end
describe "edge cases" do
context "with malformed embed data" do
let(:commit_message) do
create_commit_message(
did: test_did,
time: base_time,
rkey: "malformed123",
record: {
"text" => "Post with malformed embed",
"embed" => {
"$type" => "app.bsky.embed.images",
"images" => [
{
"alt" => "Missing image data",
# Missing "image" field
},
],
},
},
)
end
it "creates the post but skips malformed media" do
expect { monitor.handle_message(commit_message) }.to change(
Domain::Post::BlueskyPost,
:count,
).by(1).and not_change(Domain::PostFile::BlueskyPostFile, :count)
end
end
context "with unknown embed type" do
let(:commit_message) do
create_commit_message(
@@ -454,11 +423,11 @@ RSpec.describe Tasks::Bluesky::Monitor do
)
end
it "creates the post but does not process the unknown embed" do
expect { monitor.handle_message(commit_message) }.to change(
it "does not create a post" do
expect { monitor.handle_message(commit_message) }.to not_change(
Domain::Post::BlueskyPost,
:count,
).by(1).and not_change(Domain::PostFile::BlueskyPostFile, :count)
).and not_change(Domain::PostFile::BlueskyPostFile, :count)
end
end
end