Skip to content

Commit

Permalink
Fix link to worldwide office for translated worldwide organisations
Browse files Browse the repository at this point in the history
We are currently linking the wrong place for worldwide offices on
translated worldwide organisation pages.

E.g. for the content item in the test, we are currrenlty linking to
`/world/uk-embassy-in-country.fr/office/british-embassy`, which results
in a 404 response.
  • Loading branch information
brucebolt committed Feb 21, 2024
1 parent 9b2aaf4 commit 043878e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/presenters/worldwide_organisation_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def main_office
WorldwideOffice.new(
contact: WorldwideOrganisation::LinkedContactPresenter.new(office_contact_item),
has_access_and_opening_times?: office_item["access_and_opening_times"].present?,
public_url: "#{content_item['base_path']}/#{office_item['slug']}",
public_url: "#{content_item['base_path'].gsub(/\..*?$/, '')}/#{office_item['slug']}",
)
end

Expand Down
15 changes: 15 additions & 0 deletions test/presenters/worldwide_organisation_presenter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ def schema_name
assert_nil presented.main_office
end

test "#main_office returns the correct link when the worldwide organisation is not a translation" do
presented = create_presenter(WorldwideOrganisationPresenter, content_item: schema_item)

assert_equal "/world/uk-embassy-in-country/office/british-embassy", presented.main_office.public_url
end

test "#main_office returns the correct link when the worldwide organisation is a translation" do
content_item = schema_item
content_item["base_path"] = "#{content_item['base_path']}.fr"

presented = create_presenter(WorldwideOrganisationPresenter, content_item:)

assert_equal "/world/uk-embassy-in-country/office/british-embassy", presented.main_office.public_url
end

test "#home_page_offices returns an empty array when there are no home page offices" do
without_home_page_offices = schema_item
without_home_page_offices["details"].delete("home_page_office_parts")
Expand Down

0 comments on commit 043878e

Please sign in to comment.