Skip to content

Commit

Permalink
Make sure that null is not returned as the item when creating an im…
Browse files Browse the repository at this point in the history
…ported fact-check with original media in GraphQL API. (#2153)

When handling an existing media to decide if the imported fact-check is going to be added or appended to the existing media, there is a case where the media already exists with a fact-check in the same language that is trying to be imported. That case was returning nil. This PR fixes it by making sure that the new object is returned in that case, and then let the validations take care of returning a persisted or failed object.

Fixes: CV2-5804.
  • Loading branch information
caiosba authored Dec 13, 2024
1 parent cb54d3a commit b3f5756
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/models/project_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def apply_rules_and_actions_on_update
self.team.apply_rules_and_actions(self, rule_ids)
end

def self.handle_fact_check_for_existing_claim(existing_pm,new_pm)
def self.handle_fact_check_for_existing_claim(existing_pm, new_pm)
if existing_pm.fact_check.blank?
existing_pm.append_fact_check_from(new_pm)
return existing_pm
Expand All @@ -440,6 +440,7 @@ def self.handle_fact_check_for_existing_claim(existing_pm,new_pm)
return new_pm
end
end
new_pm
end

def append_fact_check_from(new_pm)
Expand Down
9 changes: 9 additions & 0 deletions test/models/project_media_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,13 @@ def setup
sleep 1
assert_equal [pm1.fact_check_id, pm2.fact_check_id, pm3.fact_check_id].sort, pm_i.get_similar_articles.map(&:id).sort
end

test "should not return null when handling fact-check for existing media" do
t = create_team
pm1 = create_project_media team: t
c = create_claim_description project_media: pm1
create_fact_check claim_description: c, language: 'en'
pm2 = ProjectMedia.new team: t, set_fact_check: { 'language' => 'en' }
assert_not_nil ProjectMedia.handle_fact_check_for_existing_claim(pm1, pm2)
end
end

0 comments on commit b3f5756

Please sign in to comment.