Skip to content

Commit

Permalink
Merge pull request #53 from alphagov/set-di-environment
Browse files Browse the repository at this point in the history
Use GOVUK_ENVIRONMENT as a backstop for DIGITAL_IDENTITY_ENVIRONMENT
  • Loading branch information
KludgeKML authored Jul 10, 2023
2 parents d535d66 + dfbcacc commit eb85ccc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/govuk_personalisation/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,16 @@ def self.find_external_url(var:, url:)
#
# @return [String] the domain
def self.digital_identity_domain
environment = ENV["DIGITAL_IDENTITY_ENVIRONMENT"]
if environment
"home.#{environment}.account.gov.uk"
if digital_identity_environment
"home.#{digital_identity_environment}.account.gov.uk"
else
"home.account.gov.uk"
end
end

def self.digital_identity_environment
return ENV["DIGITAL_IDENTITY_ENVIRONMENT"] if ENV["DIGITAL_IDENTITY_ENVIRONMENT"]

ENV["GOVUK_ENVIRONMENT"] == "production" ? nil : ENV["GOVUK_ENVIRONMENT"]
end
end
44 changes: 44 additions & 0 deletions spec/govuk_personalisation/urls_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,48 @@
end
end
end

describe "#digital_identity_domain" do
subject(:url) { described_class.digital_identity_domain }

it "returns the domain hostname" do
expect(url).to eq("home.account.gov.uk")
end

context "when the DIGITAL_IDENTITY_ENVIRONMENT env var is set" do
around do |example|
ClimateControl.modify("DIGITAL_IDENTITY_ENVIRONMENT" => "production") do
example.run
end
end

it "constructs the hostname from the env var" do
expect(url).to eq("home.production.account.gov.uk")
end
end

context "when the GOVUK_ENVIRONMENT env var is set to production" do
around do |example|
ClimateControl.modify("GOVUK_ENVIRONMENT" => "production") do
example.run
end
end

it "returns the domain hostname" do
expect(url).to eq("home.account.gov.uk")
end
end

context "when the GOVUK_ENVIRONMENT env var is not set to production" do
around do |example|
ClimateControl.modify("GOVUK_ENVIRONMENT" => "test") do
example.run
end
end

it "constructs the hostname from the env var" do
expect(url).to eq("home.test.account.gov.uk")
end
end
end
end

0 comments on commit eb85ccc

Please sign in to comment.