WIP Persist zaps, create and send zap receipts
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
2024-05-09 14:31:37 +02:00
parent c0f4e7925e
commit c6c5d80fb4
17 changed files with 242 additions and 37 deletions

View 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

View 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