<commit_before>require 'test_helper'
require "gds_api/publishing_api/special_route_publisher"
require File.dirname(__FILE__) + '/../../lib/gds_api/test_helpers/publishing_api_v2'

describe GdsApi::PublishingApi::SpecialRoutePublisher do
  include ::GdsApi::TestHelpers::PublishingApiV2

  let(:content_id) { 'a-content-id-of-sorts' }  
  let(:special_route) {
    {
      content_id: content_id,
      title: "A title",
      description: "A description",
      base_path: "/favicon.ico",
      type: "exact",
      publishing_app: "static-publisher",
      rendering_app: "static-frontend",
    }
  }

  describe ".publish" do
    it "publishes the special routes" do
      
      Timecop.freeze(Time.now) do
        publisher = GdsApi::PublishingApi::SpecialRoutePublisher.new
        endpoint = Plek.current.find('publishing-api')
        payload = {
          base_path: special_route[:base_path],
          format: "special_route",
          title: special_route[:title],
          description: special_route[:description],
          routes: [
            {
              path: special_route[:base_path],
              type: special_route[:type],
            }
          ],
          publishing_app: special_route[:publishing_app],
          rendering_app: special_route[:rendering_app],
          public_updated_at: Time.now.iso8601,
        }

        stub_any_publishing_api_call
        
        publisher.publish(special_route)

        base_path = "#{endpoint}/v2/content/#{content_id}"
        assert_requested(:put, base_path, body: payload)
        assert_requested(:post, "#{base_path}/publish", body: { update_type: 'major' })

      end
    end

    describe 'Timezone handling' do
      let(:publishing_api) {<commit_msg>Tidy the special route publisher publishing test<commit_after>require 'test_helper'
require "gds_api/publishing_api/special_route_publisher"
require File.dirname(__FILE__) + '/../../lib/gds_api/test_helpers/publishing_api_v2'

describe GdsApi::PublishingApi::SpecialRoutePublisher do
  include ::GdsApi::TestHelpers::PublishingApiV2

  let(:content_id) { 'a-content-id-of-sorts' }
  let(:special_route) {
    {
      content_id: content_id,
      title: "A title",
      description: "A description",
      base_path: "/favicon.ico",
      type: "exact",
      publishing_app: "static-publisher",
      rendering_app: "static-frontend",
    }
  }

  let(:publisher) { GdsApi::PublishingApi::SpecialRoutePublisher.new }
  let(:endpoint) { Plek.current.find('publishing-api') }

  describe ".publish" do
    before do
      stub_any_publishing_api_call
    end

    it "publishes the special routes" do
      Timecop.freeze(Time.now) do
        publisher.publish(special_route)

        expected_payload = {
          base_path: special_route[:base_path],
          format: "special_route",
          title: special_route[:title],
          description: special_route[:description],
          routes: [
            {
              path: special_route[:base_path],
              type: special_route[:type],
            }
          ],
          publishing_app: special_route[:publishing_app],
          rendering_app: special_route[:rendering_app],
          public_updated_at: Time.now.iso8601,
        }

        assert_requested(:put, "#{endpoint}/v2/content/#{content_id}", body: expected_payload)
        assert_publishing_api_publish(content_id, update_type: 'major')
      end
    end

    describe 'Timezone handling' do
      let(:publishing_api) {
{'fraction_non_alphanumeric': 0.1145475372279496, 'fraction_numerical': 0.004009163802978236, 'mean_word_length': 2.8342480790340288, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7552981', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1061, 'n_words': 177}