Skip to content

Commit 3b05f0f

Browse files
committed
Mock state rep request for testing in development
1 parent 641105f commit 3b05f0f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

app/controllers/tools_controller.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
require "rest_client"
22
require "uri"
33
require "json"
4+
# TODO: remove
5+
require "webmock"
46

57
class ToolsController < ApplicationController
68
include Tooling
9+
# TODO: remove
10+
include WebMock::API
711

812
before_action :set_user
913
before_action :set_action_page
@@ -127,6 +131,25 @@ def email
127131
# This endpoint is hit by the js for state legislator lookup-by-address actions.
128132
# It renders json containing html markup for presentation on the view
129133
def state_reps
134+
# TODO: remove
135+
WebMock.enable!
136+
WebMock.disable_net_connect!(allow_localhost: true)
137+
138+
mock_data = {
139+
"officials" => [{
140+
"name" => "Sponge Bob",
141+
"party" => "Sandy Party",
142+
"emails" => ["[email protected]"]
143+
}]
144+
}
145+
146+
Rails.application.config.google_civic_api_url = "https://civic.example.com"
147+
Rails.application.secrets.google_civic_api_key = "test-key-for-civic-api"
148+
149+
stub_request(:get, "https://civic.example.com/?address=815%20Eddy%20St%2094109&includeOffices=true&key=test-key-for-civic-api&levels=administrativeArea1&roles=legislatorLowerBody")
150+
.to_return(status: 200, body: mock_data.to_json, headers: {})
151+
152+
# end remove
130153
@email_campaign = EmailCampaign.find(params[:email_campaign_id])
131154
@actionPage = @email_campaign.action_page
132155
# TODO: strong params this

0 commit comments

Comments
 (0)