-
Notifications
You must be signed in to change notification settings - Fork 0
Updates for prefill forms consent project #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
36d7720
Read prefill forms state from new attribute, and added prefill_undeci…
anero f87e6ba
Use new account_id field instead of external_account_id from session …
anero 9ef1427
Added support for /v1/prefill_forms endpoint
anero 254ce13
Fixed format of request to /v1/prefill_forms endpoint
anero bc81cec
Updated example.rb to perform requests to /v1/prefill_forms and to wo…
anero 6d0a0e7
Rename param petition_slug to campaign_slug since it can also be an e…
anero 568e154
Use Faraday's JSON middleware instead of manually setting the content…
anero b425bed
Escape account_id query string param to avoid XSS or URL injection at…
anero 73ddf6c
Ensure that update_prefill_forms returns true when it succeeds
anero 2cb8673
Update comment
anero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| require 'cgi' | ||
|
|
||
| module CampactUserService | ||
| class PrefillForms | ||
| attr_reader :client, :account_id | ||
|
|
||
| def initialize(client, account_id) | ||
| @client = client | ||
| @account_id = account_id | ||
| end | ||
|
|
||
| def update_prefill_forms(prefill_forms_state:, campaign_slug:, **additional_params) | ||
| params = { | ||
| prefill_forms: { | ||
| state: prefill_forms_state, | ||
| slug: campaign_slug | ||
| }.merge(additional_params) | ||
| } | ||
|
|
||
| path = "/v1/prefill_forms?account_id=#{CGI.escape(account_id.to_s)}" | ||
| client.patch_request(path, body: params) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe CampactUserService::PrefillForms do | ||
| let(:client) { CampactUserService::Client.new(host: 'test.com') } | ||
| let(:account_id) { 'abcdef123456fedcba' } | ||
|
|
||
| subject do | ||
| CampactUserService::PrefillForms.new(client, account_id) | ||
| end | ||
|
|
||
| before(:each) do | ||
| WebMock.disable_net_connect! | ||
| end | ||
|
|
||
| describe '#update_prefill_forms' do | ||
| it 'should update the prefill forms state with just the state and petition slug' do | ||
| stub_patch_prefill_forms = stub_request(:patch, "https://test.com/v1/prefill_forms?account_id=#{account_id}") | ||
| .with(body: { | ||
| prefill_forms: { | ||
| state: 'allowed', | ||
| slug: 'save-the-forest' | ||
| } | ||
| }) | ||
| .to_return(status: 204) | ||
|
|
||
| result = subject.update_prefill_forms(prefill_forms_state: 'allowed', campaign_slug: 'save-the-forest') | ||
|
|
||
| assert_requested(stub_patch_prefill_forms) | ||
| expect(result).to be_truthy | ||
| end | ||
|
|
||
| it 'should update the prefill forms state including UTM parameters' do | ||
| utm_params = { | ||
| utm_campaign: 'a campaign', | ||
| utm_content: 'a content', | ||
| utm_medium: 'a medium', | ||
| utm_source: 'a source', | ||
| utm_term: 'a term', | ||
| utm_placement: 'a placement', | ||
| utm_target: 'a target' | ||
| } | ||
| stub_patch_prefill_forms = stub_request(:patch, "https://test.com/v1/prefill_forms?account_id=#{account_id}") | ||
| .with(body: { | ||
| prefill_forms: { | ||
| state: 'allowed', | ||
| slug: 'save-the-forest' | ||
| }.merge(utm_params) | ||
| }) | ||
| .to_return(status: 204) | ||
|
|
||
| subject.update_prefill_forms(prefill_forms_state: 'allowed', campaign_slug: 'save-the-forest', **utm_params) | ||
|
|
||
| assert_requested(stub_patch_prefill_forms) | ||
| end | ||
|
|
||
| it 'should escape special characters in account_id' do | ||
| unescaped_account_id = 'user@example.com' | ||
| escaped_account_id = 'user%40example.com' | ||
|
|
||
| prefill_forms = CampactUserService::PrefillForms.new(client, unescaped_account_id) | ||
|
|
||
| stub_patch_prefill_forms = stub_request(:patch, "https://test.com/v1/prefill_forms?account_id=#{escaped_account_id}") | ||
| .with(body: { | ||
| prefill_forms: { | ||
| state: 'allowed', | ||
| slug: 'save-the-forest' | ||
| } | ||
| }) | ||
| .to_return(status: 204) | ||
|
|
||
| prefill_forms.update_prefill_forms(prefill_forms_state: 'allowed', campaign_slug: 'save-the-forest') | ||
|
|
||
| assert_requested(stub_patch_prefill_forms) | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.