demarches-normaliennes/spec/controllers/faq_controller_spec.rb
2024-05-16 11:43:58 +02:00

65 lines
2.1 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

RSpec.describe FAQController, type: :controller do
describe "GET #index" do
render_views
it "displays titles and render links for all entries" do
get :index
# Usager
expect(response.body).to include("Gestion de mon compte")
expect(response.body).to include("Je veux changer mon adresse email")
expect(response.body).to include(faq_path(category: "usager", slug: "je-veux-changer-mon-adresse-email"))
# Instructeur
expect(response.body).to include("Je dois confirmer mon compte à chaque connexion")
# Instructeur
expect(response.body).to include("Les blocs répétables")
end
context "with invalid subcategory" do
before do
service = instance_double(FAQsLoaderService, all: faqs)
allow(FAQsLoaderService).to receive(:new).and_return(service)
end
let(:faqs) do
{
'usager' => {
'oops' => [{ category: 'usager', subcategory: 'oops', title: 'FAQ Title 1', slug: 'faq1' }]
}
}
end
it "fails so we can't make a typo and publish non translated subcategories" do
expect { get :index }.to raise_error(ActionView::Template::Error)
end
end
end
describe "GET #show" do
before do
allow(Current).to receive(:application_name).and_return('demarches.gouv.fr')
end
render_views
context "when the FAQ exists" do
it "renders the show template with the FAQ content and metadata" do
get :show, params: { category: 'usager', slug: 'je-veux-changer-mon-adresse-email' }
expect(response.body).to include('Si vous disposez dun compte usager sur demarches.gouv.fr')
# link to siblings
expect(response.body).to include(faq_path(category: 'usager', slug: 'je-veux-changer-mon-mot-de-passe'))
end
end
context "when the FAQ does not exist" do
it "raises a routing error for a missing FAQ" do
expect {
get :show, params: { category: 'nonexistent', slug: 'nofaq' }
}.to raise_error(ActionController::RoutingError)
end
end
end
end