diff --git a/app/models/concerns/relationship_bulk.rb b/app/models/concerns/relationship_bulk.rb index f973d6f0c2..fa549fa307 100644 --- a/app/models/concerns/relationship_bulk.rb +++ b/app/models/concerns/relationship_bulk.rb @@ -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 } @@ -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) diff --git a/test/controllers/graphql_controller_12_test.rb b/test/controllers/graphql_controller_12_test.rb index db8b519c83..f5b75927ef 100644 --- a/test/controllers/graphql_controller_12_test.rb +++ b/test/controllers/graphql_controller_12_test.rb @@ -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