class PublishingApiPresenters::EditionRedirect
  attr_reader :item, :update_type

  def initialize(item, options = {})
    @item = item
    @update_type = options[:update_type] || default_update_type
  end

  def base_path
    Whitehall.url_maker.public_document_path(item)
  end

  def as_json
    {
      base_path: base_path,
      format: "redirect",
      publishing_app: 'whitehall',
      redirects: [
        {
          path: base_path,
          type: "exact",
          destination: redirect_path
        }
      ],
      update_type: update_type,
    }
  end

private

  def redirect_path
    item.unpublishing.alternative_url.sub(Whitehall.public_root, '')
  end

  def default_update_type
    "major"
  end
end

class PublishingApiPresenters::EditionRedirect
  attr_reader :item, :update_type

  def initialize(item, options = {})
    @item = item
    @update_type = options[:update_type] || default_update_type
  end

  def base_path
    Whitehall.url_maker.public_document_path(item)
  end

  def as_json
    {
      base_path: base_path,
      format: "redirect",
      publishing_app: 'whitehall',
      redirects: [
        {
          path: base_path,
          type: "exact",
          destination: redirect_path
        }
      ],
      update_type: update_type,
    }
  end

private

  def redirect_path
    URI.parse(item.unpublishing.alternative_url).path
  end

  def default_update_type
    "major"
  end
end

Make sure redirects are only sent as paths
Make sure redirects are only sent as paths

Depending on the environment the Unpublishing was created in, the
alternative_url may or may not start with `Whitehall.public_root`. For example,
, the unpublishings we get from a data sync will us the "https://www.gov.uk"
domain. This updates the presenter so that it always sends a path with the
redirect.
