1# frozen_string_literal: true
2
3require "test_helper"
4
5API::REDIS = Minitest::Mock.new
6
7class CustomerInfoTest < Minitest::Test
8 def test_info_does_not_crash
9 sgx = Minitest::Mock.new
10 sgx.expect(:registered?, EMPromise.resolve(nil))
11
12 cust = customer(sgx: sgx)
13 assert cust.info.sync.fields
14 assert_mock sgx
15 end
16 em :test_info_does_not_crash
17
18 def test_admin_info_does_not_crash
19 sgx = Minitest::Mock.new
20 sgx.expect(:registered?, EMPromise.resolve(nil))
21
22 API::REDIS.expect(
23 :exists,
24 EMPromise.resolve(nil),
25 ["catapult_cred-customer_test@jmp.chat"]
26 )
27
28 API::REDIS.expect(
29 :lindex,
30 EMPromise.resolve(nil),
31 ["catapult_cred-test@example.net", 0]
32 )
33
34 cust = customer(sgx: sgx)
35 assert cust.admin_info.sync.fields
36 assert_mock sgx
37 end
38 em :test_admin_info_does_not_crash
39
40 def test_inactive_info_does_not_crash
41 sgx = Minitest::Mock.new
42 sgx.expect(:registered?, EMPromise.resolve(nil))
43
44 plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
45 cust = Customer.new(
46 "test",
47 Blather::JID.new("test@example.net"),
48 plan: plan,
49 sgx: sgx
50 )
51 assert cust.info.sync.fields
52 assert_mock sgx
53 end
54 em :test_inactive_info_does_not_crash
55
56 def test_inactive_admin_info_does_not_crash
57 sgx = Minitest::Mock.new
58 sgx.expect(:registered?, EMPromise.resolve(nil))
59
60 API::REDIS.expect(
61 :exists,
62 EMPromise.resolve(nil),
63 ["catapult_cred-customer_test@jmp.chat"]
64 )
65
66 API::REDIS.expect(
67 :lindex,
68 EMPromise.resolve(nil),
69 ["catapult_cred-test@example.net", 0]
70 )
71
72 plan = CustomerPlan.new("test", plan: nil, expires_at: nil)
73 cust = Customer.new(
74 "test",
75 Blather::JID.new("test@example.net"),
76 plan: plan,
77 sgx: sgx
78 )
79
80 assert cust.admin_info.sync.fields
81 assert_mock sgx
82 end
83 em :test_inactive_admin_info_does_not_crash
84
85 def test_legacy_customer_info_does_not_crash
86 cust = LegacyCustomer.new(
87 Blather::JID.new("legacy@example.com"),
88 "+12223334444"
89 )
90 assert cust.info.sync.fields
91 end
92 em :test_legacy_customer_info_does_not_crash
93
94 def test_legacy_customer_admin_info_does_not_crash
95 API::REDIS.expect(
96 :exists,
97 EMPromise.resolve(nil),
98 ["catapult_cred-customer_@jmp.chat"]
99 )
100
101 API::REDIS.expect(
102 :lindex,
103 EMPromise.resolve(nil),
104 ["catapult_cred-legacy@example.com", 0]
105 )
106
107 cust = LegacyCustomer.new(
108 Blather::JID.new("legacy@example.com"),
109 "+12223334444"
110 )
111 assert cust.admin_info.sync.fields
112 end
113 em :test_legacy_customer_admin_info_does_not_crash
114end