"""Tests for the DELETE /internal/v2/identities/ endpoint.""" import requests from tests.integration import config, utils def test_delete_employee_without_jwt() -> None: """Test deleting an internal user without a JWT.""" headers = { 'Content-Type': 'application/json', 'Orchard-Identity-Id': utils.OWS_PERMISSIONS_VENDOR_STAR_USER_ID, 'Orchard-Profile-Id': utils.OWS_PERMISSIONS_TEST_USER_SETTINGS_PROFILE_ID, 'Orchard-Profile-Type': 'SettingsProfile', } res = requests.delete( f'{config.QA_BASE_URL}/internal/v2/identities/{utils.TEST_EMPLOYEE_USER_ID}', headers=headers, ) 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_delete_employee_without_pp_role( bearer_token_user_with_vendor_star: str, ) -> None: """Test deleting an employee without having the proper role.""" headers = { 'Authorization': f'Bearer {bearer_token_user_with_vendor_star}', 'Content-Type': 'application/json', } res = requests.delete( f'{config.QA_BASE_URL}/internal/v2/identities/{utils.TEST_EMPLOYEE_USER_ID}', headers=headers, ) assert res.status_code == 403 def test_delete_employee_not_found(seat_admin_jwt: str) -> None: """Test deleting a non-existent employee.""" headers = { 'Authorization': f'Bearer {seat_admin_jwt}', 'Content-Type': 'application/json', } res = requests.delete( f'{config.QA_BASE_URL}/internal/v2/identities/00000000-0000-0000-0000-000000000000', headers=headers, ) assert res.status_code == 404 assert res.json().get('message') == 'User does not exist' def test_delete_employee_success(seat_admin_jwt: str, new_employee_id: str) -> None: """Test deleting an employee successfully.""" headers = { 'Authorization': f'Bearer {seat_admin_jwt}', 'Content-Type': 'application/json', } res = requests.delete( f'{config.QA_BASE_URL}/internal/v2/identities/{new_employee_id}', headers=headers, ) assert res.status_code == 204 # Verify the identity is deactivated res = requests.get( f'{config.QA_OWS_USERS_URL}/users/identity/{new_employee_id}', headers=headers, ) assert res.json()['active'] == 'N'