Add specs for lndhub webhook
This commit is contained in:
@@ -10,11 +10,68 @@ RSpec.describe "Webhooks", type: :request do
|
||||
end
|
||||
|
||||
context "IP allowed" do
|
||||
it "returns a 403 status" do
|
||||
before do
|
||||
ENV['WEBHOOKS_ALLOWED_IPS'] = '127.0.0.1'
|
||||
end
|
||||
|
||||
it "does not return a 403 status" do
|
||||
post "/webhooks/lndhub"
|
||||
expect(response).not_to have_http_status(:forbidden)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Webhooks from lndhub.go
|
||||
describe "/webhooks/lndhub" do
|
||||
before do
|
||||
ENV['WEBHOOKS_ALLOWED_IPS'] = '127.0.0.1'
|
||||
end
|
||||
|
||||
describe "Payload cannot be processed as JSON" do
|
||||
before do
|
||||
post "/webhooks/lndhub", params: "Foo"
|
||||
end
|
||||
|
||||
it "returns a 422 status" do
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Valid payload for outgoing payment" do
|
||||
let(:payload) { JSON.parse(File.read(File.expand_path("../fixtures/lndhub/outgoing.json", File.dirname(__FILE__)))) }
|
||||
|
||||
before do
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
end
|
||||
|
||||
it "returns a 204 status" do
|
||||
expect(response).to have_http_status(:no_content)
|
||||
end
|
||||
end
|
||||
|
||||
describe "Valid payload for incoming payment" do
|
||||
let(:user) { create :user, ln_account: "123456abcdef" }
|
||||
let(:payload) { JSON.parse(File.read(File.expand_path("../fixtures/lndhub/incoming.json", File.dirname(__FILE__)))) }
|
||||
|
||||
before do
|
||||
user.save! #FIXME this should not be necessary
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
end
|
||||
|
||||
it "returns a 200 status" do
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it "sends an XMPP message to the account owner's JID" do
|
||||
expect(enqueued_jobs.size).to eq(1)
|
||||
|
||||
msg = enqueued_jobs.first['arguments'].first
|
||||
expect(msg["type"]).to eq('normal')
|
||||
expect(msg["from"]).to eq('kosmos.org')
|
||||
expect(msg["to"]).to eq(user.address)
|
||||
expect(msg["subject"]).to eq('Sats received!')
|
||||
expect(msg["body"]).to match(/^12300 sats received/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user