<commit_before># frozen_string_literal: true

require "test_helper"

class PurgeTest < Imgix::Test
  def test_runtime_error_without_api_key
    assert_raises(RuntimeError) do
      mock_client(api_key: nil).purge(mock_image)
    end
  end

  def test_successful_purge
    stub_request(:post, endpoint).with(body: body).to_return(status: 200)

    mock_client(api_key: "10adc394").purge("/images/demo.png")

    assert_requested(
      :post,
      endpoint,
      body: "url=https%3A%2F%2Fdemo.imgix.net%2Fimages%2Fdemo.png",
      headers: mock_headers,
      times: 1
    )
  end

  private

  def mock_client(api_key: "")
    Imgix::Client.new(
      domain: "demo.imgix.net",
      api_key: api_key,
      include_library_param: false
    )
  end

  def mock_headers
    {
      "Accept" => "*/*",
      "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
      "Authorization" => "Basic MTBhZGMzOTQ6",
      "Content-Type" => "application/x-www-form-urlencoded",
      "User-Agent" => "imgix rb-#{Imgix::VERSION}"
    }
  end

  def mock_image
    "https://demo.imgix.net/images/demo.png"
  end

  def endpoint
    "https://api.imgix.com/v2/image/purger"
  end

  def body
    { "url" => mock_image }
  end
end<commit_msg>test: update endpoint, content-type and auth headers<commit_after># frozen_string_literal: true

require "test_helper"

class PurgeTest < Imgix::Test
  def test_runtime_error_without_api_key
    assert_raises(RuntimeError) do
      mock_client(api_key: nil).purge(mock_image)
    end
  end

  def test_successful_purge
    stub_request(:post, endpoint).with(body: body).to_return(status: 200)

    mock_client(api_key: "10adc394").purge("/images/demo.png")

    assert_requested(
      :post,
      endpoint,
      body: "url=https%3A%2F%2Fdemo.imgix.net%2Fimages%2Fdemo.png",
      headers: mock_headers,
      times: 1
    )
  end

  private

  def mock_client(api_key: "")
    Imgix::Client.new(
      domain: "demo.imgix.net",
      api_key: api_key,
      include_library_param: false
    )
  end

  def mock_headers
    {
      "Accept" => "*/*",
      "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
      "Authorization" => "Bearer MTBhZGMz<PASSWORD>",
      "Content-Type" => "application/json",
      "User-Agent" => "imgix rb-#{Imgix::VERSION}"
    }
  end

  def mock_image
    "https://demo.imgix.net/images/demo.png"
  end

  def endpoint
    "https://api.imgix.com/api/v1/purge"
  end

  def body
    { "url" => mock_image }
  end
end
{'fraction_non_alphanumeric': 0.13817891373801916, 'fraction_numerical': 0.017172523961661343, 'mean_word_length': 3.099836333878887, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 16, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, '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': '5291653', 'n_tokens_mistral': 972, 'n_tokens_neox': 942, 'n_words': 151}