-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4648 from DariusPirvulescu/4486-address-pickup-em…
…ail-issues 4486: address pickup email issues
- Loading branch information
Showing
5 changed files
with
116 additions
and
7 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
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
<div class="card-body"> | ||
<%= form.input :pick_up_name, label: "Pick Up Person Name", class: "form-control", wrapper: :input_group %> | ||
<%= form.input :pick_up_phone, label: "Pick Up Person's Phone #", class: "form-control", wrapper: :input_group %> | ||
<%= form.input :pick_up_email, label: "Pick Up Person's Email", class: "form-control", wrapper: :input_group %> | ||
<%= form.input :pick_up_email, label: "Pick Up Person's Email (comma-separated if multiple addresses)", placeholder: "[email protected], [email protected]", class: "form-control", wrapper: :input_group %> | ||
</div> | ||
</div> | ||
</div> | ||
|
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 |
---|---|---|
|
@@ -5,7 +5,8 @@ | |
let(:distribution) { create(:distribution, organization: user.organization, comment: "Distribution comment", partner: partner) } | ||
let(:request) { create(:request, distribution: distribution) } | ||
|
||
let(:pick_up_email) { '[email protected]' } | ||
let(:pick_up_email) { '[email protected], [email protected]' } | ||
let(:pick_up_emails) { ['[email protected]', '[email protected]'] } | ||
|
||
before do | ||
organization.default_email_text = "Default email text example\n\n%{delivery_method} %{distribution_date}\n\n%{partner_name}\n\n%{comment}" | ||
|
@@ -23,7 +24,7 @@ | |
expect(mail.body.encoded).to match("Default email text example") | ||
expect(mail.html_part.body).to match(%(From: <a href="mailto:[email protected]">[email protected]</a>)) | ||
expect(mail.to).to eq([distribution.request.user_email]) | ||
expect(mail.cc).to eq([distribution.partner.email, pick_up_email]) | ||
expect(mail.cc).to eq([distribution.partner.email, pick_up_emails.first, pick_up_emails.second]) | ||
expect(mail.from).to eq(["[email protected]"]) | ||
expect(mail.subject).to eq("test subject from TEST ORG") | ||
end | ||
|
@@ -43,10 +44,11 @@ | |
expect(mail.body.encoded).to match("picked up") | ||
end | ||
|
||
context 'when parners profile pick_up_email is present' do | ||
it 'sends email to the primary contact and partner`s pickup person' do | ||
context 'when partners profile pick_up_email is present' do | ||
it 'sends email to the primary contact and partner`s pickup persons' do | ||
expect(mail.cc.first).to match(partner.email) | ||
expect(mail.cc.second).to match(pick_up_email) | ||
expect(mail.cc.second).to match(pick_up_emails.first) | ||
expect(mail.cc.third).to match(pick_up_emails.second) | ||
end | ||
|
||
context 'when pickup person happens to be the same as the primary contact' do | ||
|
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 |
---|---|---|
|
@@ -167,6 +167,85 @@ | |
end | ||
end | ||
|
||
describe "split pick up email" do | ||
let(:profile) { build(:partner_profile, pick_up_email: "[email protected], [email protected]") } | ||
it "should disregard commas at the beginning or end of the string" do | ||
profile.update(pick_up_email: ", [email protected], [email protected],") | ||
expect(profile.split_pick_up_emails).to match_array(["[email protected]", "[email protected]"]) | ||
end | ||
|
||
it "should allow optional whitespace between email addresses" do | ||
profile.update(pick_up_email: "[email protected], [email protected]") | ||
expect(profile.split_pick_up_emails).to match_array(["[email protected]", "[email protected]"]) | ||
profile.update(pick_up_email: "[email protected],[email protected]") | ||
expect(profile.split_pick_up_emails).to match_array(["[email protected]", "[email protected]"]) | ||
end | ||
|
||
it "should handle nil value" do | ||
profile.update(pick_up_email: nil) | ||
expect(profile.split_pick_up_emails).to be_nil | ||
end | ||
|
||
it "should return empty array if for when pick_up_email is an empty string" do | ||
profile.update(pick_up_email: "") | ||
expect(profile.split_pick_up_emails).to match_array([]) | ||
end | ||
|
||
it "should correctly split strings" do | ||
profile.update(pick_up_email: "test me, [email protected], [email protected], test me") | ||
expect(profile.split_pick_up_emails).to match_array(["test", "me", "[email protected]", "[email protected]", "test", "me"]) | ||
profile.update(pick_up_email: "test me. [email protected], [email protected]. test me") | ||
expect(profile.split_pick_up_emails).to match_array(["test", "me.", "[email protected]", "[email protected].", "test", "me"]) | ||
end | ||
end | ||
|
||
describe "pick up email address validation" do | ||
context "number of email addresses" do | ||
let(:profile) { build(:partner_profile, pick_up_email: "[email protected], [email protected], [email protected], [email protected]") } | ||
it "should not allow more than three email addresses" do | ||
expect(profile).to_not be_valid | ||
profile.update(pick_up_email: "[email protected], [email protected], [email protected]") | ||
expect(profile).to be_valid | ||
end | ||
|
||
it "should not allow repeated email addresses" do | ||
profile.update(pick_up_email: "[email protected], [email protected], [email protected]") | ||
expect(profile).to_not be_valid | ||
end | ||
end | ||
|
||
context "invalid emails" do | ||
let(:profile) { build(:partner_profile, pick_up_email: "[email protected], [email protected], asdf") } | ||
it "should not allow invalid email addresses" do | ||
expect(profile).to_not be_valid | ||
profile.update(pick_up_email: "test me, [email protected], [email protected], test me") | ||
expect(profile).to_not be_valid | ||
profile.update(pick_up_email: "[email protected], [email protected]") | ||
expect(profile).to be_valid | ||
end | ||
|
||
it "should not allow input having emails separated by non-word characters" do | ||
profile.update(pick_up_email: "test me. [email protected], [email protected]. test me") | ||
expect(profile).to_not be_valid | ||
profile.update(pick_up_email: "[email protected]. [email protected]") | ||
expect(profile).to_not be_valid | ||
profile.update(pick_up_email: "[email protected][email protected]") | ||
expect(profile).to_not be_valid | ||
profile.update(pick_up_email: "[email protected]/ [email protected]/ [email protected]") | ||
expect(profile).to_not be_valid | ||
profile.update(pick_up_email: "[email protected] [email protected] [email protected]") | ||
expect(profile).to_not be_valid | ||
profile.update(pick_up_email: "[email protected]' [email protected]' [email protected]") | ||
expect(profile).to_not be_valid | ||
end | ||
|
||
it "should handle nil value" do | ||
profile.update(pick_up_email: nil) | ||
expect(profile).to be_valid | ||
end | ||
end | ||
end | ||
|
||
describe "client share behaviour" do | ||
context "no served areas" do | ||
let(:profile) { build(:partner_profile) } | ||
|