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