Skip to content

Commit

Permalink
update stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
DGaffney committed Aug 18, 2024
1 parent 0b96781 commit f633165
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test/models/bot/smooch_6_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,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, /\/text\/similarity\/search\//).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
Expand Down Expand Up @@ -807,9 +807,9 @@ def send_message_outside_24_hours_window(template, pm = nil)

test 'should process menu option using NLU' do
# Mock any call to Alegre like `POST /text/similarity/` with a "text" parameter that contains "want"
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/text/similarity/' && z[:text] =~ /want/ }.returns(true)
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/similarity/sync/text' && z[:text] =~ /want/ }.returns(true)
# Mock any call to Alegre like `GET /text/similarity/` with a "text" parameter that does not contain "want"
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/text/similarity/search/' && (z[:text] =~ /want/).nil? }.returns({ 'result' => [] })
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/similarity/sync/text' && (z[:text] =~ /want/).nil? }.returns({ 'result' => [] })

# Enable NLU and add a couple of keywords for the newsletter menu option
nlu = SmoochNlu.new(@team.slug)
Expand All @@ -822,7 +822,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
subscription_option_id = @installation.get_smooch_workflows[0]['smooch_state_main']['smooch_menu_options'][2]['smooch_menu_option_id']

# Mock a call to Alegre like `GET /text/similarity/` with a "text" parameter that contains "want"
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/text/similarity/search/' && z[:text] =~ /want/ }.returns({ 'result' => [
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/similarity/sync/text' && z[:text] =~ /want/ }.returns({ 'result' => [
{ '_score' => 0.9, '_source' => { 'context' => { 'menu_option_id' => subscription_option_id } } },
{ '_score' => 0.2, '_source' => { 'context' => { 'menu_option_id' => query_option_id } } }
]})
Expand All @@ -836,7 +836,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
assert_state 'main'

# Mock a call to Alegre like `GET /text/similarity/` with a "text" parameter that contains "want"
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/text/similarity/search/' && z[:text] =~ /want/ }.returns({ 'result' => [
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/similarity/sync/text' && z[:text] =~ /want/ }.returns({ 'result' => [
{ '_score' => 0.96, '_source' => { 'context' => { 'menu_option_id' => subscription_option_id } } },
{ '_score' => 0.91, '_source' => { 'context' => { 'menu_option_id' => query_option_id } } }
]})
Expand Down Expand Up @@ -875,9 +875,9 @@ def send_message_outside_24_hours_window(template, pm = nil)
Sidekiq::Testing.fake! do
WebMock.disable_net_connect! allow: /#{CheckConfig.get('elasticsearch_host')}|#{CheckConfig.get('storage_endpoint')}/
# Mock any call to Alegre like `POST /text/similarity/` with a "text" parameter that contains "who are you"
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/text/similarity/' && z[:text] =~ /who are you/ }.returns(true)
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/similarity/sync/test' && z[:text] =~ /who are you/ }.returns(true)
# Mock any call to Alegre like `GET /text/similarity/` with a "text" parameter that does not contain "who are you"
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/text/similarity/search/' && (z[:text] =~ /who are you/).nil? }.returns({ 'result' => [] })
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/similarity/sync/test' && (z[:text] =~ /who are you/).nil? }.returns({ 'result' => [] })

# Enable NLU and add a couple of keywords to a new "About Us" resource
nlu = SmoochNlu.new(@team.slug)
Expand All @@ -887,7 +887,7 @@ def send_message_outside_24_hours_window(template, pm = nil)
r.add_keyword('who are you')

# Mock a call to Alegre like `GET /text/similarity/` with a "text" parameter that contains "who are you"
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/text/similarity/search/' && z[:text] =~ /who are you/ }.returns({ 'result' => [
Bot::Alegre.stubs(:request).with{ |x, y, z| x == 'post' && y == '/similarity/sync/text' && z[:text] =~ /who are you/ }.returns({ 'result' => [
{ '_score' => 0.9, '_source' => { 'context' => { 'resource_id' => 0 } } },
{ '_score' => 0.8, '_source' => { 'context' => { 'resource_id' => r.id } } }
]})
Expand Down

0 comments on commit f633165

Please sign in to comment.