@@ -402,3 +402,159 @@ async def test_update_company_no_data(cli, db_conn, company, other_server):
402402 'details' : {},
403403 'status' : 'success' ,
404404 }
405+
406+
407+ async def test_update_company_update_contractors_false (cli , db_conn , company , other_server , worker ):
408+ curr = await db_conn .execute (sa_companies .select ())
409+ result = await curr .first ()
410+ assert result .domains == ['example.com' ]
411+ assert other_server .app ['request_log' ] == []
412+
413+ r = await signed_request (
414+ cli ,
415+ f'/{ company .public_key } /webhook/options' ,
416+ signing_key_ = 'this is the master key' ,
417+ domains = ['changed.com' ],
418+ display_mode = 'enquiry-modal' ,
419+ show_location_search = False ,
420+ pagination = 20 ,
421+ sort_on = 'review_rating' ,
422+ auth_url = 'https://foobar.com/whatever' ,
423+ terms_link = 'https://terms.com/' ,
424+ distance_units = 'km' ,
425+ currency = {'code' : 'USD' , 'symbol' : '$' },
426+ update_contractors = False ,
427+ )
428+ assert r .status == 200 , await r .text ()
429+ response_data = await r .json ()
430+ assert response_data == {
431+ 'details' : {
432+ 'domains' : ['changed.com' ],
433+ 'options' : {
434+ 'display_mode' : 'enquiry-modal' ,
435+ 'show_location_search' : False ,
436+ 'pagination' : 20 ,
437+ 'sort_on' : 'review_rating' ,
438+ 'auth_url' : 'https://foobar.com/whatever' ,
439+ 'terms_link' : 'https://terms.com/' ,
440+ 'distance_units' : 'km' ,
441+ 'currency' : {'code' : 'USD' , 'symbol' : '$' },
442+ },
443+ },
444+ 'company_domains' : ['changed.com' ],
445+ 'status' : 'success' ,
446+ }
447+ await worker .run_check ()
448+ assert other_server .app ['request_log' ] == []
449+
450+ curr = await db_conn .execute (sa_companies .select ())
451+ result = await curr .first ()
452+ assert result .domains == ['changed.com' ]
453+ assert result .options == {
454+ 'display_mode' : 'enquiry-modal' ,
455+ 'pagination' : 20 ,
456+ 'show_location_search' : False ,
457+ 'sort_on' : 'review_rating' ,
458+ 'auth_url' : 'https://foobar.com/whatever' ,
459+ 'terms_link' : 'https://terms.com/' ,
460+ 'distance_units' : 'km' ,
461+ 'currency' : {'code' : 'USD' , 'symbol' : '$' },
462+ }
463+
464+ r = await cli .get (f'/{ company .public_key } /options' )
465+ assert r .status == 200 , await r .text ()
466+ assert {
467+ 'display_mode' : 'enquiry-modal' ,
468+ 'name' : 'foobar' ,
469+ 'name_display' : 'first_name_initial' ,
470+ 'pagination' : 20 ,
471+ 'router_mode' : 'hash' ,
472+ 'show_hours_reviewed' : True ,
473+ 'show_labels' : True ,
474+ 'show_location_search' : False ,
475+ 'show_stars' : True ,
476+ 'show_subject_filter' : True ,
477+ 'sort_on' : 'review_rating' ,
478+ 'auth_url' : 'https://foobar.com/whatever' ,
479+ 'terms_link' : 'https://terms.com/' ,
480+ 'distance_units' : 'km' ,
481+ 'currency' : {'code' : 'USD' , 'symbol' : '$' },
482+ } == await r .json ()
483+
484+
485+ async def test_update_company_update_contractors_true (cli , db_conn , company , other_server , worker ):
486+ curr = await db_conn .execute (sa_companies .select ())
487+ result = await curr .first ()
488+ assert result .domains == ['example.com' ]
489+ assert other_server .app ['request_log' ] == []
490+
491+ r = await signed_request (
492+ cli ,
493+ f'/{ company .public_key } /webhook/options' ,
494+ signing_key_ = 'this is the master key' ,
495+ domains = ['changed.com' ],
496+ display_mode = 'enquiry-modal' ,
497+ show_location_search = False ,
498+ pagination = 20 ,
499+ sort_on = 'review_rating' ,
500+ auth_url = 'https://foobar.com/whatever' ,
501+ terms_link = 'https://terms.com/' ,
502+ distance_units = 'km' ,
503+ currency = {'code' : 'USD' , 'symbol' : '$' },
504+ update_contractors = True ,
505+ )
506+ assert r .status == 200 , await r .text ()
507+ response_data = await r .json ()
508+ assert response_data == {
509+ 'details' : {
510+ 'domains' : ['changed.com' ],
511+ 'options' : {
512+ 'display_mode' : 'enquiry-modal' ,
513+ 'show_location_search' : False ,
514+ 'pagination' : 20 ,
515+ 'sort_on' : 'review_rating' ,
516+ 'auth_url' : 'https://foobar.com/whatever' ,
517+ 'terms_link' : 'https://terms.com/' ,
518+ 'distance_units' : 'km' ,
519+ 'currency' : {'code' : 'USD' , 'symbol' : '$' },
520+ },
521+ },
522+ 'company_domains' : ['changed.com' ],
523+ 'status' : 'success' ,
524+ }
525+ await worker .run_check ()
526+ assert other_server .app ['request_log' ] == [('contractor_list' , None ), ('contractor_list' , '2' )]
527+
528+ curr = await db_conn .execute (sa_companies .select ())
529+ result = await curr .first ()
530+ assert result .domains == ['changed.com' ]
531+ assert result .options == {
532+ 'display_mode' : 'enquiry-modal' ,
533+ 'pagination' : 20 ,
534+ 'show_location_search' : False ,
535+ 'sort_on' : 'review_rating' ,
536+ 'auth_url' : 'https://foobar.com/whatever' ,
537+ 'terms_link' : 'https://terms.com/' ,
538+ 'distance_units' : 'km' ,
539+ 'currency' : {'code' : 'USD' , 'symbol' : '$' },
540+ }
541+
542+ r = await cli .get (f'/{ company .public_key } /options' )
543+ assert r .status == 200 , await r .text ()
544+ assert {
545+ 'display_mode' : 'enquiry-modal' ,
546+ 'name' : 'foobar' ,
547+ 'name_display' : 'first_name_initial' ,
548+ 'pagination' : 20 ,
549+ 'router_mode' : 'hash' ,
550+ 'show_hours_reviewed' : True ,
551+ 'show_labels' : True ,
552+ 'show_location_search' : False ,
553+ 'show_stars' : True ,
554+ 'show_subject_filter' : True ,
555+ 'sort_on' : 'review_rating' ,
556+ 'auth_url' : 'https://foobar.com/whatever' ,
557+ 'terms_link' : 'https://terms.com/' ,
558+ 'distance_units' : 'km' ,
559+ 'currency' : {'code' : 'USD' , 'symbol' : '$' },
560+ } == await r .json ()
0 commit comments