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
41 CustomerPlan::DB.expect(
42 :query_one,
43 EMPromise.resolve({ start_date: Time.now }),
44 [String, "test"]
45 )
46
47 cust = customer(sgx: sgx, plan_name: "test_usd")
48 assert cust.admin_info.sync.form
49 assert_mock sgx
50 end
51 em :test_admin_info_does_not_crash
52
53 def test_inactive_info_does_not_crash
54 sgx = Minitest::Mock.new
55 sgx.expect(:registered?, false)
56
57 plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
58 cust = Customer.new(
59 "test",
60 Blather::JID.new("test@example.net"),
61 plan: plan,
62 sgx: sgx
63 )
64 assert cust.info.sync.form
65 assert_mock sgx
66 end
67 em :test_inactive_info_does_not_crash
68
69 def test_inactive_admin_info_does_not_crash
70 sgx = Minitest::Mock.new
71 sgx.expect(:registered?, false)
72 sgx.expect(:fwd, CustomerFwd::None.new(uri: nil, timeout: nil))
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.form
83 assert_mock sgx
84 end
85 em :test_inactive_admin_info_does_not_crash
86
87 def test_missing_customer_admin_info_does_not_crash
88 cust = CustomerInfoForm::NoCustomer.new
89 assert cust.admin_info.form
90 end
91 em :test_missing_customer_admin_info_does_not_crash
92end