Skip to content

Commit 78f8134

Browse files
committed
Add fake index query in production only suitable for preview apps
1 parent b87e2a8 commit 78f8134

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

+25-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 if Rails.env.production?
5+
46
postcode_lookup = PostcodeLookup.new(postcode)
57

68
if postcode_lookup.local_custodian_codes.count == 1
@@ -15,8 +17,30 @@ def index
1517
render json: { errors: { "postcode": [e.message] } }, status:
1618
end
1719

20+
FAKE_ADDRESS_LIST = [
21+
{ address: "PEARDOWN HOUSE, FENAPPLE CLOSE, BREAM ROAD, WEST THYME, APPLETON, SW1A 2BB", slug: "dorset", name: "Dorset Council" },
22+
{ address: "STRAWBERRY COTTAGE, FENAPPLE CLOSE, BREAM ROAD, WEST THYME, APPLETON, SW1A 2BB", slug: "westminster", name: "City of Westminster" },
23+
].freeze
24+
25+
def fake_index
26+
case postcode
27+
when "BAD"
28+
render json: { errors: { "postcode": I18n.t(LocationError.new("invalidPostcodeFormat").message) } }, status: :bad_request
29+
when "SW1A 2AA"
30+
redirect_to "/api/local-authority/westminster"
31+
when "SW1A 2BB"
32+
render json: { addresses: FAKE_ADDRESS_LIST }
33+
else
34+
render json: { errors: { "postcode": I18n.t(LocationError.new("noLaMatch").message) } }, status: :not_found
35+
end
36+
end
37+
1838
def show
19-
@local_authority = LocalAuthority.from_slug(params[:authority_slug])
39+
@local_authority = if Rails.env.production?
40+
LocalAuthority.new({ "slug" => params[:authority_slug], "name" => params[:authority_slug].gsub("-", " ").titleize, "tier" => "unitary", "homepage_url" => "https://www.gov.uk" })
41+
else
42+
LocalAuthority.from_slug(params[:authority_slug])
43+
end
2044

2145
render json: { local_authority: @local_authority.to_h }
2246
rescue GdsApi::HTTPNotFound

0 commit comments

Comments
 (0)