-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add missing data_authorization_handler form (#145)
- Loading branch information
Showing
4 changed files
with
356 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,51 @@ | ||
<%= form.hidden_field :handler_name %> | ||
<div class="help-text help-text-form-required-fields"> | ||
* <%= t('decidim.authorization_handlers.data_authorization_handler.help_text.required_fields') %> | ||
</div> | ||
<div class="row"> | ||
<div class="columns medium-6"> | ||
<div class="field lastname_field"> | ||
<%= form.text_field :lastname, label: I18n.t('decidim.authorization_handlers.data_authorization_handler.fields.lastname')%> | ||
<p class="help-text"><%= I18n.t('decidim.authorization_handlers.data_authorization_handler.help_text.lastname') %></p> | ||
</div> | ||
</div> | ||
<div class="columns medium-6"> | ||
<div class="field firstname_field"> | ||
<%= form.text_field :firstname, label: I18n.t('decidim.authorization_handlers.data_authorization_handler.fields.firstname')%> | ||
<p class="help-text"><%= I18n.t('decidim.authorization_handlers.data_authorization_handler.help_text.firstname') %></p> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="columns medium-4"> | ||
<div class="field postal_code_field"> | ||
<%= form.text_field :postal_code, label: I18n.t('decidim.authorization_handlers.data_authorization_handler.fields.postal_code'), maxlength: 5, pattern: "[0-9]{5}" %> | ||
<p class="help-text"><%= I18n.t('decidim.authorization_handlers.data_authorization_handler.help_text.postal_code') %></p> | ||
</div> | ||
</div> | ||
<div class="columns medium-8"> | ||
<div class="field city_field"> | ||
<%= form.text_field :city, label: I18n.t('decidim.authorization_handlers.data_authorization_handler.fields.city') %> | ||
<p class="help-text"><%= I18n.t('decidim.authorization_handlers.data_authorization_handler.help_text.city') %></p> | ||
</div> | ||
</div> | ||
</div> | ||
<fieldset class="fieldset"> | ||
<legend class="legend"><%= I18n.t('decidim.authorization_handlers.data_authorization_handler.legend') %></legend> | ||
<div class="row"> | ||
<div class="field phone_field columns medium-12"> | ||
<%= form.text_field :phone, label: I18n.t('decidim.authorization_handlers.data_authorization_handler.fields.phone') %> | ||
</div> | ||
</div> | ||
</fieldset> | ||
<div class="field gdpr_field"> | ||
<%= form.check_box :gdpr, label: I18n.t('decidim.authorization_handlers.data_authorization_handler.fields.gdpr') %> | ||
</div> | ||
<div class="field minimum_age_field"> | ||
<%= form.check_box :minimum_age, label: I18n.t('decidim.authorization_handlers.data_authorization_handler.fields.minimum_age') %> | ||
</div> | ||
<div class="padding-2"> | ||
<strong><%= I18n.t('decidim.authorization_handlers.data_authorization_handler.help_text.global_help')%></strong> | ||
</div> | ||
|
||
<%= javascript_pack_tag "extended_socio_demographic_authorization_handler" %> |
This file contains 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 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 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,269 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
describe "Data authorization", type: :system do | ||
let(:organization) { create(:organization, available_authorizations: ["data_authorization_handler"]) } | ||
let(:user) { create(:user, :confirmed, organization: organization) } | ||
let(:firstname) { "John" } | ||
let(:lastname) { "Doe" } | ||
let(:phone) { "0605040302" } | ||
let(:postal_code) { "75001" } | ||
let(:city) { "Paris 1er Arrondissement" } | ||
let(:gdpr) { true } | ||
let(:minimum_age) { true } | ||
let(:response_body) do | ||
JSON.dump([{ "75001" => "Paris 1er Arrondissement" }]) | ||
end | ||
let(:stubbed_request) do | ||
stub_request(:get, "/postal-code-autocomplete/75001").to_return(status: 200, body: response_body, headers: {}) | ||
stub_request(:get, "https://apicarto.ign.fr/api/codes-postaux/communes/75001").to_return(status: 200, body: response_body, headers: {}) | ||
end | ||
|
||
before do | ||
switch_to_host(organization.host) | ||
login_as user, scope: :user | ||
visit decidim_verifications.authorizations_path | ||
click_link("Data Sharing Process") | ||
stubbed_request | ||
end | ||
|
||
it "can be authorized" do | ||
expect(page).to have_content("Data Sharing Process") | ||
end | ||
|
||
context "when the form is filled in correctly" do | ||
before do | ||
fill_in :authorization_handler_firstname, with: firstname | ||
fill_in :authorization_handler_lastname, with: lastname | ||
fill_in :authorization_handler_phone, with: phone | ||
fill_in :authorization_handler_postal_code, with: postal_code | ||
fill_in :authorization_handler_city, with: city | ||
check :authorization_handler_gdpr | ||
check :authorization_handler_minimum_age | ||
click_button "Send" | ||
end | ||
|
||
shared_examples_for "is a valid firstname" do | ||
it "is valid" do | ||
expect(page).to have_content("successfully") | ||
end | ||
end | ||
|
||
context "when the firstname is valid" do | ||
let(:firstname) { "John" } | ||
|
||
it_behaves_like "is a valid firstname" | ||
end | ||
|
||
context "when the firstname contains ' or -" do | ||
let(:firstname) { "Jo-hn's" } | ||
|
||
it_behaves_like "is a valid firstname" | ||
end | ||
|
||
context "when the firstname contains a space" do | ||
let(:firstname) { "John Doe" } | ||
|
||
it_behaves_like "is a valid firstname" | ||
end | ||
|
||
context "when the firstname contains an accent" do | ||
let(:firstname) { "Jöhn Tâylot" } | ||
|
||
it_behaves_like "is a valid firstname" | ||
end | ||
|
||
shared_examples_for "is a valid lastname" do | ||
it "is valid" do | ||
expect(page).to have_content("successfully") | ||
end | ||
end | ||
|
||
context "when the lastname is valid" do | ||
let(:lastname) { "Doe" } | ||
|
||
it_behaves_like "is a valid lastname" | ||
end | ||
|
||
context "when the lastname contains ' or -" do | ||
let(:lastname) { "Do-e's" } | ||
|
||
it_behaves_like "is a valid lastname" | ||
end | ||
|
||
context "when the lastname contains a space" do | ||
let(:lastname) { "Doe John" } | ||
|
||
it_behaves_like "is a valid lastname" | ||
end | ||
|
||
context "when the lastname contains accents" do | ||
let(:lastname) { "Maël-Taylôr" } | ||
|
||
it_behaves_like "is a valid lastname" | ||
end | ||
|
||
it "authorizes the user" do | ||
expect(page).to have_content("successfully") | ||
end | ||
end | ||
|
||
context "when the form is filled in incorrectly" do | ||
before do | ||
fill_in :authorization_handler_firstname, with: firstname | ||
fill_in :authorization_handler_lastname, with: lastname | ||
fill_in :authorization_handler_phone, with: phone | ||
fill_in :authorization_handler_postal_code, with: postal_code | ||
fill_in :authorization_handler_city, with: city | ||
check :authorization_handler_gdpr | ||
check :authorization_handler_minimum_age | ||
end | ||
|
||
shared_examples_for "is an invalid firstname" do | ||
it "is invalid" do | ||
expect(page).to have_content("contains an error") | ||
end | ||
end | ||
|
||
context "when the firstname contains number" do | ||
let(:firstname) { "John1" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it_behaves_like "is an invalid firstname" | ||
end | ||
|
||
context "when the firstname contains special characters" do | ||
let(:firstname) { "John@" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it_behaves_like "is an invalid firstname" | ||
end | ||
|
||
shared_examples_for "is an invalid lastname" do | ||
it "is invalid" do | ||
expect(page).to have_content("contains an error") | ||
end | ||
end | ||
|
||
context "when the lastname contains number" do | ||
let(:lastname) { "Doe1" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it_behaves_like "is an invalid lastname" | ||
end | ||
|
||
context "when the lastname contains special characters" do | ||
let(:lastname) { "Doe@" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it_behaves_like "is an invalid lastname" | ||
end | ||
|
||
describe "when the name is empty" do | ||
let(:lastname) { "" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it "does not authorize the user" do | ||
expect(page).to have_content("error") | ||
end | ||
end | ||
|
||
describe "when the firstname is empty" do | ||
let(:firstname) { "" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it "does not authorize the user" do | ||
expect(page).to have_content("error") | ||
end | ||
end | ||
|
||
describe "when the phone number is empty" do | ||
let(:phone) { "" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it "does not authorize the user" do | ||
expect(page).to have_content("error") | ||
end | ||
end | ||
|
||
describe "when no postal code is entered" do | ||
let(:postal_code) { "" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it "does not authorize the user" do | ||
expect(page).to have_content("error") | ||
end | ||
end | ||
|
||
describe "when the postal_code is invalid" do | ||
let(:postal_code) { "1234" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it "does not authorize the user" do | ||
expect(page).to have_content("error") | ||
end | ||
end | ||
|
||
describe "when the city is empty" do | ||
let(:city) { "" } | ||
|
||
before do | ||
click_button "Send" | ||
end | ||
|
||
it "does not authorize the user" do | ||
expect(page).to have_content("error") | ||
end | ||
end | ||
|
||
describe "when gdpr is not checked" do | ||
before do | ||
uncheck :authorization_handler_gdpr | ||
click_button "Send" | ||
end | ||
|
||
it "does not authorize the user" do | ||
expect(page).to have_content("must be accepted") | ||
end | ||
end | ||
|
||
describe "when minimum age is not checked" do | ||
before do | ||
uncheck :authorization_handler_minimum_age | ||
click_button "Send" | ||
end | ||
|
||
it "does not authorize the user" do | ||
expect(page).to have_content("must be accepted") | ||
end | ||
end | ||
end | ||
end |