feat: add sitemap for help center (#9280)

* feat: start sitemap

* feat: add base url and last mod to sitemap

* fix: typo

* test: sitemap generation

* test: add draft articles

* fix: escape dots in regex matching

* feat: perpend protocol to the url

* feat: use ChatwootApp.help_center_root

* feat: don't parse the URL

* fix: function declaration
This commit is contained in:
Shivam Mishra
2024-04-26 21:36:39 +05:30
committed by GitHub
parent d88d0bdd80
commit 78f94511ff
5 changed files with 48 additions and 1 deletions

View File

@@ -1,12 +1,15 @@
require 'rails_helper'
RSpec.describe 'Public Portals API', type: :request do
RSpec.describe Public::Api::V1::PortalsController, type: :request do
let!(:account) { create(:account) }
let!(:agent) { create(:user, account: account, role: :agent) }
let!(:portal) { create(:portal, slug: 'test-portal', account_id: account.id, custom_domain: 'www.example.com') }
before do
create(:portal, slug: 'test-portal-1', account_id: account.id)
create(:portal, slug: 'test-portal-2', account_id: account.id)
create_list(:article, 3, account: account, author: agent, portal: portal, status: :published)
create_list(:article, 2, account: account, author: agent, portal: portal, status: :draft)
end
describe 'GET /public/api/v1/portals/{portal_slug}' do
@@ -28,4 +31,28 @@ RSpec.describe 'Public Portals API', type: :request do
Please send us an email at support@chatwoot.com with the custom domain name and account API key"
end
end
describe 'GET /public/api/v1/portals/{portal_slug}/sitemap' do
context 'when custom_domain is present' do
it 'gets a valid sitemap' do
get "/hc/#{portal.slug}/sitemap.xml"
expect(response).to have_http_status(:success)
expect(response.body).to match(/<sitemap/)
expect(Nokogiri::XML(response.body).errors).to be_empty
end
it 'has valid sitemap links' do
get "/hc/#{portal.slug}/sitemap.xml"
expect(response).to have_http_status(:success)
parsed_xml = Nokogiri::XML(response.body)
links = parsed_xml.css('loc')
links.each do |link|
expect(link.text).to match(%r{https://www\.example\.com/hc/test-portal/articles/\d+})
end
expect(links.length).to eq 3
end
end
end
end