akkounts/spec/services/nostr_manager/publish_zap_receipt_spec.rb
Râu Cao b91d90d75c
Fix some specs, improve config
Allow empty string to unset nostr relay URL config
2024-08-14 13:37:15 +02:00

58 lines
1.8 KiB
Ruby

require 'rails_helper'
RSpec.describe NostrManager::PublishZapReceipt, type: :model do
let(:user) { create :user, ln_account: "123456abcdef" }
let(:zap) { create :zap, user: user }
before do
Setting.nostr_relay_url = ""
end
describe "Default/delayed execution" do
it "publishes zap receipts to all requested relays" do
expect(NostrPublishEventJob).to receive(:perform_later)
.exactly(2).times.and_return(true)
described_class.call(zap: zap)
end
context "with a long relay list" do
before do
relays = zap.request["tags"].find { |t| t.first == "relays" }
[
"wss://aegonstargaryen.example.com", "wss://visenya.example.com",
"wss://rhaenys.example.com", "wss://housevelaryon.example.com",
"wss://aemond.example.com", "wss://jaehaerys.example.com",
"wss://daenerys.example.com", "wss://corlys.example.com",
"wss://laenor.example.com", "wss://alysanne.example.com",
"wss://balerion.example.com", "wss://meraxes.example.com",
"wss://vhaegar.example.com", "wss://vermax.example.com",
"wss://caraxes.example.com"
].each do |url|
relays << url
end
end
it "limits publishing attempts to the first 12 relays" do
expect(NostrPublishEventJob).to receive(:perform_later)
.exactly(12).times.and_return(true)
described_class.call(zap: zap)
end
context "with own relay configured" do
before do
Setting.nostr_relay_url = "wss://foobar.kosmos.org"
end
it "also publishes the receipt to our own relay" do
expect(NostrPublishEventJob).to receive(:perform_later)
.exactly(13).times.and_return(true)
described_class.call(zap: zap)
end
end
end
end
end