diff --git a/app/jobs/create_lndhub_wallet_job.rb b/app/jobs/create_lndhub_account_job.rb similarity index 60% rename from app/jobs/create_lndhub_wallet_job.rb rename to app/jobs/create_lndhub_account_job.rb index 30b4778..9cf33b1 100644 --- a/app/jobs/create_lndhub_wallet_job.rb +++ b/app/jobs/create_lndhub_account_job.rb @@ -1,11 +1,11 @@ -class CreateLndhubWalletJob < ApplicationJob +class CreateLndhubAccountJob < ApplicationJob queue_as :default def perform(user) return if user.ln_login.present? && user.ln_password.present? - lndhub = Lndhub.new - credentials = lndhub.create({ partnerid: user.ou, accounttype: "user" }) + lndhub = LndhubV2.new + credentials = lndhub.create_account user.update! ln_login: credentials["login"], ln_password: credentials["password"] diff --git a/app/services/create_account.rb b/app/services/create_account.rb index fac6442..f332a53 100644 --- a/app/services/create_account.rb +++ b/app/services/create_account.rb @@ -11,7 +11,7 @@ class CreateAccount < ApplicationService def call user = create_user_in_database add_ldap_document - create_lndhub_wallet(user) + create_lndhub_account(user) if @invitation.present? update_invitation(user.id) @@ -49,9 +49,9 @@ class CreateAccount < ApplicationService ExchangeXmppContactsJob.perform_later(@invitation.user, @username, @domain) end - def create_lndhub_wallet(user) + def create_lndhub_account(user) #TODO enable in development when we have a local lndhub (mock?) API return if Rails.env.development? - CreateLndhubWalletJob.perform_later(user) + CreateLndhubAccountJob.perform_later(user) end end diff --git a/app/services/lndhub_v2.rb b/app/services/lndhub_v2.rb index af5f3a9..bb4c4b9 100644 --- a/app/services/lndhub_v2.rb +++ b/app/services/lndhub_v2.rb @@ -70,7 +70,7 @@ class LndhubV2 # V2 # - def create_account(payload) + def create_account(payload={}) post "v2/users", payload, admin_token: Rails.application.credentials.lndhub[:admin_token] end diff --git a/config/credentials/test.yml.enc b/config/credentials/test.yml.enc index 5a1530a..dd9d846 100644 --- a/config/credentials/test.yml.enc +++ b/config/credentials/test.yml.enc @@ -1 +1 @@ -IIjYiPSeZeMFhH8i8v8akXN4JrtGU+OsMQ8GAao/gVdesggriCBAQ8z+Vd0cmTf1SKYeT3OQDgygEekupr325P4eD9fZ+yi56EA/UMXQXMDVZAvZw7iwvKaOXpqisbWdJnomr1GXrHyR415Ce/Fxft3fgXDwMHJW2u+dDJgpE09uORnB9GXycFwHQmoIdXo=--iQ/Vcm0VcwHgUkwQ--tKHQW/45gM/s/NplqGPaxw== \ No newline at end of file +vqH5By5qFLImVjdlWj+7FwGg8APKnr/AEd7WqekG7L0vNA32WGBpwS1uGzs02LIcATRwGj8DyJxiBOB/w9z8cwoO+t6Woi5hAnOSCQwFWKLT0dZq7jgtT8pxK0Yu/Nf91PEFN1rc/8ZFy2KKVpbtMbMPyivT38e/ctBZD/lHrWkndvLXYvFVhqWjUnDOGbhwl/U0RZgqBBjvlm3B0JkQfiN8VXPlCJL2Cd8kd0+MpRCRTgtcxA==--OdVXnDP7OhzJxCsP--+8SI6IFIeXyDxXb+WpqhIQ== \ No newline at end of file diff --git a/spec/jobs/create_lndhub_wallet_job_spec.rb b/spec/jobs/create_lndhub_account_job_spec.rb similarity index 83% rename from spec/jobs/create_lndhub_wallet_job_spec.rb rename to spec/jobs/create_lndhub_account_job_spec.rb index 4b64ba1..aa2d179 100644 --- a/spec/jobs/create_lndhub_wallet_job_spec.rb +++ b/spec/jobs/create_lndhub_account_job_spec.rb @@ -1,13 +1,13 @@ require 'rails_helper' require 'webmock/rspec' -RSpec.describe CreateLndhubWalletJob, type: :job do +RSpec.describe CreateLndhubAccountJob, type: :job do let(:user) { create :user, cn: "willherschel", ou: "kosmos.org" } subject(:job) { described_class.perform_later(user) } before do - stub_request(:post, "http://localhost:3023/create") + stub_request(:post, "http://localhost:3026/v2/users") .to_return(status: 200, headers: {}, body: { login: "abc123", password: "def456" }.to_json) end @@ -15,8 +15,8 @@ RSpec.describe CreateLndhubWalletJob, type: :job do it "creates a new LndHub account" do perform_enqueued_jobs { job } - expect(WebMock).to have_requested(:post, "http://localhost:3023/create") - .with { |req| req.body == '{"partnerid":"kosmos.org","accounttype":"user"}' } + expect(WebMock).to have_requested(:post, "http://localhost:3026/v2/users") + .with { |req| req.body == '{}' } user.reload expect(user.ln_login).to eq("abc123") diff --git a/spec/services/create_account_spec.rb b/spec/services/create_account_spec.rb index 0180b0d..9e35a2f 100644 --- a/spec/services/create_account_spec.rb +++ b/spec/services/create_account_spec.rb @@ -93,7 +93,7 @@ RSpec.describe CreateAccount, type: :model do end end - describe "#create_lndhub_wallet" do + describe "#create_lndhub_account" do include ActiveJob::TestHelper let(:service) { CreateAccount.new( @@ -102,8 +102,8 @@ RSpec.describe CreateAccount, type: :model do )} let(:new_user) { create :user, cn: "halfinney", ou: "kosmos.org" } - it "enqueues a job to create an LndHub wallet" do - service.send(:create_lndhub_wallet, new_user) + it "enqueues a job to create an LndHub account" do + service.send(:create_lndhub_account, new_user) expect(enqueued_jobs.size).to eq(1)