-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathsubaccount_api_spec.rb
75 lines (56 loc) · 2.26 KB
/
subaccount_api_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
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'spec_helper'
describe SparkPostRails::DeliveryMethod do
before(:each) do
SparkPostRails.configuration.set_defaults
@delivery_method = SparkPostRails::DeliveryMethod.new
end
context "Message-Specific API Key" do
it "uses supplied API key instead of default" do
SparkPostRails.configure do |c|
c.api_key = 'NEW_DEFAULT_API_KEY'
end
test_email = Mailer.test_email sparkpost_data: {api_key: 'SUBACCOUNT_API_KEY'}
@delivery_method.deliver!(test_email)
expect(@delivery_method.headers).to include("Authorization" => "SUBACCOUNT_API_KEY")
end
it "uses default API if no message-specific API key applied" do
SparkPostRails.configure do |c|
c.api_key = 'NEW_DEFAULT_API_KEY'
end
test_email = Mailer.test_email
@delivery_method.deliver!(test_email)
expect(@delivery_method.headers).to include("Authorization" => "NEW_DEFAULT_API_KEY")
end
end
context "Subaccount ID" do
it "accepts a subaccount ID in the configuration" do
SparkPostRails.configure do |c|
c.subaccount = 123
end
test_email = Mailer.test_email
@delivery_method.deliver!(test_email)
expect(@delivery_method.headers).to include("X-MSYS-SUBACCOUNT" => "123")
end
it "defaults to no subaccount ID in the configuration" do
expect(SparkPostRails.configuration.subaccount).to eq(nil)
end
it "accepts subaccount ID for an individual message" do
test_email = Mailer.test_email sparkpost_data: {subaccount: 456}
@delivery_method.deliver!(test_email)
expect(@delivery_method.headers).to include("X-MSYS-SUBACCOUNT" => "456")
end
it "uses subaccount ID on message instead of value in configuration" do
SparkPostRails.configure do |c|
c.subaccount = 123
end
test_email = Mailer.test_email sparkpost_data: {subaccount: 456}
@delivery_method.deliver!(test_email)
expect(@delivery_method.headers).to include("X-MSYS-SUBACCOUNT" => "456")
end
it "does not include the subaccount header when none is specified" do
test_email = Mailer.test_email
@delivery_method.deliver!(test_email)
expect(@delivery_method.headers.has_key?("X-MSYS-SUBACCOUNT")).to eq(false)
end
end
end