Skip to content

Commit

Permalink
CV2-5846: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
melsawy committed Dec 17, 2024
1 parent 2813d7e commit 823541a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def search_for_similar_articles(query, pm = nil)
end
}
threads << Thread.new {
ex_items = Bot::Smooch.search_for_explainers(nil, query, self.id, limit)
ex_items = Bot::Smooch.search_for_explainers(nil, query, self.id, limit).distinct
# Exclude the ones already applied to a target item
ex_items = ex_items.where.not(id: pm.explainer_ids) unless pm&.explainer_ids.blank?
}
Expand Down
16 changes: 8 additions & 8 deletions test/controllers/feeds_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setup
@f = create_feed published: true
@f.teams = [@t1, @t2]
FeedTeam.update_all(shared: true)
Bot::Smooch.stubs(:search_for_similar_published_fact_checks).with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, false).returns([@pm1, @pm2])
Bot::Smooch.stubs(:search_for_similar_published_fact_checks).with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, nil, false).returns([@pm1, @pm2])
end

def teardown
Expand All @@ -44,7 +44,7 @@ def teardown
b.api_key = a
b.save!
create_team_user team: @t1, user: b
Bot::Smooch.stubs(:search_for_similar_published_fact_checks).with('text', 'Foo', [@t1.id], 3, nil, false).returns([@pm1])
Bot::Smooch.stubs(:search_for_similar_published_fact_checks).with('text', 'Foo', [@t1.id], 3, nil, nil, nil, false).returns([@pm1])

authenticate_with_token a
get :index, params: { filter: { type: 'text', query: 'Foo' } }
Expand All @@ -55,7 +55,7 @@ def teardown

test "should request feed data" do
Bot::Smooch.stubs(:search_for_similar_published_fact_checks)
.with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, false)
.with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, nil, false)
.returns([@pm1, @pm2])
authenticate_with_token @a
get :index, params: { filter: { type: 'text', query: 'Foo', feed_id: @f.id } }
Expand All @@ -68,13 +68,13 @@ def teardown
Sidekiq::Testing.fake! do
authenticate_with_token @a

Bot::Smooch.stubs(:search_for_similar_published_fact_checks).with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, false).returns([@pm1, @pm2])
Bot::Smooch.stubs(:search_for_similar_published_fact_checks).with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, nil, false).returns([@pm1, @pm2])
get :index, params: { filter: { type: 'text', query: 'Foo', feed_id: @f.id } }
assert_response :success
assert_equal 'Foo', json_response['data'][0]['attributes']['organization']
assert_equal 'Bar', json_response['data'][1]['attributes']['organization']

Bot::Smooch.stubs(:search_for_similar_published_fact_checks).with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, false).returns([@pm2, @pm1])
Bot::Smooch.stubs(:search_for_similar_published_fact_checks).with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, nil, false).returns([@pm2, @pm1])
get :index, params: { filter: { type: 'text', query: 'Foo', feed_id: @f.id } }
assert_response :success
assert_equal 'Bar', json_response['data'][0]['attributes']['organization']
Expand Down Expand Up @@ -111,7 +111,7 @@ def teardown
test "should save request query" do
Bot::Alegre.stubs(:request).returns({})
Bot::Smooch.stubs(:search_for_similar_published_fact_checks)
.with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, false)
.with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, nil, false)
.returns([@pm1, @pm2])
Sidekiq::Testing.inline!
authenticate_with_token @a
Expand All @@ -129,7 +129,7 @@ def teardown
test "should save relationship between request and results" do
Bot::Alegre.stubs(:request).returns({})
Bot::Smooch.stubs(:search_for_similar_published_fact_checks)
.with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, false)
.with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, nil, false)
.returns([@pm1, @pm2])
Sidekiq::Testing.inline!
authenticate_with_token @a
Expand All @@ -143,7 +143,7 @@ def teardown
test "should not save request when skip_save_request is true" do
Bot::Alegre.stubs(:request).returns({})
Bot::Smooch.stubs(:search_for_similar_published_fact_checks)
.with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, false)
.with('text', 'Foo', [@t1.id, @t2.id], 3, nil, @f.id, nil, false)
.returns([@pm1, @pm2])
Sidekiq::Testing.inline!
authenticate_with_token @a
Expand Down

0 comments on commit 823541a

Please sign in to comment.