# frozen_string_literal: true require "webmock" require "factory_bot_rails" require "simplecov" require "minitest/reporters" class NeetoCommonsBackend::TestHelper class << self def webapp_setup common_setup webmock_disable_net_connect add_modules_to_action_dispatch_integration_test add_methods_to_action_dispatch_integration_test end def common_setup simplecov_config minitest_reporters_config setup_common_stubs add_modules_to_active_support_test_case end private def setup_common_stubs WebMock.stub_request(:post, "http://app.lvh.me:9000/api/v1/server/global_roles") .to_return(status: 200, body: "", headers: {}) end def minitest_reporters_config Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)] end def simplecov_config SimpleCov.start "rails" do groups.clear track_files "{app}/**/*.rb" add_filter "test/" add_filter "lib/" add_filter "app/mailer_previews/" add_filter "app/models/concerns/" add_filter "app/controllers/concerns/" add_filter "app/services/sample_data/" add_filter "app/services/sample_data_loader_service.rb" add_filter "app/services/seeds/sample_data_service.rb" add_group "Controllers", "app/controllers" add_group "Models", "app/models" add_group "Services", "app/services" add_group "Mailers", "app/mailers" add_group "Workers", "app/workers" add_group "Jobs", "app/jobs" add_group "Carriers", "app/carriers" add_group "Policies", "app/policies" add_group "Channels", "app/channels" add_group "Helpers", "app/helpers" end end def webmock_disable_net_connect WebMock.disable_net_connect!(allow_localhost: true, allow: "fonts.googleapis.com") end def add_methods_to_action_dispatch_integration_test ActionDispatch::IntegrationTest.define_method(:response_json) do response.parsed_body end ActionDispatch::IntegrationTest.define_method(:validate_response) do |response_code, **messages| assert_response response_code messages.each_key do |key| assert_equal messages[key], response_json[key.to_s] end end end def add_modules_to_action_dispatch_integration_test ActionDispatch::IntegrationTest.include(ActionView::Helpers::TranslationHelper) ActionDispatch::IntegrationTest.include(Devise::Test::IntegrationHelpers) end def add_modules_to_active_support_test_case ActiveSupport::TestCase.include(ActionView::Helpers::TranslationHelper) ActiveSupport::TestCase.include(FactoryBot::Syntax::Methods) end end end