@@ -170,6 +170,96 @@ async def test_review_user_pre_registration(
170170 await conn .commit ()
171171
172172
173+ async def test_review_user_pre_registration_with_invitation_extras (
174+ app : web .Application ,
175+ product_name : ProductName ,
176+ product_owner_user : dict [str , Any ],
177+ pre_registration_details_db_cleanup : list [int ],
178+ ):
179+ # Arrange
180+ asyncpg_engine = get_asyncpg_engine (app )
181+
182+ 183+ created_by_user_id = product_owner_user ["id" ]
184+ reviewer_id = product_owner_user ["id" ]
185+ institution = "Test Institution"
186+ pre_registration_details : dict [str , Any ] = {
187+ "institution" : institution ,
188+ "pre_first_name" : "Review" ,
189+ "pre_last_name" : "WithInvitation" ,
190+ }
191+
192+ # Create a pre-registration to review
193+ pre_registration_id = await _users_repository .create_user_pre_registration (
194+ asyncpg_engine ,
195+ email = test_email ,
196+ created_by = created_by_user_id ,
197+ product_name = product_name ,
198+ ** pre_registration_details ,
199+ )
200+
201+ # Add to cleanup list
202+ pre_registration_details_db_cleanup .append (pre_registration_id )
203+
204+ # Prepare invitation extras (mimicking the structure from _users_rest.py)
205+ invitation_extras = {
206+ "invitation" : {
207+ "issuer" : str (reviewer_id ),
208+ "guest" : test_email ,
209+ "trial_account_days" : 30 ,
210+ "extra_credits_in_usd" : 100.0 ,
211+ "product_name" : product_name ,
212+ "created" : "2024-01-01T00:00:00Z" ,
213+ }
214+ }
215+
216+ # Act - review and approve the registration with invitation extras
217+ new_status = AccountRequestStatus .APPROVED
218+ await _users_repository .review_user_pre_registration (
219+ asyncpg_engine ,
220+ pre_registration_id = pre_registration_id ,
221+ reviewed_by = reviewer_id ,
222+ new_status = new_status ,
223+ invitation_extras = invitation_extras ,
224+ )
225+
226+ # Assert - Use list_user_pre_registrations to verify
227+ registrations , count = await _users_repository .list_user_pre_registrations (
228+ asyncpg_engine ,
229+ filter_by_pre_email = test_email ,
230+ filter_by_product_name = product_name ,
231+ )
232+
233+ # Check count and that we found our registration
234+ assert count == 1
235+ assert len (registrations ) == 1
236+
237+ # Get the registration
238+ reg = registrations [0 ]
239+
240+ # Verify basic details
241+ assert reg ["id" ] == pre_registration_id
242+ assert reg ["pre_email" ] == test_email
243+ assert reg ["pre_first_name" ] == "Review"
244+ assert reg ["pre_last_name" ] == "WithInvitation"
245+ assert reg ["institution" ] == institution
246+ assert reg ["product_name" ] == product_name
247+ assert reg ["account_request_status" ] == new_status
248+ assert reg ["created_by" ] == created_by_user_id
249+ assert reg ["account_request_reviewed_by" ] == reviewer_id
250+ assert reg ["account_request_reviewed_at" ] is not None
251+
252+ # Verify invitation extras were stored correctly
253+ assert reg ["extras" ] is not None
254+ assert "invitation" in reg ["extras" ]
255+ invitation_data = reg ["extras" ]["invitation" ]
256+ assert invitation_data ["issuer" ] == str (reviewer_id )
257+ assert invitation_data ["guest" ] == test_email
258+ assert invitation_data ["trial_account_days" ] == 30
259+ assert invitation_data ["extra_credits_in_usd" ] == 100.0
260+ assert invitation_data ["product_name" ] == product_name
261+
262+
173263async def test_list_user_pre_registrations (
174264 app : web .Application ,
175265 product_name : ProductName ,
0 commit comments