@@ -402,34 +402,41 @@ class TestTransactionExpenseData:
402402 @pytest .mark .asyncio
403403 async def test_update_transaction_expense_data_with_specific_category_and_label (self , extend ):
404404 """Test updating the expense data for a transaction using a specific expense category and label."""
405- # Retrieve available expense categories (active ones)
406- categories_response = await extend .expense_data .get_expense_categories (active = True )
407- assert "expenseCategories" in categories_response , "Response should include 'expenseCategories'"
408- expense_categories = categories_response ["expenseCategories" ]
409- assert expense_categories , "No expense categories available for testing"
410-
411- # For this test, pick the first expense category
412- category = expense_categories [0 ]
413- category_id = category ["id" ]
414-
415- # Retrieve the labels for the chosen expense category
416- labels_response = await extend .expense_data .get_expense_category_labels (
417- category_id = category_id ,
418- page = 0 ,
419- per_page = 10
405+ # Create a new expense category for testing
406+ u = uuid .uuid4 ()
407+ category_name = f"Integration Test Category { u } "
408+ category_code = f"INTEG-CAT-{ u } "
409+ category_resp = await extend .expense_data .create_expense_category (
410+ name = category_name ,
411+ code = category_code ,
412+ required = True ,
413+ active = True ,
414+ free_text_allowed = False ,
420415 )
421- assert "expenseLabels" in labels_response , "Response should include 'expenseLabels'"
422- expense_labels = labels_response [ "expenseLabels" ]
423- assert expense_labels , "No expense labels available for the selected category"
416+ category_id = category_resp [ "id" ]
417+ assert category_resp [ "name" ] == category_name
418+ assert category_resp [ "code" ] == category_code
424419
425- # Pick the first label from the list
426- label = expense_labels [0 ]
427- label_id = label ["id" ]
420+ # Create a label under the category
421+ u1 = uuid .uuid4 ()
422+ label_name = f"Integration Label { u1 } "
423+ label_code = f"INTEG-LABEL-{ u1 } "
424+ label_resp = await extend .expense_data .create_expense_category_label (
425+ category_id = category_id ,
426+ name = label_name ,
427+ code = label_code ,
428+ active = True
429+ )
430+ label_id = label_resp ["id" ]
431+ assert label_resp ["name" ] == label_name
432+ assert label_resp ["code" ] == label_code
428433
429434 # Retrieve at least one transaction to update expense data
430435 transactions_response = await extend .transactions .get_transactions (per_page = 1 )
431- assert transactions_response .get ("transactions" ), "No transactions available for testing expense data update"
432- transaction = transactions_response ["transactions" ][0 ]
436+ assert "report" in transactions_response , "Response should include 'report'"
437+ assert "transactions" in transactions_response ["report" ], "Response should include 'transactions'"
438+ assert transactions_response ["report" ]["transactions" ], "No transactions available for testing expense data update"
439+ transaction = transactions_response ["report" ]["transactions" ][0 ]
433440 transaction_id = transaction ["id" ]
434441
435442 # Prepare the expense data payload with the specific category and label
@@ -447,11 +454,10 @@ async def test_update_transaction_expense_data_with_specific_category_and_label(
447454
448455 # Verify the response contains the transaction id and expected expense details
449456 assert "id" in response , "Response should include the transaction id"
450- if "expenseDetails" in response :
451- # Depending on the API response, the structure might vary; adjust assertions accordingly
452- assert response ["expenseDetails" ] == update_payload ["expenseDetails" ], (
453- "Expense details in the response should match the update payload"
454- )
457+ assert "expenseDetails" in response , "Response should include expenseDetails"
458+ assert len (response ["expenseDetails" ]) == 1 , "Response should contain exactly one expense detail"
459+ assert response ["expenseDetails" ][0 ]["categoryId" ] == category_id , "Category ID should match"
460+ assert response ["expenseDetails" ][0 ]["labelId" ] == label_id , "Label ID should match"
455461
456462
457463@pytest .mark .integration
0 commit comments