MAJOR=4
MINOR=36
DEVNAME=tty36
     ˆÉÈÏ571ÂÅÍ ;    ‹      ÅUÑnÚ0}ïWx~Ø[r	P:ÑÄSG�†FQ¦išö`b‡XMâÈ6¤ìëçl‚•j¬{‰¯ãcûœsm_ÿM8îÍ¾Núèãì~ˆ&Ÿ?=„€/­@8ë�¶Ûð ú#ŒpbLÑ(ËÒ-[®T˜M!1YÚm”ˆŒËÃäÊ¯þ‘+ä'œ2Û"ß“r2ÈB2F —FÆ›» ˜Ì4hž³X¤Üe<“n¢ÝHÊÂnÀd¤­ÓÚn·ÖÀø
¢„*ðZÝN§êŠˆƒ^Îí áˆ¼Xškà+ž›¶5K
¶¬ü¹dëŠ¬÷‰Ùý7Ñù†_*â›­h*y€�,0ñE¶@ZEÉ\Ã<¥ù£»1F45þ6è�¿[˜¤šM|ŠÅã ¿ï£Ûqb2¢÷�ÇÜ[Ì&CªÊ$±àì$ø¡?ˆ§kLÈu¤Da„Ì÷P°¥F2ÕµZ¯­‚D¢j{ÎýbÆänÚÍÂÁ´¶„UKìÙ½fš1™Pe3�B¡xd¤Zom¨9½Íçº¸ÝuÑV¤‹Ä`‚�ƒŽ"_àÌ2Ìe™šc�?j‹•€‰ýü�Q³Ñì8^Óix¨Ùê6n:´ÏÆ§¿¥Ë”quÈüTB·æoØWÁ³
<§Õ@ÞM·ýî¤‚K˜¾‚B–\Yu{‰¼.ÿý¹ÇdŸŸ‡«ã—`¹y—1©ÛK¤?_…3_AØÖ6eË‡ºÆþë/÷ÚÆ    N   ˆl–Ãa¾”*i?u8 …p/Üiå1hß�þBó�¬ã€²2ó¥,¤þÑƒpM?ÐÌa–ßi~” T¾R( 	Å+€và@¦-ÿÏ i    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe 'KnowledgeBase public feed', type: :request do
  include_context 'basic Knowledge Base'

  before do
    # Skip asset generation: the not found page links stylesheets the test environment does not compile.
    allow_any_instance_of(ActionView::Base).to receive(:compute_asset_path).and_return('')

    published_answer
    travel 1.minute
    published_answer_in_other_category
  end

  describe '#root' do
    before do
      get help_root_feed_path(locale_name)
    end

    it 'lists entries' do
      answer_index = response.body.index published_answer.translations.first.title
      answer_index2 = response.body.index published_answer_in_other_category.translations.first.title

      expect(answer_index > answer_index2).to be_truthy
    end

    it 'uses KB title' do
      expect(response.body).to include(knowledge_base.translations.first.title)
    end
  end

  describe '#category' do
    context 'with a public category' do
      before do
        get help_category_feed_path(locale_name, category)
      end

      it 'lists entries', :aggregate_failures do
        expect(response.body).to include(published_answer.translations.first.title)
        expect(response.body).not_to include(published_answer_in_other_category.translations.first.title)
      end

      it 'uses category title' do
        expect(response.body).to include(category.translations.first.title)
      end
    end

    context 'when the category has no published answers' do
      let(:hidden_category) { create(:knowledge_base_category, :containing_internal, knowledge_base: knowledge_base, translations: [build(:knowledge_base_category_translation, title: 'SecretCanary', kb_locale: primary_locale)]) }

      before do
        # The feed icon prints the category title in the layout head and the feed picker.
        knowledge_base.update!(show_feed_icon: true)
      end

      context 'when visited anonymously' do
        before do
          get help_category_feed_path(locale_name, hidden_category)
        end

        it 'is not found', :aggregate_failures do
          expect(response).to have_http_status(:not_found)
          expect(response.body).not_to match(%r{secretcanary}i)
        end
      end

      # The guard is the policy, not the published content alone: editors keep the feed.
      context 'when visited by an editor' do
        before do
          authenticated_as(create(:admin), via: :browser)

          get help_category_feed_path(locale_name, hidden_category)
        end

        it 'serves the feed', :aggregate_failures do
          expect(response).to have_http_status(:ok)
          expect(response.body).to include('SecretCanary')
        end
      end
    end

    context 'when the category does not exist' do
      before do
        get help_category_feed_path(locale_name, 0)
      end

      it 'is not found' do
        expect(response).to have_http_status(:not_found)
      end
    end
  end

  context 'with no answers' do
    before do
      Ticket.destroy_all
    end

    it 'loads' do
      get help_root_feed_path(locale_name)

      expect(response).to have_http_status :ok
    end
  end

  # Custom subdomain/path is handled by rewriting at the web server, which calls
  # the original /help URL with a custom