"""Tests for canned_response_note model.""" from datetime import datetime import pytest from product_review.api import db from product_review.models import canned_response_note as canned_response_note_model from tests.utils.db_utils import create_test_canned_response_note def test_create_canned_response_note(): """Test create canned response note.""" canned_response_note_model.create_canned_response_note( canned_response_id=1, modified_by_user_id="user-2", note_text="some abc", note_keyword="abc", language_code="en", ) db.session.commit() item = canned_response_note_model.get_canned_response_note(1) assert isinstance(item.pop("last_updated"), datetime) assert item == { "note_id": 1, "canned_response_id": 1, "modified_by_user_id": "user-2", "note_text": "some abc", "note_keyword": "abc", "language_code": "en", } def test_update_canned_response_note(): """Test update canned response note.""" create_test_canned_response_note( canned_response_id=1, modified_by_user_id="user-2", note_text="some abc", note_keyword="abc", language_code="en", ) canned_response_note_model.update_canned_response_note( note_id=1, note_keyword="abc not the same", modified_by_user_id="user-0" ) db.session.commit() item = canned_response_note_model.get_canned_response_note(1) assert isinstance(item.pop("last_updated"), datetime) assert item == { "note_id": 1, "canned_response_id": 1, "modified_by_user_id": "user-0", "note_text": "some abc", "note_keyword": "abc not the same", "language_code": "en", } def test_update_canned_response_note_not_found(): """Test update canned response note not found.""" with pytest.raises(Exception) as er: canned_response_note_model.update_canned_response_note( note_id=1, note_keyword="abc 123", modified_by_user_id="user-0" ) assert ( str(getattr(er, "value", None)) == '{"status": 404, "code": "not_found", "message": "Not Found"}' ) def test_get_canned_response_notes(): """Test get canned response notes.""" create_test_canned_response_note( canned_response_id=1, modified_by_user_id="user-2", note_text="some abc", note_keyword="abc", language_code="en", ) create_test_canned_response_note( canned_response_id=2, modified_by_user_id="user-2", note_text="some def", note_keyword="def", language_code="en", ) results = canned_response_note_model.get_canned_response_notes( [[1, "en"], [2, "en"], [2, "fr"]] ) assert len(results) == 2 assert results[0].canned_response_id == 1 assert results[0].language_code == "en" assert results[1].canned_response_id == 2 assert results[1].language_code == "en"