WIP Verify and respond to zap requests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe "/lnurlpay", type: :request do
|
||||
|
||||
context "Non-existent user" do
|
||||
describe "GET /.well-known/lnurlpay/:username" do
|
||||
describe "GET /.well-known/lnurlp/:username" do
|
||||
it "returns a 404" do
|
||||
get lightning_address_path(username: "csw")
|
||||
expect(response).to have_http_status(:not_found)
|
||||
@@ -32,7 +31,7 @@ RSpec.describe "/lnurlpay", type: :request do
|
||||
login_as user, :scope => :user
|
||||
end
|
||||
|
||||
describe "GET /.well-known/lnurlpay/:username" do
|
||||
describe "GET /.well-known/lnurlp/:username" do
|
||||
it "returns a formatted Lightning Address response" do
|
||||
get lightning_address_path(username: "satoshi")
|
||||
|
||||
@@ -67,29 +66,83 @@ RSpec.describe "/lnurlpay", type: :request do
|
||||
expect(res["pr"]).to eq("lnbc50u1p3lwgknpp52g78gqya5euvzjc53fc6hkmlm2rfjhcd305tcmc0g9gaestav48sdq4gdhkven9v5sx6mmwv4ujzcqzpgxqyz5vqsp5skkz4jlqr6tkvv2g9739ygrjupc4rkqd94mc7dfpj3pgx3f6w7qs9qyyssq7mf3fzcuxlmkr9nqatcch3u8uf4gjyawe052tejz8e9fqxu4pncqk3qklt8g6ylpshg09xyjquyrgtc72vcw5cp0dzcf406apyua7dgpnfn7an")
|
||||
end
|
||||
|
||||
context "amount too low" do
|
||||
describe "amount too low" do
|
||||
it "returns an error" do
|
||||
get lnurlpay_invoice_path(username: "satoshi", params: {
|
||||
amount: 5000, comment: "Coffee time!"
|
||||
})
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
res = JSON.parse(response.body)
|
||||
expect(res["status"]).to eq('ERROR')
|
||||
expect(res["reason"]).to eq('Invalid amount')
|
||||
end
|
||||
end
|
||||
|
||||
context "comment too long" do
|
||||
describe "comment too long" do
|
||||
it "returns an error" do
|
||||
get lnurlpay_invoice_path(username: "satoshi", params: {
|
||||
amount: 5000000, comment: "Coffee time is the best time, so here's some money for you to get some. May I suggest to sample some Pacamara beans from El Salvador?"
|
||||
})
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
res = JSON.parse(response.body)
|
||||
expect(res["status"]).to eq('ERROR')
|
||||
expect(res["reason"]).to eq('Comment too long')
|
||||
end
|
||||
end
|
||||
|
||||
context "zap request" do
|
||||
describe "with invalid request event" do
|
||||
it "returns an error" do
|
||||
get lnurlpay_invoice_path(username: "satoshi", params: {
|
||||
amount: 2100000, nostr: { foo: "bar" }.to_json
|
||||
})
|
||||
|
||||
res = JSON.parse(response.body)
|
||||
expect(res["status"]).to eq('ERROR')
|
||||
expect(res["reason"]).to eq('Invalid zap request')
|
||||
end
|
||||
end
|
||||
|
||||
describe "with valid request event" do
|
||||
let(:event) {
|
||||
{
|
||||
id: "3cf02d7f0ccd9711c25098fc50b3a7ab880326e4e51cc8c7a7b59f147cff4fff",
|
||||
pubkey: "730b43e6f62c2ab22710b046e481802c8ac1108ed2cb9c21dff808d57ba24b6c",
|
||||
created_at: 1712487443,
|
||||
kind: 9734,
|
||||
tags: [
|
||||
["relays", "wss://nostr.kosmos.org", "wss://relay.example.com"],
|
||||
["p", "07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3"]],
|
||||
content: "",
|
||||
sig: "e9e9bb2bac4267a107ab5c3368f504b4f11b8e3b5ae875a1d63c74d6934138d2521dc35815b6f534fc5d803cbf633736d871886368bb8f92c4ad3837a68a06f2"
|
||||
}
|
||||
}
|
||||
|
||||
it "returns an invoice" do
|
||||
expect_any_instance_of(User).to receive(:ln_create_invoice)
|
||||
.with(
|
||||
amount: 2100,
|
||||
memo: "Zapped satoshi@kosmos.org on Nostr",
|
||||
description_hash: "540279cd9da15279c8299d6d9ff1ab2a79eb259ee218adf3de393e1abe723077"
|
||||
)
|
||||
.and_return("lnbc50u1p3lwgknpp52g78gqya5euvzjc53fc6hkmlm2rfjhcd305tcmc0g9gaestav48sdq4gdhkven9v5sx6mmwv4ujzcqzpgxqyz5vqsp5skkz4jlqr6tkvv2g9739ygrjupc4rkqd94mc7dfpj3pgx3f6w7qs9qyyssq7mf3fzcuxlmkr9nqatcch3u8uf4gjyawe052tejz8e9fqxu4pncqk3qklt8g6ylpshg09xyjquyrgtc72vcw5cp0dzcf406apyua7dgpnfn7an")
|
||||
|
||||
get lnurlpay_invoice_path(username: "satoshi", params: {
|
||||
amount: 2100000, nostr: event.to_json
|
||||
})
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
res = JSON.parse(response.body)
|
||||
expect(res["status"]).to eq('OK')
|
||||
expect(res["pr"]).to match(/^lnbc/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /.well-known/keysend/:username/" do
|
||||
|
||||
Reference in New Issue
Block a user