diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb index efc12a92a..69ec29733 100644 --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -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: "Test #{rand(100000).to_i}Test".html_safe end diff --git a/config/routes.rb b/config/routes.rb index e4bc0fa4e..e2c6f3d51 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/controllers/test_controller_test.rb b/test/controllers/test_controller_test.rb index eb9fef1b8..94eaed620 100644 --- a/test/controllers/test_controller_test.rb +++ b/test/controllers/test_controller_test.rb @@ -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