Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Right now the tests still fail, because we haven't added the new behavior.
Some notes:

- Currently we are still creating the media from the original_claim through
ProjectMedia, so I'm adding the tests to ProjectMedia.
- I'll add the new behavior, make sure the tests are working, and then
work on refactoring: we want to move this from ProjectMedia to Media.
– On the last test, I think, there is some extra weirdness going on:
it is actually creating 4 Medias: 2 Claims and 2 Links. I don't think it
should create the Link Medias. I'll look into that.
  • Loading branch information
vasconsaurus committed Jan 22, 2025
1 parent ad18785 commit 54b7546
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/models/project_media_7_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,40 @@ def setup
ProjectMedia.handle_fact_check_for_existing_claim(pm1, pm2)
end
end

test "should save the original_claim link when media is created from original_claim" do
setup_elasticsearch

# Mock Pender response for Link
link_url = 'https://example.com'
pender_url = CheckConfig.get('pender_url_private') + '/api/medias'
link_response = {
type: 'media',
data: {
url: link_url,
type: 'item'
}
}.to_json
WebMock.stub_request(:get, pender_url).with(query: { url: link_url }).to_return(body: link_response)
pm_link = create_project_media(set_original_claim: link_url)
assert_not_nil pm_link.media.original_claim
assert_equal pm_link.media.url, pm_link.media.original_claim
end

test "should save the original_claim text when media is created from original_claim" do
pm_claim = create_project_media(set_original_claim: 'This is a claim.')
assert_not_nil pm_claim.media.original_claim
assert_equal pm_claim.media.quote, pm_claim.media.original_claim
end

# For whatever reason this last test is actually creating 4 Medias: 2 Claims and 2 Links
# I don't think it should create the Link Medias
test "should check if the original_claim exists and return that instance when trying to create media" do
t = create_team
create_project team: t

assert_difference 'Media.count', 1 do
2.times { create_project_media(team: t, set_original_claim: 'This is a claim.') }
end
end
end

0 comments on commit 54b7546

Please sign in to comment.