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
  8PlanInfo::DB = FakeDB.new(
  9	["test"] => [
 10		{
 11			"start_date" => Time.parse("2020-01-01"),
 12			"activation_date" => Time.parse("2021-01-01")
 13		}
 14	]
 15)
 16
 17class CustomerInfoTest < Minitest::Test
 18	def test_info_does_not_crash
 19		sgx = Minitest::Mock.new
 20		sgx.expect(:registered?, false)
 21		sgx.expect(:registered?, false)
 22
 23		CustomerPlan::REDIS.expect(
 24			:get,
 25			EMPromise.resolve(nil),
 26			["jmp_customer_auto_top_up_amount-test"]
 27		)
 28
 29		CustomerPlan::DB.expect(
 30			:query_defer,
 31			EMPromise.resolve([{ "start_date" => Time.now }]),
 32			[String, ["test"]]
 33		)
 34
 35		cust = customer(sgx: sgx, plan_name: "test_usd")
 36
 37		assert cust.info.sync.form
 38		assert_mock sgx
 39	end
 40	em :test_info_does_not_crash
 41
 42	def test_admin_info_does_not_crash
 43		sgx = Minitest::Mock.new
 44		sgx.expect(:registered?, false)
 45		sgx.expect(:registered?, false)
 46		fwd = CustomerFwd.for(uri: "tel:+12223334444", timeout: 15)
 47		sgx.expect(:fwd, fwd)
 48
 49		CustomerPlan::REDIS.expect(
 50			:get,
 51			EMPromise.resolve(nil),
 52			["jmp_customer_auto_top_up_amount-test"]
 53		)
 54
 55		CustomerPlan::DB.expect(
 56			:query_defer,
 57			EMPromise.resolve([{ "start_date" => Time.now }]),
 58			[String, ["test"]]
 59		)
 60
 61		cust = customer(sgx: sgx, plan_name: "test_usd")
 62		assert cust.admin_info.sync.form
 63		assert_mock sgx
 64	end
 65	em :test_admin_info_does_not_crash
 66
 67	def test_inactive_info_does_not_crash
 68		sgx = Minitest::Mock.new
 69		sgx.expect(:registered?, false)
 70		sgx.expect(:registered?, false)
 71
 72		plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
 73		cust = Customer.new(
 74			"test",
 75			Blather::JID.new("test@example.net"),
 76			plan: plan,
 77			sgx: sgx
 78		)
 79		assert cust.info.sync.form
 80		assert_mock sgx
 81	end
 82	em :test_inactive_info_does_not_crash
 83
 84	def test_inactive_admin_info_does_not_crash
 85		sgx = Minitest::Mock.new
 86		sgx.expect(:registered?, false)
 87		sgx.expect(:registered?, false)
 88		sgx.expect(:fwd, CustomerFwd::None.new(uri: nil, timeout: nil))
 89
 90		plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
 91		cust = Customer.new(
 92			"test",
 93			Blather::JID.new("test@example.net"),
 94			plan: plan,
 95			sgx: sgx
 96		)
 97
 98		assert cust.admin_info.sync.form
 99		assert_mock sgx
100	end
101	em :test_inactive_admin_info_does_not_crash
102
103	def test_missing_customer_admin_info_does_not_crash
104		cust = CustomerInfoForm::NoCustomer.new
105		assert cust.admin_info.form
106	end
107	em :test_missing_customer_admin_info_does_not_crash
108end