Skip to content

Commit

Permalink
Merge branch 'epic/CV2-5373-most-recent-articles-to-most-relevant-art…
Browse files Browse the repository at this point in the history
…icles' of github.com:meedan/check-api into epic/CV2-5373-most-recent-articles-to-most-relevant-articles
  • Loading branch information
melsawy committed Dec 11, 2024
2 parents 5d9d26d + f58a856 commit 20785b7
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/controllers/test_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,39 @@ def suggest_similarity_item
render_success 'suggest_similarity', pm1
end

def create_imported_standalone_fact_check
team = Team.current = Team.find(params[:team_id])
user = User.where(email: params[:email]).last
description = params[:description]
context = params[:context]
title = params[:title]
summary = params[:summary]
url = params[:url]
language = params[:language] || 'en'

# Create ClaimDescription
claim_description = ClaimDescription.create!(
description: description,
context: context,
user: user,
team: team
)

# Set up FactCheck
fact_check = FactCheck.new(
claim_description: claim_description,
title: title,
summary: summary,
url: url,
language: language,
user: user,
publish_report: true,
report_status: 'published'
)
fact_check.save!
render_success 'fact_check', fact_check
end

def random
render html: "<!doctype html><html><head><title>Test #{rand(100000).to_i}</title></head><body>Test</body></html>".html_safe
end
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
match '/test/suggest_similarity' => 'test#suggest_similarity_item', via: :get
match '/test/install_bot' => 'test#install_bot', via: :get
match '/test/add_team_user' => 'test#add_team_user', via: :get
match '/test/create_imported_standalone_fact_check' => 'test#create_imported_standalone_fact_check', via: :get
match '/test/random' => 'test#random', via: :get
end
47 changes: 47 additions & 0 deletions test/controllers/test_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,53 @@ class TestControllerTest < ActionController::TestCase
Rails.unstub(:env)
end

test "should create standalone fact check and associate with the team" do
# Test setup
team = create_team
user = create_user
create_team_user(user: user, team: team)

assert_difference 'FactCheck.count' do
get :create_imported_standalone_fact_check, params: {
team_id: team.id,
email: user.email,
description: 'Test description',
context: 'Test context',
title: 'Test title',
summary: 'Test summary',
url: 'http://example.com',
language: 'en'
}
end

assert_response :success
end

test "should not create standalone fact check and associate with the team" do
Rails.stubs(:env).returns('development')

# Test setup
team = create_team
user = create_user
create_team_user(user: user, team: team)

assert_no_difference 'FactCheck.count' do
get :create_imported_standalone_fact_check, params: {
team_id: team.id,
email: user.email,
description: 'Test description',
context: 'Test context',
title: 'Test title',
summary: 'Test summary',
url: 'http://example.com',
language: 'en'
}
end

assert_response 400
Rails.unstub(:env)
end

test "should get a random number in HTML" do
get :random
assert_response :success
Expand Down

0 comments on commit 20785b7

Please sign in to comment.