by descending post id

This commit is contained in:
Dylan Knutson
2025-08-13 08:18:47 +00:00
parent 6bb0b255fb
commit b33a267a83
13 changed files with 185 additions and 16 deletions

View File

@@ -140,5 +140,98 @@ RSpec.describe Domain::PostsHelper, type: :helper do
expect(link_for_source.model_path).to eq("/posts/fa@123456")
end
end
describe "Bluesky link handling" do
it "returns nil for Bluesky URLs that are not found" do
expect(
helper.link_for_source(
"https://bsky.app/profile/user1.bsky.social/post/123456",
),
).to be_nil
end
%w[
https://bsky.app/profile/user1.bsky.social/post/123456
https://bsky.app/profile/user1.bsky.social/post/123456/
bsky.app/profile/user1.bsky.social/post/123456
bsky.app/profile/user1.bsky.social/post/123456/
Bsky.app/profile/user1.bsky.social/post/123456
Bsky.app/profile/user1.bsky.social/post/123456/
].each do |url|
it "returns a link to Bluesky post for #{url}" do
user = create(:domain_user_bluesky_user, handle: "user1.bsky.social")
post =
create(
:domain_post_bluesky_post,
creator: user,
rkey: "123456",
at_uri: "at://#{user.did}/app.bsky.feed.post/123456",
text: "Bluesky Post Title",
)
expect(url).to eq_link_for_source(
model: post,
title: "Bluesky Post Title",
)
end
end
%w[
https://bsky.app/profile/did:plc:1234567890/post/abcdef
https://bsky.app/profile/did:plc:1234567890/post/abcdef/
bsky.app/profile/did:plc:1234567890/post/abcdef
bsky.app/profile/did:plc:1234567890/post/abcdef/
Bsky.app/profile/did:plc:1234567890/post/abcdef
Bsky.app/profile/did:plc:1234567890/post/abcdef/
].each do |url|
it "returns a link to Bluesky post for DID-based URL #{url}" do
post =
create(
:domain_post_bluesky_post,
rkey: "abcdef",
at_uri: "at://did:plc:1234567890/app.bsky.feed.post/abcdef",
text: "DID Bluesky Post",
)
expect(url).to eq_link_for_source(
model: post,
title: "DID Bluesky Post",
)
end
end
it "has the right model path for Bluesky posts" do
user = create(:domain_user_bluesky_user, handle: "user1.bsky.social")
post =
create(
:domain_post_bluesky_post,
creator: user,
rkey: "123456",
at_uri: "at://#{user.did}/app.bsky.feed.post/123456",
text: "Bluesky Post Title",
)
link_for_source =
helper.link_for_source(
"https://bsky.app/profile/user1.bsky.social/post/123456",
)
expect(link_for_source).to be_present
expect(link_for_source.model_path).to eq("/posts/bsky@123456")
end
it "handles URLs with different case variations" do
user = create(:domain_user_bluesky_user, handle: "user1.bsky.social")
post =
create(
:domain_post_bluesky_post,
creator: user,
rkey: "123456",
at_uri: "at://#{user.did}/app.bsky.feed.post/123456",
text: "Case Test Post",
)
# Test that the method handles case variations in the host part
# but the handle part should match exactly as stored in the database
expect(
"BSKY.APP/profile/user1.bsky.social/post/123456",
).to eq_link_for_source(model: post, title: "Case Test Post")
end
end
end
end

View File

@@ -11,7 +11,6 @@ RSpec::Matchers.define :eq_link_for_source do |model:, title:|
failure_message do |actual_url|
actual = helper.link_for_source(actual_url)
if actual.nil?
binding.pry
"link for source was nil for url #{actual_url}"
elsif actual.model != model
"expected model #{model.to_gid.uri.to_s} to be #{actual.model.to_gid.uri.to_s} for url #{actual_url}"