diff --git a/static/js/search/recommend.js b/static/js/search/recommend.js index 268f9d3..8b1b543 100644 --- a/static/js/search/recommend.js +++ b/static/js/search/recommend.js @@ -949,13 +949,12 @@ function get_like_keywords(like_sentence) { function get_recommend_keyword() { get_like() - console.log(like_sentence) - if (like_sentence[0] == '') { - like_keyword = [''] + if (like_sentence == "") { + like_keyword = "" $.ajax({ url: "/account/friends/keyword", type: 'POST', - data: JSON.stringify({ "like_keyowrd": like_keyword[0] }), + data: JSON.stringify({ "like_keyowrd": like_keyword }), enctype: 'multipart/form-data', headers: { 'X-CSRFTOKEN': CSRF_TOKEN diff --git a/tests/friend/services/test_friend_service.py b/tests/friend/services/test_friend_service.py index bedf418..2dfd761 100644 --- a/tests/friend/services/test_friend_service.py +++ b/tests/friend/services/test_friend_service.py @@ -6,6 +6,12 @@ from apps.friend.services.friend_service import FriendService from tests.account.factories import UserFactory, UserLikeKeywordFactory from tests.friend.factories import FriendFactory, FriendRequestFactory +from tests.search.factories import ( + BookFactory, + NewsFactory, + ShoppingFactory, + YoutubeFactory, +) pytestmark = pytest.mark.django_db @@ -140,3 +146,26 @@ def test_친구_관심_키워드_최신순_최대_3개_노출(): assert len(recommended) == 3 assert [word for word in recommended] == [obj.keyword for obj in keywords[:3]] + + +def test_유저_like_데이터_불러오기(): + + user = UserFactory.create() + youtube = YoutubeFactory.create(user=user) + news = NewsFactory.create(user=user) + book = BookFactory.create(user=user) + shopping = ShoppingFactory.create(user=user) + + sentence = FriendService.get_user_like_data(user_id=user.id) + + assert ( + sentence + == youtube.title + + " " + + news.title + + " " + + book.title + + " " + + shopping.title + + " " + ) diff --git a/tests/friend/v1/apis/test_friend_api.py b/tests/friend/v1/apis/test_friend_api.py index edff8c3..16c6b8f 100644 --- a/tests/friend/v1/apis/test_friend_api.py +++ b/tests/friend/v1/apis/test_friend_api.py @@ -12,6 +12,12 @@ from tests.account.factories import UserFactory, UserLikeKeywordFactory from tests.friend.factories import FriendFactory from tests.helpers import authorization_header +from tests.search.factories import ( + BookFactory, + NewsFactory, + ShoppingFactory, + YoutubeFactory, +) pytestmark = pytest.mark.django_db @@ -77,3 +83,25 @@ def test_관심_키워드_최대_3개_노출(client: Client): assert res.status_code == status.HTTP_200_OK assert res.data["keywords"] == list(reversed(sample_keywords))[:3] + + +def test_유저_좋아요_데이터_like_sentence_반환(client: Client): + + user = UserFactory.create(is_active=True) + youtube = YoutubeFactory.create(user=user) + news = NewsFactory.create(user=user) + book = BookFactory.create(user=user) + shopping = ShoppingFactory.create(user=user) + + res = client.post( + reverse("friend:v1:friends-get-user-like"), + content_type="application/json", + **authorization_header(user), + ) + + sentence = ( + youtube.title + " " + news.title + " " + book.title + " " + shopping.title + " " + ) + + assert res.status_code == status.HTTP_200_OK + assert res.data["like_sentence"] == sentence