"""Integration tests for GET /internal/parent_company//applications.""" import requests from account.constants.constants import ORCHARD_PARENT_COMPANY_UUID, SME_PARENT_COMPANY_UUID from account.models import application as app_model from tests.integration import config class TestGetParentCompanyApplications: """Integration tests for the parent company applications endpoint.""" def test_get_parent_company_applications_orchard_success(self, bearer_token_seat_admin) -> None: """GET /internal/parent_company//applications returns applications for Orchard.""" response = requests.get( f'{config.QA_BASE_URL}/internal/parent_company/{ORCHARD_PARENT_COMPANY_UUID}/applications', headers={'Authorization': f'Bearer {bearer_token_seat_admin}'}, ) assert response.status_code == 200 data = response.json() assert 'applications' in data assert len(data['applications']) == 2 # Check Insights app insights_app = next( ( app for app in data['applications'] if app['application_id'] == app_model.INSIGHTS_APP ), None, ) assert insights_app is not None assert insights_app['roles'] == [app_model.INSIGHTS_BASE_ROLE] assert insights_app['url'] == 'https://insights.theorchard.com' # Check Settings app settings_app = next( ( app for app in data['applications'] if app['application_id'] == app_model.SETTINGS_APP ), None, ) assert settings_app is not None assert settings_app['roles'] == [app_model.SETTINGS_BASE_ROLE] assert settings_app['url'] == 'https://settings.theorchard.com' def test_get_parent_company_applications_sme_success(self, bearer_token_seat_admin) -> None: """GET /internal/parent_company//applications returns applications for SME.""" response = requests.get( f'{config.QA_BASE_URL}/internal/parent_company/{SME_PARENT_COMPANY_UUID}/applications', headers={'Authorization': f'Bearer {bearer_token_seat_admin}'}, ) assert response.status_code == 200 data = response.json() assert 'applications' in data assert len(data['applications']) == 2 # Check that SME uses sme domain insights_app = next( ( app for app in data['applications'] if app['application_id'] == app_model.INSIGHTS_APP ), None, ) assert insights_app is not None assert insights_app['url'] == 'https://insights.sme.com' settings_app = next( ( app for app in data['applications'] if app['application_id'] == app_model.SETTINGS_APP ), None, ) assert settings_app is not None assert settings_app['url'] == 'https://settings.sme.com' def test_get_parent_company_applications_invalid_uuid(self, bearer_token_seat_admin) -> None: """GET /internal/parent_company//applications returns 400 for invalid UUID.""" invalid_uuid = '00000000-0000-0000-0000-000000000000' response = requests.get( f'{config.QA_BASE_URL}/internal/parent_company/{invalid_uuid}/applications', headers={'Authorization': f'Bearer {bearer_token_seat_admin}'}, ) assert response.status_code == 400 def test_get_parent_company_applications_missing_auth_header(self) -> None: """GET /internal/parent_company//applications returns 401 without auth header.""" response = requests.get( f'{config.QA_BASE_URL}/internal/parent_company/{ORCHARD_PARENT_COMPANY_UUID}/applications', ) assert response.status_code == 401 def test_get_parent_company_applications_forbidden_without_seat_role( self, bearer_token_with_vendor_star ) -> None: """GET /internal/parent_company//applications returns 403 without SEAT role.""" response = requests.get( f'{config.QA_BASE_URL}/internal/parent_company/{ORCHARD_PARENT_COMPANY_UUID}/applications', headers={'Authorization': f'Bearer {bearer_token_with_vendor_star}'}, ) assert response.status_code == 403