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