From 7645093c2ed3f134e1f3ae617cba792f740e7387 Mon Sep 17 00:00:00 2001 From: Devin Gaffney Date: Sat, 17 Aug 2024 19:09:43 -0700 Subject: [PATCH] set to sync --- app/models/explainer.rb | 2 +- test/models/bot/smooch_6_test.rb | 10 +++++----- test/models/explainer_test.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/explainer.rb b/app/models/explainer.rb index c59740740..0e4708173 100644 --- a/app/models/explainer.rb +++ b/app/models/explainer.rb @@ -108,7 +108,7 @@ def self.search_by_similarity(text, language, team_id) language: language } } - Bot::Alegre.get_async_raw_params(params, "text") + response = Bot::Alegre.get_sync_raw_params(params, "text") results = response['result'].to_a.sort_by{ |result| result['_score'] } explainer_ids = results.collect{ |result| result.dig('_source', 'context', 'explainer_id').to_i }.uniq.first(3) explainer_ids.empty? ? Explainer.none : Explainer.where(team_id: team_id, id: explainer_ids) diff --git a/test/models/bot/smooch_6_test.rb b/test/models/bot/smooch_6_test.rb index bc414b93e..eed425a1b 100644 --- a/test/models/bot/smooch_6_test.rb +++ b/test/models/bot/smooch_6_test.rb @@ -139,7 +139,7 @@ def send_message_outside_24_hours_window(template, pm = nil) test "should submit query without details on tipline bot v2" do WebMock.stub_request(:post, /\/text\/similarity\/search\//).to_return(body: {}.to_json) # For explainers - WebMock.stub_request(:post, /\/similarity\/async\/text/).to_return(body: {}.to_json) # For explainers + WebMock.stub_request(:post, /\/similarity\/sync\/text/).to_return(body: {}.to_json) # For explainers claim = 'This is a test claim' send_message 'hello', '1', '1', random_string, random_string, claim, random_string, random_string, '1' assert_saved_query_type 'default_requests' @@ -209,7 +209,7 @@ def send_message_outside_24_hours_window(template, pm = nil) end test "should submit query with details on tipline bot v2" do - WebMock.stub_request(:post, /\/similarity\/async\/text/).to_return(body: {}.to_json) # For explainers + WebMock.stub_request(:post, /\/similarity\/sync\/text/).to_return(body: {}.to_json) # For explainers WebMock.stub_request(:post, /\/text\/similarity\/search\//).to_return(body: {}.to_json) # For explainers claim = 'This is a test claim' send_message 'hello', '1', '1', random_string, '2', random_string, claim, '1' @@ -287,7 +287,7 @@ def send_message_outside_24_hours_window(template, pm = nil) end test "should submit query and handle search error on tipline bot v2" do - WebMock.stub_request(:post, /\/similarity\/async\/text/).to_return(body: {}.to_json) # For explainers + WebMock.stub_request(:post, /\/similarity\/sync\/text/).to_return(body: {}.to_json) # For explainers CheckSearch.any_instance.stubs(:medias).raises(StandardError) Sidekiq::Testing.inline! do send_message 'hello', '1', '1', 'Foo bar', '1' @@ -386,7 +386,7 @@ def send_message_outside_24_hours_window(template, pm = nil) ProjectMedia.any_instance.stubs(:report_status).returns('published') ProjectMedia.any_instance.stubs(:analysis_published_article_url).returns(random_url) Bot::Alegre.stubs(:get_merged_similar_items).returns({ create_project_media.id => { score: 0.9 } }) - WebMock.stub_request(:post, /\/similarity\/async\/text/).to_return(body: {}.to_json) # For explainers + WebMock.stub_request(:post, /\/similarity\/sync\/text/).to_return(body: {}.to_json) # For explainers Sidekiq::Testing.inline! do send_message 'hello', '1', '1', "Foo bar foo bar #{url} foo bar", '1' end @@ -695,7 +695,7 @@ def send_message_outside_24_hours_window(template, pm = nil) pm = create_project_media team: @team publish_report(pm, {}, nil, { language: 'pt', use_visual_card: false }) Bot::Smooch.stubs(:get_search_results).returns([pm]) - WebMock.stub_request(:post, /\/similarity\/async\/text/).to_return(body: {}.to_json) # For explainers + WebMock.stub_request(:post, /\/similarity\/sync\/text/).to_return(body: {}.to_json) # For explainers Sidekiq::Testing.inline! do send_message 'hello', '1', '1', 'Foo bar', '1' end diff --git a/test/models/explainer_test.rb b/test/models/explainer_test.rb index 14e3517d4..c9010238f 100644 --- a/test/models/explainer_test.rb +++ b/test/models/explainer_test.rb @@ -100,12 +100,12 @@ def setup # Index two paragraphs and title when the explainer is created Bot::Alegre.stubs(:request).with('post', '/similarity/async/text', anything).times(3) - Bot::Alegre.stubs(:request).with('delete', '/similarity/async/text', anything).never + Bot::Alegre.stubs(:request).with('delete', '/text/similarity/', anything).never ex = create_explainer description: description # Update the index when paragraphs change Bot::Alegre.stubs(:request).with('post', '/similarity/async/text', anything).times(2) - Bot::Alegre.stubs(:request).with('delete', '/similarity/async/text', anything).once + Bot::Alegre.stubs(:request).with('delete', '/text/similarity/', anything).once ex = Explainer.find(ex.id) ex.description = 'Now this is the only paragraph' ex.save!