diff --git a/lib/registration.rb b/lib/registration.rb index 3c7b00c2983a54379f11ed25a9bd0ea89bf30006..12466d3cbaf2409ada01ba4e13a397b80c899ec8 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -539,10 +539,11 @@ class Registration end class Snikket - def initialize(customer, tel, error: nil) + def initialize(customer, tel, error: nil, db: LazyObject.new { DB }) @customer = customer @tel = tel @error = error + @db = db end ACTION_VAR = "http://jabber.org/protocol/commands#actions" @@ -572,9 +573,7 @@ class Registration IQ_MANAGER.write(::Snikket::Launch.new( nil, CONFIG[:snikket_hosting_api], domain: domain )).then { |launched| - GetInvite.for( - ::Snikket::CustomerInstance.for(@customer, domain, launched) - ).then(&:write) + save_instance_and_wait(domain, launched) }.catch { |e| next EMPromise.reject(e) unless e.respond_to?(:text) @@ -582,6 +581,13 @@ class Registration } end + def save_instance_and_wait(domain, launched) + instance = ::Snikket::CustomerInstance.for(@customer, domain, launched) + ::Snikket::Repo.new(db: @db).put(instance).then do + GetInvite.for(instance).then(&:write) + end + end + class GetInvite def self.for(instance) instance.fetch_invite.then do |xmpp_uri| diff --git a/lib/snikket.rb b/lib/snikket.rb index cfcfa3ca33625dfba1bdb197df3f0e9a5a905605..50e1d137bbf2bc081272eb47f52847ebafb76ac0 100644 --- a/lib/snikket.rb +++ b/lib/snikket.rb @@ -138,7 +138,7 @@ module Snikket end class Repo - def initialize(db: DB) + def initialize(db: LazyObject.new { DB }) @db = db end diff --git a/test/test_helper.rb b/test/test_helper.rb index be130085d6b42f80758333b9ce6ad6575cc382a1..7aae1a144134f4a704fb145e839df03e8cc10041 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -309,6 +309,10 @@ class FakeDB row = row.transform_keys(&:to_sym) if row && field_names_as == :symbol EMPromise.resolve(row || default) end + + def exec(_, _) + EMPromise.resolve(nil) + end end class FakeLog diff --git a/test/test_registration.rb b/test/test_registration.rb index a344741a554ff501e5bc2c445ed04847d302e84c..7fd2463ceb89920b64d0b3ffc737d83c5835ade5 100644 --- a/test/test_registration.rb +++ b/test/test_registration.rb @@ -948,7 +948,8 @@ class RegistrationTest < Minitest::Test @sgx = Minitest::Mock.new(TrivialBackendSgxRepo.new.get("test")) @snikket = Registration::FinishOnboarding::Snikket.new( customer, - "+15555550000" + "+15555550000", + db: FakeDB.new ) end