WIP Persist zaps, create and send zap receipts
This commit is contained in:
45
spec/services/nostr_manager/create_zap_receipt_spec.rb
Normal file
45
spec/services/nostr_manager/create_zap_receipt_spec.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe NostrManager::CreateZapReceipt, type: :model do
|
||||
let(:user) { create :user, ln_account: "123456abcdef" }
|
||||
let(:zap) { create :zap, user: user }
|
||||
|
||||
# before do
|
||||
# user.save!
|
||||
# zap.save!
|
||||
# end
|
||||
|
||||
subject {
|
||||
described_class.call(
|
||||
zap: zap, paid_at: 1673428978,
|
||||
preimage: "3539663535656537343331663432653165396430623966633664656664646563"
|
||||
)
|
||||
}
|
||||
|
||||
describe "Zap receipt" do
|
||||
it "is a kind:9735 note" do
|
||||
expect(subject).to be_a(Nostr::Event)
|
||||
expect(subject.kind).to eq(9735)
|
||||
end
|
||||
|
||||
it "sets created_at to when the invoice was paid" do
|
||||
expect(subject.created_at).to eq(1673428978)
|
||||
end
|
||||
|
||||
it "contains the zap recipient" do
|
||||
expect(subject.tags.find{|t| t[0] == "p"}[1]).to eq("07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3")
|
||||
end
|
||||
|
||||
it "contains the bolt11 invoice" do
|
||||
expect(subject.tags.find{|t| t[0] == "bolt11"}[1]).to eq(zap.payment_request)
|
||||
end
|
||||
|
||||
it "contains the invoice preimage" do
|
||||
expect(subject.tags.find{|t| t[0] == "preimage"}[1]).to eq("3539663535656537343331663432653165396430623966633664656664646563")
|
||||
end
|
||||
|
||||
it "contains the serialized zap request event as description" do
|
||||
expect(subject.tags.find{|t| t[0] == "description"}[1]).to eq(zap.request_event.to_json)
|
||||
end
|
||||
end
|
||||
end
|
||||
16
spec/services/nostr_manager/publish_zap_receipt_spec.rb
Normal file
16
spec/services/nostr_manager/publish_zap_receipt_spec.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe NostrManager::PublishZapReceipt, type: :model do
|
||||
let(:user) { create :user, ln_account: "123456abcdef" }
|
||||
let(:zap) { create :zap, user: user }
|
||||
|
||||
describe "Default/delayed execution" do
|
||||
it "publishes zap receipts to all requested relays" do
|
||||
2.times do
|
||||
expect(NostrPublishEventJob).to receive(:perform_later).and_return(true)
|
||||
end
|
||||
|
||||
described_class.call(zap: zap)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user