"""Integration tests for lambda function.""" from sync_contract_sap.constants import ACTION_STATE_ACTION_NAME from tests.integration.conftest import dockerized_lambda_api_client from tests.integration.utils.db_helper import fetch_single_db_entry def test_invoke_lambda(basic_headers: dict[str, str]) -> None: """Assert lambda action.""" dockerized_lambda = dockerized_lambda_api_client(basic_headers) # defined in utils\db_fixtures.py account_name = 'integration tests' contract_name = 'test' query = """ select * from abacus_state where action_name = '{}'; """.format(ACTION_STATE_ACTION_NAME) result = fetch_single_db_entry(query) assert result['action_status'] == 'init' query = """ select * from account where account_name = '{}'; """.format(account_name) result = fetch_single_db_entry(query) assert result['sap_created_at'] is None query = """select * from contract where contract_name = '{}'; """.format(contract_name) result = fetch_single_db_entry(query) assert result['sap_created_at'] is None body = { 'abacus_event_id': 1, 'target_type': 'contract', 'target_id': '1', 'event_name': 'sync_contract_sap', 'event_date': '1997-07-16T19 :20:30.45+01:00', } res = dockerized_lambda.post_lambda('2015-03-31', body) assert res.status_code == 200 assert 'status' in res.json(), ( f'error type was: {res.json()["errorType"]}, ' f'error message was: {res.json()["errorMessage"]}' ) assert res.json()['status'] == 'OK' query = """ select * from abacus_state where action_name = '{}'; """.format(ACTION_STATE_ACTION_NAME) result = fetch_single_db_entry(query) assert result['action_status'] == 'complete' query = """ select * from account where account_name = '{}'; """.format(account_name) result = fetch_single_db_entry(query) assert result['sap_created_at'] is not None query = """ select * from contract where contract_name = '{}'; """.format(contract_name) result = fetch_single_db_entry(query) assert result['sap_created_at'] is not None