test_customer_info.rb

  1# frozen_string_literal: true
  2
  3require "test_helper"
  4require "customer_info"
  5
  6API::REDIS = FakeRedis.new
  7CustomerPlan::REDIS = Minitest::Mock.new
  8
  9class CustomerInfoTest < Minitest::Test
 10	def test_info_does_not_crash
 11		sgx = Minitest::Mock.new
 12		sgx.expect(:registered?, false)
 13		sgx.expect(:registered?, false)
 14
 15		CustomerPlan::REDIS.expect(
 16			:get,
 17			EMPromise.resolve(nil),
 18			["jmp_customer_auto_top_up_amount-test"]
 19		)
 20
 21		cust = customer(sgx: sgx)
 22		assert cust.info.sync.fields
 23		assert_mock sgx
 24	end
 25	em :test_info_does_not_crash
 26
 27	def test_admin_info_does_not_crash
 28		sgx = Minitest::Mock.new
 29		sgx.expect(:registered?, false)
 30		sgx.expect(:registered?, false)
 31
 32		CustomerPlan::REDIS.expect(
 33			:get,
 34			EMPromise.resolve(nil),
 35			["jmp_customer_auto_top_up_amount-test"]
 36		)
 37
 38		cust = customer(sgx: sgx)
 39		assert cust.admin_info.sync.fields
 40		assert_mock sgx
 41	end
 42	em :test_admin_info_does_not_crash
 43
 44	def test_inactive_info_does_not_crash
 45		sgx = Minitest::Mock.new
 46		sgx.expect(:registered?, false)
 47		sgx.expect(:registered?, false)
 48
 49		CustomerPlan::REDIS.expect(
 50			:get,
 51			EMPromise.resolve(nil),
 52			["jmp_customer_auto_top_up_amount-test"]
 53		)
 54
 55		plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
 56		cust = Customer.new(
 57			"test",
 58			Blather::JID.new("test@example.net"),
 59			plan: plan,
 60			sgx: sgx
 61		)
 62		assert cust.info.sync.fields
 63		assert_mock sgx
 64	end
 65	em :test_inactive_info_does_not_crash
 66
 67	def test_inactive_admin_info_does_not_crash
 68		sgx = Minitest::Mock.new
 69		sgx.expect(:registered?, false)
 70		sgx.expect(:registered?, false)
 71
 72		CustomerPlan::REDIS.expect(
 73			:get,
 74			EMPromise.resolve(nil),
 75			["jmp_customer_auto_top_up_amount-test"]
 76		)
 77
 78		plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
 79		cust = Customer.new(
 80			"test",
 81			Blather::JID.new("test@example.net"),
 82			plan: plan,
 83			sgx: sgx
 84		)
 85
 86		assert cust.admin_info.sync.fields
 87		assert_mock sgx
 88	end
 89	em :test_inactive_admin_info_does_not_crash
 90
 91	def test_legacy_customer_info_does_not_crash
 92		cust = LegacyCustomer.new(
 93			Blather::JID.new("legacy@example.com"),
 94			"+12223334444"
 95		)
 96		assert cust.info.sync.fields
 97	end
 98	em :test_legacy_customer_info_does_not_crash
 99
100	def test_legacy_customer_admin_info_does_not_crash
101		cust = LegacyCustomer.new(
102			Blather::JID.new("legacy@example.com"),
103			"+12223334444"
104		)
105		assert cust.admin_info.sync.fields
106	end
107	em :test_legacy_customer_admin_info_does_not_crash
108end