"""Tests for subaccount_note model.""" from datetime import datetime from product_review.api import db from product_review.models import subaccount_note as subaccount_note_model from tests.utils.db_utils import create_test_subaccount_note def test_get_items(): """Test get_items.""" create_test_subaccount_note(subaccount_id=1, note="abc", updated_by="user-123") create_test_subaccount_note(subaccount_id=2, note="def", updated_by="user-123") result = subaccount_note_model.get_items() for item in result: assert isinstance(item.pop("updated_timestamp"), datetime) assert result == [ {"subaccount_id": 1, "note": "abc", "updated_by": "user-123"}, {"subaccount_id": 2, "note": "def", "updated_by": "user-123"}, ] def test_get_subaccount_note(): """Test get_subaccount_note.""" create_test_subaccount_note(subaccount_id=1, note="abc", updated_by="user-123") result = subaccount_note_model.get_subaccount_note(1) assert isinstance(result.pop("updated_timestamp"), datetime) assert result == {"subaccount_id": 1, "note": "abc", "updated_by": "user-123"} def test_get_subaccount_note_none(): """Test get_subaccount_note None.""" result = subaccount_note_model.get_subaccount_note(2) assert result is None def test_create_subaccount_note(): """Test create_subaccount_note.""" subaccount_note_model.create_subaccount_note(1, "abc", "user-123") db.session.commit() item = subaccount_note_model.get_subaccount_note(1) assert isinstance(item.pop("updated_timestamp"), datetime) assert item == {"subaccount_id": 1, "note": "abc", "updated_by": "user-123"} def test_update_subaccount_note(): """Test update_subaccount_note.""" mock_obj = create_test_subaccount_note( subaccount_id=1, note="abc", updated_by="user-123" ) prev_updated_timestamp = mock_obj.updated_timestamp subaccount_note_model.update_subaccount_note(1, "def", "user-123") db.session.commit() item = subaccount_note_model.get_subaccount_note(1) assert item.pop("updated_timestamp") > prev_updated_timestamp assert item == {"subaccount_id": 1, "note": "def", "updated_by": "user-123"}