test/services/recommender_test.rb in meducation_sdk-1.6.11 vs test/services/recommender_test.rb in meducation_sdk-1.6.12

- old
+ new

@@ -30,17 +30,24 @@ def test_should_call_new Recommender.expects(:new).with(item, {}).returns(mock(recommend: nil)) Recommender.recommend(item) end + def test_should_call_user_recommnder_new_with_user + user = User.new({}) + Recommender::UserRecommender.expects(:new).with(user, {}).returns(mock(recommend: nil)) + Recommender.recommend(user) + end + def test_should_proxy_to_recommend Recommender.any_instance.expects(:recommend) Recommender.recommend(nil) end def test_should_use_items_not_board_items Net::HTTP.expects(:get_response).with("recommender.meducation.net", "/combined?MediaFile/#{item.id}", 4567).returns(empty_response) + MediaFile.expects(:where).returns(@per_result) item = BoardItem.new(item_type: "MediaFile", item_id: 10) Recommender.new(item).recommend end def test_should_call_the_recommender_service_for_individual_recommendation @@ -150,8 +157,29 @@ recommendation_type: item2.class.name, recommendation_id: item2.id ) Net::HTTP.expects(:get_response).raises(StandardError) items = Recommender.new(item).recommend assert_equal [item2], items + end + + def test_user_recommender_calls_spi + user = User.new({id: 2}) + recommender = Recommender::UserRecommender.new(user) + Loquor.expects(:get).with("items/recommendations_for_user", user_id: user.id).returns([]) + recommender.recommend + end + + def test_user_recommender_calls_return_objects + user = User.new({id: 2}) + response = [{type: "MediaFile", id: 8}, {type: "ExternalResource", id: 22}] + recommender = Recommender::UserRecommender.new(user) + Loquor.expects(:get).returns(response) + results = recommender.recommend + + assert results[0].is_a?(MediaFile) + assert_equal 8, results[0].id + + assert results[1].is_a?(ExternalResource) + assert_equal 22, results[1].id end end end