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
22		CustomerPlan::DB.expect(
23			:query_one,
24			EMPromise.resolve({ start_date: Time.now }),
25			[String, "test"]
26		)
27
28		cust = customer(sgx: sgx, plan_name: "test_usd")
29
30		assert cust.info.sync.form
31		assert_mock sgx
32	end
33	em :test_info_does_not_crash
34
35	def test_admin_info_does_not_crash
36		sgx = Minitest::Mock.new
37		sgx.expect(:registered?, false)
38		fwd = CustomerFwd.for(uri: "tel:+12223334444", timeout: 15)
39		sgx.expect(:fwd, fwd)
40		sgx.expect(:registered?, false)
41
42		CustomerPlan::DB.expect(
43			:query_one,
44			EMPromise.resolve({ start_date: Time.now }),
45			[String, "test"]
46		)
47
48		cust = customer(sgx: sgx, plan_name: "test_usd")
49		assert cust.admin_info.sync.form
50		assert_mock sgx
51	end
52	em :test_admin_info_does_not_crash
53
54	def test_inactive_info_does_not_crash
55		sgx = Minitest::Mock.new
56		sgx.expect(:registered?, false)
57
58		plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
59		cust = Customer.new(
60			"test",
61			Blather::JID.new("test@example.net"),
62			plan: plan,
63			sgx: sgx
64		)
65		assert cust.info.sync.form
66		assert_mock sgx
67	end
68	em :test_inactive_info_does_not_crash
69
70	def test_inactive_admin_info_does_not_crash
71		sgx = Minitest::Mock.new
72		sgx.expect(:registered?, false)
73		sgx.expect(:registered?, false)
74		sgx.expect(:fwd, CustomerFwd::None.new(uri: nil, timeout: nil))
75
76		plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
77		cust = Customer.new(
78			"test",
79			Blather::JID.new("test@example.net"),
80			plan: plan,
81			sgx: sgx
82		)
83
84		assert cust.admin_info.sync.form
85		assert_mock sgx
86	end
87	em :test_inactive_admin_info_does_not_crash
88
89	def test_missing_customer_admin_info_does_not_crash
90		cust = CustomerInfoForm::NoCustomer.new
91		assert cust.admin_info.form
92	end
93	em :test_missing_customer_admin_info_does_not_crash
94end