~singpolyma/sgx-jmp

ref: fea0ffeb22d0f229d528b30f3844c425b5009ad9 sgx-jmp/test/test_backend_sgx.rb -rw-r--r-- 1.5 KiB
fea0ffebStephen Paul Weber Merge branch 'no-more-catapult' 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true

require "test_helper"
require "bwmsgsv2_repo"
require "backend_sgx"
require "trivial_backend_sgx_repo"

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

class BackendSgxTest < Minitest::Test
	def test_registered
		Bwmsgsv2Repo::IQ_MANAGER.expect(
			:write,
			EMPromise.resolve(IBR.new.tap { |ibr| ibr.registered = true }),
			[Matching.new do |ibr|
				assert_equal :get, ibr.type
				assert_equal "customer_test@component", ibr.from.to_s
			end]
		)
		sgx = Bwmsgsv2Repo.new(redis: FakeRedis.new).get("test").sync
		assert sgx.registered?
	end
	em :test_registered

	def test_registered_not_registered
		Bwmsgsv2Repo::IQ_MANAGER.expect(
			:write,
			EMPromise.resolve(IBR.new.tap { |ibr| ibr.registered = false }),
			[Matching.new do |ibr|
				assert_equal :get, ibr.type
				assert_equal "customer_test@component", ibr.from.to_s
			end]
		)
		sgx = Bwmsgsv2Repo.new(redis: FakeRedis.new).get("test").sync
		refute sgx.registered?
	end
	em :test_registered_not_registered

	def test_register!
		BackendSgx::IQ_MANAGER.expect(
			:write,
			EMPromise.resolve(OpenStruct.new(error?: false)),
			[Matching.new do |ibr|
				assert_equal "customer_test@component", ibr.from.to_s
				assert_equal "test_bw_account", ibr.nick
				assert_equal "test_bw_user", ibr.username
				assert_equal "test_bw_password", ibr.password
				assert_equal "+15555550000", ibr.phone
			end]
		)
		sgx = TrivialBackendSgxRepo.new.get("test")
		sgx.register!("+15555550000")
		BackendSgx::IQ_MANAGER.verify
	end
end