~singpolyma/sgx-jmp

236df825ed4353baba20050004785fe42c6d2683 — Stephen Paul Weber 3 months ago 4b11837
Split out IBRRepo
3 files changed, 37 insertions(+), 15 deletions(-)

M lib/bwmsgsv2_repo.rb
A lib/ibr_repo.rb
M test/test_backend_sgx.rb
M lib/bwmsgsv2_repo.rb => lib/bwmsgsv2_repo.rb +9 -12
@@ 3,15 3,21 @@
require "lazy_object"

require_relative "customer_fwd"
require_relative "ibr"
require_relative "ibr_repo"
require_relative "trivial_backend_sgx_repo"

class Bwmsgsv2Repo
	VOICEMAIL_TRANSCRIPTION_DISABLED = 0

	def initialize(jid: CONFIG[:sgx], redis: LazyObject.new { REDIS }, **kwargs)
	def initialize(
		jid: CONFIG[:sgx],
		redis: LazyObject.new { REDIS },
		ibr_repo: IBRRepo.new,
		**kwargs
	)
		@jid = jid
		@redis = redis
		@ibr_repo = ibr_repo
		@trivial_repo = TrivialBackendSgxRepo.new(jid: jid, **kwargs)
	end



@@ 74,16 80,7 @@ protected
	end

	def registration(from_jid)
		ibr = IBR.new(:get, @jid)
		ibr.from = from_jid

		IQ_MANAGER.write(ibr).catch { nil }.then do |result|
			if result.respond_to?(:registered?) && result.registered?
				result
			else
				false
			end
		end
		@ibr_repo.registered?(@jid, from: from_jid)
	end

	def from_redis(from_jid, tel)

A lib/ibr_repo.rb => lib/ibr_repo.rb +25 -0
@@ 0,0 1,25 @@
# frozen_string_literal: true

require "lazy_object"
require "value_semantics/monkey_patched"

require_relative "ibr"

class IBRRepo
	value_semantics do
		iq_manager Anything(), default: LazyObject.new { IQ_MANAGER }
	end

	def registered?(jid, from:)
		ibr = IBR.new(:get, jid)
		ibr.from = from

		iq_manager.write(ibr).catch { nil }.then do |result|
			if result.respond_to?(:registered?) && result.registered?
				result
			else
				false
			end
		end
	end
end

M test/test_backend_sgx.rb => test/test_backend_sgx.rb +3 -3
@@ 6,11 6,11 @@ require "backend_sgx"
require "trivial_backend_sgx_repo"

BackendSgx::IQ_MANAGER = Minitest::Mock.new
Bwmsgsv2Repo::IQ_MANAGER = Minitest::Mock.new
IBRRepo::IQ_MANAGER = Minitest::Mock.new

class BackendSgxTest < Minitest::Test
	def test_registered
		Bwmsgsv2Repo::IQ_MANAGER.expect(
		IBRRepo::IQ_MANAGER.expect(
			:write,
			EMPromise.resolve(IBR.new.tap { |ibr| ibr.registered = true }),
			[Matching.new do |ibr|


@@ 24,7 24,7 @@ class BackendSgxTest < Minitest::Test
	em :test_registered

	def test_registered_not_registered
		Bwmsgsv2Repo::IQ_MANAGER.expect(
		IBRRepo::IQ_MANAGER.expect(
			:write,
			EMPromise.resolve(IBR.new.tap { |ibr| ibr.registered = false }),
			[Matching.new do |ibr|