1
1
module Api
2
2
class LocalAuthorityController < Api ::BaseController
3
3
def index
4
+ return fake_index if Rails . env . production?
5
+
4
6
postcode_lookup = PostcodeLookup . new ( postcode )
5
7
6
8
if postcode_lookup . local_custodian_codes . count == 1
@@ -15,8 +17,30 @@ def index
15
17
render json : { errors : { "postcode" : [ e . message ] } } , status :
16
18
end
17
19
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
+
18
38
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
20
44
21
45
render json : { local_authority : @local_authority . to_h }
22
46
rescue GdsApi ::HTTPNotFound
0 commit comments