"""Tests for the POST /internal/user/email endpoint.""" import requests from tests.integration import config, constants def test_get_employee_by_email_without_jwt() -> None: """Test getting employee by email without a JWT.""" headers = { 'Content-Type': 'application/json', 'Orchard-Identity-Id': constants.INTEGRATION_TEST_USER_IDENTITY_ID, 'Orchard-Profile-Id': '650536', 'Orchard-Profile-Type': 'SettingsProfile', } res = requests.post( f'{config.QA_BASE_URL}/internal/user/get_by_email', headers=headers, json={'email': 'test@theorchard.com'}, ) assert res.status_code == 401 assert res.json().get('code') == 'authorization_error' assert res.json().get('message') == 'Request context has no identity uuid.' def test_get_employee_by_email_without_pp_role(authorized_user_jwt: str) -> None: """Test getting employee by email without having the proper role.""" headers = { 'Authorization': f'Bearer {authorized_user_jwt}', 'Content-Type': 'application/json', } res = requests.post( f'{config.QA_BASE_URL}/internal/user/get_by_email', headers=headers, json={'email': 'test@theorchard.com'}, ) assert res.status_code == 403 def test_get_employee_by_email(seat_admin_jwt: str) -> None: """Test getting employee by email with the seat role.""" headers = { 'Authorization': f'Bearer {seat_admin_jwt}', 'Content-Type': 'application/json', } res = requests.post( f'{config.QA_BASE_URL}/internal/user/get_by_email', headers=headers, json={'email': 'ratoui@sonymusic-pde.com'}, ) assert res.status_code == 200 assert 'id' in res.json() assert res.json()['id'] is not None def test_get_employee_by_email_not_found(seat_admin_jwt: str) -> None: """Test getting employee by email when identity does not exist.""" headers = { 'Authorization': f'Bearer {seat_admin_jwt}', 'Content-Type': 'application/json', } res = requests.post( f'{config.QA_BASE_URL}/internal/user/get_by_email', headers=headers, json={'email': 'bogus@theorchard.com'}, ) assert res.status_code == 404 assert res.json().get('message') == 'Identity not found' def test_get_employee_by_email_invalid_domain(seat_admin_jwt: str) -> None: """Test getting employee by email with an invalid email domain.""" headers = { 'Authorization': f'Bearer {seat_admin_jwt}', 'Content-Type': 'application/json', } res = requests.post( f'{config.QA_BASE_URL}/internal/user/get_by_email', headers=headers, json={'email': 'test@gmail.com'}, ) assert res.status_code == 400 assert 'gmail.com is not valid for employee identities' in str(res.json().get('message', ''))