-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathrecipients_spec.rb
62 lines (47 loc) · 2.75 KB
/
recipients_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'spec_helper'
describe SparkPostRails::DeliveryMethod do
before(:each) do
@delivery_method = SparkPostRails::DeliveryMethod.new
end
context "Recipients" do
context "single recipient" do
it "handles email only" do
test_email = Mailer.test_email
@delivery_method.deliver!(test_email)
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}})])
end
it "handles name and email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>"
@delivery_method.deliver!(test_email)
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}})])
end
end
context "multiple recipients" do
it "handles email only" do
test_email = Mailer.test_email to: "[email protected], [email protected]"
@delivery_method.deliver!(test_email)
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", header_to: anything}})])
end
it "handles name and email" do
test_email = Mailer.test_email to: "Sam Test <[email protected]>, Joe Test <[email protected]>"
@delivery_method.deliver!(test_email)
expect(@delivery_method.data[:recipients]).to match([a_hash_including({:address=>{:email=>"[email protected]", :name=>"Sam Test", header_to: anything}}),
a_hash_including({:address=>{:email=>"[email protected]", :name=>"Joe Test", header_to: anything}})])
end
it "handles mix of email only and name/email" do
test_email = Mailer.test_email to: "Sam Test <[email protected]>, [email protected]"
@delivery_method.deliver!(test_email)
expect(@delivery_method.data[:recipients]).to match_array([a_hash_including({:address=>{:email=>"[email protected]", :name=>"Sam Test", header_to: anything}}),
a_hash_including({:address=>{:email=>"[email protected]", header_to: anything}})])
end
it "compiles list of email addresses to populate :header_to for each recipient" do
expected_header_to = "[email protected],[email protected]"
test_email = Mailer.test_email to: "a <[email protected]>, [email protected]"
@delivery_method.deliver!(test_email)
expect(@delivery_method.data[:recipients].first[:address][:header_to]).to eql(expected_header_to)
expect(@delivery_method.data[:recipients].second[:address][:header_to]).to eql(expected_header_to)
end
end
end
end