chore: cross domain banner between APP_HOST_LEGACY and APP_HOST
This commit is contained in:
parent
61a9bedfff
commit
4dd24f0925
10 changed files with 137 additions and 11 deletions
59
spec/components/switch_domain_banner_component_spec.rb
Normal file
59
spec/components/switch_domain_banner_component_spec.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe SwitchDomainBannerComponent, type: :component do
|
||||
let(:app_host_legacy) { "demarches-simplifiees.fr" }
|
||||
let(:app_host) { "demarches.gouv.fr" }
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let(:request_host) { app_host_legacy }
|
||||
let(:path) { "/" }
|
||||
|
||||
before do
|
||||
allow(Current).to receive(:host).and_return(app_host)
|
||||
stub_const("ApplicationHelper::APP_HOST_LEGACY", app_host_legacy)
|
||||
stub_const("ApplicationHelper::APP_HOST", app_host)
|
||||
|
||||
Flipper.enable(:switch_domain)
|
||||
end
|
||||
|
||||
after do
|
||||
Flipper.disable(:switch_domain)
|
||||
end
|
||||
|
||||
subject(:rendered) do
|
||||
with_request_url path, host: request_host, format: nil do
|
||||
render_inline(described_class.new(user: user))
|
||||
end
|
||||
end
|
||||
|
||||
context "when request is already on APP_HOST" do
|
||||
let(:request_host) { app_host }
|
||||
|
||||
it "notify about names change" do
|
||||
expect(rendered.to_html).to include("demarches-simplifiees.fr")
|
||||
expect(rendered.to_html).to include(app_host)
|
||||
expect(rendered.to_html).not_to include("window.location")
|
||||
expect(rendered.to_html).not_to include("Suivez ce lien")
|
||||
end
|
||||
|
||||
context "when user has already set preferred domain" do
|
||||
let(:user) { create(:user, preferred_domain: :demarches_gouv_fr) }
|
||||
|
||||
it "does not render the banner" do
|
||||
expect(rendered.to_html).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "URL generation" do
|
||||
let(:path) { "/admin/procedures" }
|
||||
|
||||
it "generate an url to the new domain" do
|
||||
expect(rendered.to_html).to have_link(APPLICATION_NAME, href: "http://demarches.gouv.fr/admin/procedures")
|
||||
expect(rendered.to_html).not_to include("window.location")
|
||||
expect(rendered.to_html).to include("Suivez ce lien")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue