1
1
import json
2
2
3
+ from cc_common .exceptions import CCInternalException
3
4
from moto import mock_aws
4
5
5
6
from .. import TstFunction
@@ -16,10 +17,13 @@ class TestGetPurchasePrivilegeOptions(TstFunction):
16
17
def _when_testing_provider_user_event_with_custom_claims (self , test_compact = TEST_COMPACT ):
17
18
self .test_data_generator .put_default_compact_configuration_in_configuration_table (
18
19
value_overrides = {
20
+ 'configuredStates' : [
21
+ {'postalAbbreviation' : 'ky' , 'isLive' : True } # Make Kentucky live
22
+ ],
19
23
'paymentProcessorPublicFields' : {
20
24
'publicClientKey' : MOCK_PUBLIC_CLIENT_KEY ,
21
25
'apiLoginId' : MOCK_API_LOGIN_ID ,
22
- }
26
+ },
23
27
}
24
28
)
25
29
self .test_data_generator .put_default_jurisdiction_configuration_in_configuration_table ()
@@ -36,6 +40,20 @@ def test_get_purchase_privilege_options_returns_expected_jurisdiction_option(sel
36
40
37
41
event = self ._when_testing_provider_user_event_with_custom_claims ()
38
42
43
+ # Set up compact configuration with mixed live statuses
44
+ self .test_data_generator .put_default_compact_configuration_in_configuration_table (
45
+ value_overrides = {
46
+ 'configuredStates' : [
47
+ {'postalAbbreviation' : 'ky' , 'isLive' : True }, # Live
48
+ {'postalAbbreviation' : 'oh' , 'isLive' : False }, # Not live
49
+ ],
50
+ 'paymentProcessorPublicFields' : {
51
+ 'publicClientKey' : MOCK_PUBLIC_CLIENT_KEY ,
52
+ 'apiLoginId' : MOCK_API_LOGIN_ID ,
53
+ },
54
+ }
55
+ )
56
+
39
57
resp = get_purchase_privilege_options (event , self .mock_context )
40
58
41
59
self .assertEqual (200 , resp ['statusCode' ])
@@ -111,28 +129,76 @@ def test_get_purchase_privilege_options_returns_400_if_api_call_made_without_pro
111
129
112
130
self .assertEqual (400 , resp ['statusCode' ])
113
131
114
- def test_get_purchase_privilege_options_returns_empty_list_if_user_compact_do_not_match_any_option_in_db (self ):
132
+ def test_get_purchase_privilege_options_filters_out_jurisdictions_with_licensee_registration_disabled (self ):
115
133
from handlers .privileges import get_purchase_privilege_options
116
134
117
- event = self ._when_testing_provider_user_event_with_custom_claims (test_compact = 'some-compact' )
135
+ event = self ._when_testing_provider_user_event_with_custom_claims ()
136
+
137
+ # Set up compact configuration. In this case, because ohio has not elected to go live, it does not show up
138
+ # in the list of configured states
139
+ self .test_data_generator .put_default_compact_configuration_in_configuration_table (
140
+ value_overrides = {
141
+ 'configuredStates' : [
142
+ {'postalAbbreviation' : 'ky' , 'isLive' : True } # Make Kentucky live
143
+ ],
144
+ 'paymentProcessorPublicFields' : {
145
+ 'publicClientKey' : MOCK_PUBLIC_CLIENT_KEY ,
146
+ 'apiLoginId' : MOCK_API_LOGIN_ID ,
147
+ },
148
+ }
149
+ )
150
+
151
+ # Create jurisdiction with licenseeRegistrationEnabled = True
152
+ self .test_data_generator .put_default_jurisdiction_configuration_in_configuration_table (
153
+ value_overrides = {
154
+ 'postalAbbreviation' : 'ky' ,
155
+ 'jurisdictionName' : 'Kentucky' ,
156
+ 'licenseeRegistrationEnabled' : True ,
157
+ }
158
+ )
159
+
160
+ # Create jurisdiction with licenseeRegistrationEnabled = False
161
+ self .test_data_generator .put_default_jurisdiction_configuration_in_configuration_table (
162
+ value_overrides = {
163
+ 'postalAbbreviation' : 'oh' ,
164
+ 'jurisdictionName' : 'Ohio' ,
165
+ 'licenseeRegistrationEnabled' : False ,
166
+ }
167
+ )
168
+
169
+ self ._load_provider_data ()
118
170
119
171
resp = get_purchase_privilege_options (event , self .mock_context )
120
172
121
173
self .assertEqual (200 , resp ['statusCode' ])
122
174
privilege_options = json .loads (resp ['body' ])
123
175
124
- self .assertEqual ([], privilege_options ['items' ])
176
+ # ensure the compact and privilege were returned
177
+ self .assertEqual (2 , len (privilege_options ['items' ]))
125
178
126
- def test_get_purchase_privilege_options_filters_out_jurisdictions_with_licensee_registration_disabled (self ):
179
+ # Filter to only jurisdiction options
180
+ jurisdiction_options = [option for option in privilege_options ['items' ] if option ['type' ] == 'jurisdiction' ]
181
+
182
+ # Should only return the jurisdiction with licenseeRegistrationEnabled = True
183
+ self .assertEqual (1 , len (jurisdiction_options ))
184
+ returned_jurisdiction = jurisdiction_options [0 ]
185
+ self .assertEqual ('ky' , returned_jurisdiction ['postalAbbreviation' ])
186
+ self .assertEqual ('Kentucky' , returned_jurisdiction ['jurisdictionName' ])
187
+
188
+ def test_get_purchase_privilege_options_raises_exception_if_no_live_configured_states (self ):
189
+ """Test that jurisdictions not in configuredStates are filtered out."""
127
190
from handlers .privileges import get_purchase_privilege_options
128
191
129
- # Set up compact configuration
192
+ event = self ._when_testing_provider_user_event_with_custom_claims ()
193
+
194
+ # Set up compact configuration with empty configuredStates
130
195
self .test_data_generator .put_default_compact_configuration_in_configuration_table (
131
196
value_overrides = {
197
+ 'configuredStates' : [], # Empty configuredStates
132
198
'paymentProcessorPublicFields' : {
133
199
'publicClientKey' : MOCK_PUBLIC_CLIENT_KEY ,
134
200
'apiLoginId' : MOCK_API_LOGIN_ID ,
135
- }
201
+ },
136
202
}
137
203
)
138
204
@@ -145,32 +211,62 @@ def test_get_purchase_privilege_options_filters_out_jurisdictions_with_licensee_
145
211
}
146
212
)
147
213
148
- # Create jurisdiction with licenseeRegistrationEnabled = False
214
+ with self .assertRaises (CCInternalException ):
215
+ get_purchase_privilege_options (event , self .mock_context )
216
+
217
+ def test_get_purchase_privilege_options_includes_live_jurisdictions_in_configured_states (self ):
218
+ """Test that only jurisdictions with isLive=true are included."""
219
+ from handlers .privileges import get_purchase_privilege_options
220
+
221
+ event = self ._when_testing_provider_user_event_with_custom_claims ()
222
+
223
+ # Set up compact configuration with mixed live statuses
224
+ self .test_data_generator .put_default_compact_configuration_in_configuration_table (
225
+ value_overrides = {
226
+ 'configuredStates' : [
227
+ {'postalAbbreviation' : 'ky' , 'isLive' : True }, # Live
228
+ {'postalAbbreviation' : 'oh' , 'isLive' : False }, # Not live
229
+ ],
230
+ 'paymentProcessorPublicFields' : {
231
+ 'publicClientKey' : MOCK_PUBLIC_CLIENT_KEY ,
232
+ 'apiLoginId' : MOCK_API_LOGIN_ID ,
233
+ },
234
+ }
235
+ )
236
+
237
+ # Create both jurisdictions with licenseeRegistrationEnabled = True
238
+ self .test_data_generator .put_default_jurisdiction_configuration_in_configuration_table (
239
+ value_overrides = {
240
+ 'postalAbbreviation' : 'ky' ,
241
+ 'jurisdictionName' : 'Kentucky' ,
242
+ 'licenseeRegistrationEnabled' : True ,
243
+ }
244
+ )
245
+
149
246
self .test_data_generator .put_default_jurisdiction_configuration_in_configuration_table (
150
247
value_overrides = {
151
248
'postalAbbreviation' : 'oh' ,
152
249
'jurisdictionName' : 'Ohio' ,
153
- 'licenseeRegistrationEnabled' : False ,
250
+ 'licenseeRegistrationEnabled' : True ,
154
251
}
155
252
)
156
253
157
- self ._load_provider_data ()
158
-
159
- event = self ._when_testing_provider_user_event_with_custom_claims ()
160
-
161
254
resp = get_purchase_privilege_options (event , self .mock_context )
162
255
163
256
self .assertEqual (200 , resp ['statusCode' ])
164
257
privilege_options = json .loads (resp ['body' ])
165
258
166
- # ensure the compact and privilege were returned
259
+ # Should return compact option + 1 live jurisdiction
167
260
self .assertEqual (2 , len (privilege_options ['items' ]))
168
261
169
- # Filter to only jurisdiction options
262
+ # Verify compact option and one jurisdiction option are returned
263
+ compact_options = [option for option in privilege_options ['items' ] if option ['type' ] == 'compact' ]
170
264
jurisdiction_options = [option for option in privilege_options ['items' ] if option ['type' ] == 'jurisdiction' ]
171
265
172
- # Should only return the jurisdiction with licenseeRegistrationEnabled = True
266
+ self . assertEqual ( 1 , len ( compact_options ))
173
267
self .assertEqual (1 , len (jurisdiction_options ))
268
+
269
+ # Verify only the live jurisdiction (Kentucky) is returned
174
270
returned_jurisdiction = jurisdiction_options [0 ]
175
271
self .assertEqual ('ky' , returned_jurisdiction ['postalAbbreviation' ])
176
272
self .assertEqual ('Kentucky' , returned_jurisdiction ['jurisdictionName' ])
0 commit comments