@@ -430,6 +430,52 @@ async def test_sales_call_with_bdr_person(
430430 company = db .exec (select (Company )).first ()
431431 assert company .bdr_person_id == bdr_person .tc2_admin_id
432432
433+ @patch ('fastapi.BackgroundTasks.add_task' )
434+ @patch ('app.callbooker.google.AdminGoogleCalendar._create_resource' )
435+ async def test_sales_call_with_bdr_person_resolves_tc2_admin_id (
436+ self , mock_gcal_builder , mock_add_task , client , db , test_pipeline , test_stage , test_config
437+ ):
438+ """Test booking sales call when tc2_admin_id is passed as bdr_person_id gets resolved to admin.id"""
439+ from sqlalchemy .exc import IntegrityError
440+
441+ mock_gcal_builder .side_effect = fake_gcal_builder ()
442+ sales_person = db .create (Admin (first_name = 'Sales' , last_name = 'Person' , username = 'sales@example.com' ))
443+ bdr_person = db .create (
444+ Admin (
445+ first_name = 'BDR' ,
446+ last_name = 'Person' ,
447+ username = 'bdr@example.com' ,
448+ tc2_admin_id = 4253776 ,
449+ is_bdr_person = True ,
450+ )
451+ )
452+
453+ meeting_data = CB_MEETING_DATA .copy ()
454+ meeting_data ['bdr_person_id' ] = 4253776
455+
456+ original_commit = db .commit
457+ commit_count = [0 ]
458+
459+ def mock_commit ():
460+ commit_count [0 ] += 1
461+ if commit_count [0 ] == 1 :
462+ raise IntegrityError ('' , '' , '' , '' )
463+ return original_commit ()
464+
465+ db .commit = mock_commit
466+
467+ try :
468+ r = client .post (
469+ client .app .url_path_for ('book-sales-call' ), json = {'admin_id' : sales_person .id , ** meeting_data }
470+ )
471+
472+ assert r .status_code == 200
473+
474+ company = db .exec (select (Company )).first ()
475+ assert company .bdr_person_id == bdr_person .id
476+ finally :
477+ db .commit = original_commit
478+
433479 @patch ('fastapi.BackgroundTasks.add_task' )
434480 @patch ('app.callbooker.google.AdminGoogleCalendar._create_resource' )
435481 async def test_sales_call_uses_pipeline_dft_entry_stage (
0 commit comments