# frozen_string_literal: true require "test_helper" require "customer_info" API::REDIS = FakeRedis.new CustomerPlan::REDIS = Minitest::Mock.new class CustomerInfoTest < Minitest::Test def test_info_does_not_crash sgx = Minitest::Mock.new sgx.expect(:registered?, false) sgx.expect(:registered?, false) CustomerPlan::REDIS.expect( :get, EMPromise.resolve(nil), ["jmp_customer_auto_top_up_amount-test"] ) cust = customer(sgx: sgx) assert cust.info.sync.fields assert_mock sgx end em :test_info_does_not_crash def test_admin_info_does_not_crash sgx = Minitest::Mock.new sgx.expect(:registered?, false) sgx.expect(:registered?, false) CustomerPlan::REDIS.expect( :get, EMPromise.resolve(nil), ["jmp_customer_auto_top_up_amount-test"] ) cust = customer(sgx: sgx) assert cust.admin_info.sync.fields assert_mock sgx end em :test_admin_info_does_not_crash def test_inactive_info_does_not_crash sgx = Minitest::Mock.new sgx.expect(:registered?, false) sgx.expect(:registered?, false) CustomerPlan::REDIS.expect( :get, EMPromise.resolve(nil), ["jmp_customer_auto_top_up_amount-test"] ) plan = CustomerPlan.new("test", plan: nil, expires_at: nil) cust = Customer.new( "test", Blather::JID.new("test@example.net"), plan: plan, sgx: sgx ) assert cust.info.sync.fields assert_mock sgx end em :test_inactive_info_does_not_crash def test_inactive_admin_info_does_not_crash sgx = Minitest::Mock.new sgx.expect(:registered?, false) sgx.expect(:registered?, false) CustomerPlan::REDIS.expect( :get, EMPromise.resolve(nil), ["jmp_customer_auto_top_up_amount-test"] ) plan = CustomerPlan.new("test", plan: nil, expires_at: nil) cust = Customer.new( "test", Blather::JID.new("test@example.net"), plan: plan, sgx: sgx ) assert cust.admin_info.sync.fields assert_mock sgx end em :test_inactive_admin_info_does_not_crash def test_legacy_customer_info_does_not_crash cust = LegacyCustomer.new( Blather::JID.new("legacy@example.com"), "+12223334444" ) assert cust.info.sync.fields end em :test_legacy_customer_info_does_not_crash def test_legacy_customer_admin_info_does_not_crash cust = LegacyCustomer.new( Blather::JID.new("legacy@example.com"), "+12223334444" ) assert cust.admin_info.sync.fields end em :test_legacy_customer_admin_info_does_not_crash end