Skip to content

Commit

Permalink
Send report when bulk-accepting suggestion. (#1927)
Browse files Browse the repository at this point in the history
Fixes CV2-4758.
  • Loading branch information
caiosba authored Jun 18, 2024
1 parent 94394bb commit 24657cf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/concerns/relationship_bulk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def bulk_update(ids, updates, team)
team_id: team&.id,
user_id: User.current&.id,
source_id: source_id,
action: updates[:action]
}
self.delay.run_update_callbacks(ids.to_json, extra_options.to_json)
{ source_project_media: pm_source }
Expand Down Expand Up @@ -110,6 +111,8 @@ def run_update_callbacks(ids_json, extra_options_json)
callbacks.each do |callback|
r.send(callback)
end
# Send report if needed
Relationship.inherit_status_and_send_report(r.id) if extra_options['action'] == 'accept'
end
# Update un-matched field
ProjectMedia.where(id: target_ids).update_all(unmatched: 0)
Expand Down
27 changes: 27 additions & 0 deletions test/controllers/graphql_controller_12_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,31 @@ def teardown
Rails.stubs(:logger).returns(mock_logger)
post :create, params: { query: query }
end

test "should send report when bulk-accepting suggestion" do
Sidekiq::Testing.fake!
WebMock.stub_request(:get, /#{CheckConfig.get('narcissus_url')}/).to_return(body: '{"url":"http://screenshot/test/test.png"}')
create_verification_status_stuff
pm1 = create_project_media team: @t ; s = pm1.last_status_obj ; s.status = 'false' ; s.save!
publish_report(pm1)
pm2 = create_project_media team: @t ; s = pm2.last_status_obj ; s.status = 'undetermined' ; s.save!
b1 = create_team_bot(name: 'Alegre', login: 'alegre')
b2 = create_team_bot(name: 'Smooch', login: 'smooch', set_approved: true)
b2.install_to!(@t)
r = create_relationship source_id: pm1.id, target_id: pm2.id, relationship_type: Relationship.suggested_type, user: b1

assert_equal 'false', pm1.reload.last_status
assert_equal 'undetermined', pm2.reload.last_status

authenticate_with_user(@u)
query = 'mutation { updateRelationships(input: { clientMutationId: "1", ids: ' + [r.graphql_id].to_json + ', action: "accept", source_id: ' + pm1.id.to_s + ' }) { ids } }'
Sidekiq::Testing.inline! do
post :create, params: { query: query, team: @t.slug }
end
assert_response :success

# Child item should inherit status from parent when suggestion is accepted
assert_equal 'false', pm1.reload.last_status
assert_equal 'false', pm2.reload.last_status
end
end

0 comments on commit 24657cf

Please sign in to comment.