<commit_before># frozen_string_literal: true

require "test_helper"
require "support/file_uploader_helpers"

module GobiertoAdmin
  class FileUploadServiceTest < ActiveSupport::TestCase
    include FileUploaderHelpers

    def file_upload_service
      @file_upload_service ||= GobiertoAdmin::FileUploadService.new(
        site: site,
        collection: :test_collection,
        attribute_name: :test_attribute,
        file: file
      )
    end

    def site
      @site ||= sites(:madrid)
    end

    def file
      @file ||= Rack::Test::UploadedFile.new(
        File.join(
          ActionDispatch::IntegrationTest.fixture_path,
          "files/gobierto_people/people/avatar.jpg"
        )
      )
    end

    def test_adapter
      assert_kind_of FileUploader::S3, file_upload_service.adapter
      assert_equal file, file_upload_service.adapter.file
      assert_includes file_upload_service.adapter.file_name, "site-#{site.id}/test_collection/test_attribute"
      assert_includes file_upload_service.adapter.file_name, file.original_filename
    end

    def test_adapter_in_development
      Rails.env.stub(:development?, true) do
        assert_kind_of FileUploader::Local, file_upload_service.adapter
        assert_equal file, file_upload_service.adapter.file<commit_msg>#1448: stub APP_CONFIG to test FileUploadService<commit_after># frozen_string_literal: true

require "test_helper"
require "support/file_uploader_helpers"

module GobiertoAdmin
  class FileUploadServiceTest < ActiveSupport::TestCase
    include FileUploaderHelpers

    def file_upload_service
      @file_upload_service ||= GobiertoAdmin::FileUploadService.new(
        site: site,
        collection: :test_collection,
        attribute_name: :test_attribute,
        file: file
      )
    end

    def site
      @site ||= sites(:madrid)
    end

    def file
      @file ||= Rack::Test::UploadedFile.new(
        File.join(
          ActionDispatch::IntegrationTest.fixture_path,
          "files/gobierto_people/people/avatar.jpg"
        )
      )
    end

    def test_adapter
      Object.stub_const(:APP_CONFIG, APP_CONFIG.dup.tap { |config| config["file_uploads_adapter"] = "s3" }) do
        assert_kind_of FileUploader::S3, file_upload_service.adapter
        assert_equal file, file_upload_service.adapter.file
        assert_includes file_upload_service.adapter.file_name, "site-#{site.id}/test_collection/test_attribute"
        assert_includes file_upload_service.adapter.file_name, file.original_filename
      end
    end

    def test_adapter_in_development
      Rails.env.stub(:development?, true) do
        assert_kind_of FileUploader::Local, file_upload_service.adapter
        assert_equal file, file_upload_service.adapter.file
{'fraction_non_alphanumeric': 0.0794460641399417, 'fraction_numerical': 0.002551020408163265, 'mean_word_length': 3.420289855072464, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4624113', 'n_tokens_mistral': 824, 'n_tokens_neox': 812, 'n_words': 143}