Merge pull request 'Add user preferences and configurable notifications' (#113) from feature/user_preferences into master
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #113 Reviewed-by: galfert <garret.alfert@gmail.com>
This commit was merged in pull request #113.
This commit is contained in:
@@ -55,22 +55,51 @@ RSpec.describe "Webhooks", type: :request do
|
||||
|
||||
before do
|
||||
user.save! #FIXME this should not be necessary
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
end
|
||||
|
||||
it "returns a 200 status" do
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
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)
|
||||
it "does not send notifications by default" do
|
||||
expect(enqueued_jobs.size).to eq(0)
|
||||
end
|
||||
|
||||
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/)
|
||||
context "notification preference set to 'xmpp'" do
|
||||
before do
|
||||
user.update! preferences: { lightning_notify_sats_received: "xmpp" }
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
end
|
||||
|
||||
it "sends an XMPP message to the account owner's JID" do
|
||||
expect(enqueued_jobs.size).to eq(1)
|
||||
expect(enqueued_jobs.first["job_class"]).to eq("XmppSendMessageJob")
|
||||
|
||||
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(/^12,300 sats received/)
|
||||
end
|
||||
end
|
||||
|
||||
context "notification preference set to 'email'" do
|
||||
before do
|
||||
user.update! preferences: { lightning_notify_sats_received: "email" }
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
end
|
||||
|
||||
it "sends an email notification to the account owner" do
|
||||
expect(enqueued_jobs.size).to eq(1)
|
||||
expect(enqueued_jobs.first["job_class"]).to eq("ActionMailer::MailDeliveryJob")
|
||||
args = enqueued_jobs.first['arguments']
|
||||
expect(args[0]).to eq("NotificationMailer")
|
||||
expect(args[1]).to eq("lightning_sats_received")
|
||||
expect(args[3]["params"]["user"]["_aj_globalid"]).to eq("gid://akkounts/User/1")
|
||||
expect(args[3]["params"]["amount_sats"]).to eq(12300)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user