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