Skip to content

Commit 5ef72b1

Browse files
committed
Add fake index and LA queries in production only (suitable for preview apps)
1 parent cb275a4 commit 5ef72b1

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Diff for: app/controllers/api/local_authority_controller.rb

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module Api
22
class LocalAuthorityController < Api::BaseController
33
def index
4+
return fake_index_query if Rails.env.production?
5+
46
postcode_lookup = PostcodeLookup.new(postcode)
57

68
if postcode_lookup.local_custodian_codes.count == 1
@@ -16,7 +18,7 @@ def index
1618
end
1719

1820
def show
19-
@local_authority = LocalAuthority.from_slug(params[:authority_slug])
21+
@local_authority = Rails.env.production? ? fake_local_authority : LocalAuthority.from_slug(params[:authority_slug])
2022

2123
render json: { local_authority: @local_authority.to_h }
2224
rescue GdsApi::HTTPNotFound
@@ -25,6 +27,38 @@ def show
2527

2628
private
2729

30+
FAKE_ADDRESS_LIST = [
31+
{ address: "PEARDOWN HOUSE, FENAPPLE CLOSE, BREAM ROAD, WEST THYME, APPLETON, SW1A 2BB", slug: "dorset", name: "Dorset Council" },
32+
{ address: "STRAWBERRY COTTAGE, FENAPPLE CLOSE, BREAM ROAD, WEST THYME, APPLETON, SW1A 2BB", slug: "westminster", name: "City of Westminster" },
33+
].freeze
34+
35+
def fake_index_query
36+
raise LocationError, "invalidPostcodeFormat" if postcode.blank?
37+
38+
case postcode
39+
when "BAD"
40+
raise LocationError, "invalidPostcodeFormat"
41+
when "SW1A 2AA"
42+
redirect_to "/api/local-authority/westminster"
43+
when "SW1A 2BB"
44+
render json: { addresses: FAKE_ADDRESS_LIST }
45+
else
46+
raise LocationError, "noLaMatch"
47+
end
48+
end
49+
50+
def fake_local_authority
51+
case params[:authority_slug]
52+
when "missing"
53+
raise GdsApi::HTTPNotFound
54+
when "derbyshire-dales"
55+
parent = LocalAuthority.new({ "slug" => "derbyshire", "name" => "Derbyshire County Council", "tier" => "county", "homepage_url" => "https://www.gov.uk" })
56+
LocalAuthority.new({ "slug" => "derbyshire-dales", "name" => "Derbyshire Dales District Council", "tier" => "district", "homepage_url" => "https://www.gov.uk", "parent" => parent })
57+
else
58+
LocalAuthority.new({ "slug" => params[:authority_slug], "name" => params[:authority_slug].gsub("-", " ").titleize, "tier" => "unitary", "homepage_url" => "https://www.gov.uk" })
59+
end
60+
end
61+
2862
def postcode
2963
@postcode ||= PostcodeSanitizer.sanitize(params[:postcode])
3064
end

0 commit comments

Comments
 (0)