govdelivery-tms 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -5
- data/README.md +0 -32
- data/Rakefile +4 -6
- data/govdelivery-tms.gemspec +15 -15
- data/lib/govdelivery-tms.rb +0 -9
- data/lib/govdelivery/tms/base.rb +4 -6
- data/lib/govdelivery/tms/client.rb +15 -16
- data/lib/govdelivery/tms/collection_resource.rb +7 -8
- data/lib/govdelivery/tms/connection.rb +4 -4
- data/lib/govdelivery/tms/errors.rb +7 -8
- data/lib/govdelivery/tms/instance_resource.rb +34 -39
- data/lib/govdelivery/tms/link_header.rb +27 -28
- data/lib/govdelivery/tms/mail/delivery_method.rb +11 -14
- data/lib/govdelivery/tms/resource/collections.rb +0 -20
- data/lib/govdelivery/tms/resource/command.rb +1 -2
- data/lib/govdelivery/tms/resource/command_action.rb +1 -1
- data/lib/govdelivery/tms/resource/command_type.rb +8 -9
- data/lib/govdelivery/tms/resource/email_message.rb +0 -1
- data/lib/govdelivery/tms/resource/email_recipient.rb +1 -1
- data/lib/govdelivery/tms/resource/from_address.rb +1 -1
- data/lib/govdelivery/tms/resource/inbound_sms_message.rb +1 -1
- data/lib/govdelivery/tms/resource/keyword.rb +6 -7
- data/lib/govdelivery/tms/resource/recipient.rb +1 -1
- data/lib/govdelivery/tms/resource/sms_message.rb +0 -1
- data/lib/govdelivery/tms/util/core_ext.rb +3 -3
- data/lib/govdelivery/tms/util/hal_link_parser.rb +11 -12
- data/lib/govdelivery/tms/version.rb +1 -1
- data/spec/client_spec.rb +6 -6
- data/spec/command_types_spec.rb +14 -14
- data/spec/email_message_spec.rb +42 -45
- data/spec/email_template_spec.rb +49 -51
- data/spec/errors_spec.rb +3 -3
- data/spec/from_address_spec.rb +37 -36
- data/spec/inbound_sms_messages_spec.rb +2 -2
- data/spec/instance_resource_spec.rb +4 -6
- data/spec/keyword_spec.rb +8 -10
- data/spec/keywords_spec.rb +4 -4
- data/spec/mail/delivery_method_spec.rb +8 -9
- data/spec/sms_message_spec.rb +9 -11
- data/spec/sms_messages_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -5
- data/spec/tms_spec.rb +3 -3
- metadata +34 -64
- data/lib/govdelivery/tms/resource/ipaws_acknowledgement.rb +0 -9
- data/lib/govdelivery/tms/resource/ipaws_alert.rb +0 -38
- data/lib/govdelivery/tms/resource/ipaws_category.rb +0 -7
- data/lib/govdelivery/tms/resource/ipaws_cog_profile.rb +0 -29
- data/lib/govdelivery/tms/resource/ipaws_event_code.rb +0 -7
- data/lib/govdelivery/tms/resource/ipaws_nwem_area.rb +0 -18
- data/lib/govdelivery/tms/resource/ipaws_nwem_authorization.rb +0 -9
- data/lib/govdelivery/tms/resource/ipaws_nwem_auxilary_data.rb +0 -8
- data/lib/govdelivery/tms/resource/ipaws_response_type.rb +0 -7
- data/lib/govdelivery/tms/resource/ipaws_static_resource.rb +0 -8
- data/spec/ipaws_acknowledgement_spec.rb +0 -16
- data/spec/ipaws_alerts_spec.rb +0 -192
- data/spec/ipaws_cog_profile_spec.rb +0 -75
- data/spec/ipaws_event_codes_spec.rb +0 -35
- data/spec/ipaws_nwem_areas_spec.rb +0 -58
- data/spec/ipaws_nwem_authorization_spec.rb +0 -16
data/spec/client_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe GovDelivery::TMS::Client do
|
3
|
-
context
|
3
|
+
context 'creating a new client' do
|
4
4
|
before do
|
5
|
-
response = double('response', status: 200, body: {
|
5
|
+
response = double('response', status: 200, body: { '_links' => [{ 'self' => '/' }, { 'horse' => '/horses/new' }, { 'rabbits' => '/rabbits' }] })
|
6
6
|
@raw_connection = double('raw_connection', get: response)
|
7
7
|
@connection = allow(GovDelivery::TMS::Connection).to receive(:new).and_return(double('connection', connection: @raw_connection))
|
8
8
|
@client = GovDelivery::TMS::Client.new('auth_token', api_root: 'null_url')
|
@@ -16,21 +16,21 @@ describe GovDelivery::TMS::Client do
|
|
16
16
|
expect(@client.rabbits).to be_kind_of(GovDelivery::TMS::Rabbits)
|
17
17
|
end
|
18
18
|
it 'should handle 4xx responses' do
|
19
|
-
allow(@raw_connection).to receive(:get).and_return(double('response', status: 404, body: {'message' => 'hi'}))
|
19
|
+
allow(@raw_connection).to receive(:get).and_return(double('response', status: 404, body: { 'message' => 'hi' }))
|
20
20
|
expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::Error)
|
21
21
|
end
|
22
22
|
it 'should handle 5xx responses' do
|
23
|
-
allow(@raw_connection).to receive(:get).and_return(double('response', status: 503, body: {'message' => 'oops'}))
|
23
|
+
allow(@raw_connection).to receive(:get).and_return(double('response', status: 503, body: { 'message' => 'oops' }))
|
24
24
|
expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::Error)
|
25
25
|
end
|
26
26
|
it 'should handle 202 responses' do
|
27
|
-
allow(@raw_connection).to receive(:get).and_return(double('response', status: 202, body: {'message' => 'hi'}))
|
27
|
+
allow(@raw_connection).to receive(:get).and_return(double('response', status: 202, body: { 'message' => 'hi' }))
|
28
28
|
expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::InProgress)
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'creating a new client without output' do
|
32
32
|
subject { GovDelivery::TMS::Client.new('auth_token', api_root: 'null_url', logger: false) }
|
33
|
-
its(:logger){ should be_falsey }
|
33
|
+
its(:logger) { should be_falsey }
|
34
34
|
its(:horse) { should be_kind_of(GovDelivery::TMS::Horse) }
|
35
35
|
end
|
36
36
|
|
data/spec/command_types_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GovDelivery::TMS::CommandTypes do
|
4
|
-
context
|
4
|
+
context 'loading command types' do
|
5
5
|
let(:client) do
|
6
6
|
double('client')
|
7
7
|
end
|
@@ -9,21 +9,21 @@ describe GovDelivery::TMS::CommandTypes do
|
|
9
9
|
@command_types = GovDelivery::TMS::CommandTypes.new(client, '/command_types')
|
10
10
|
end
|
11
11
|
it 'should GET ok' do
|
12
|
-
body = [{
|
13
|
-
|
14
|
-
|
15
|
-
{
|
16
|
-
|
17
|
-
|
18
|
-
{
|
19
|
-
|
20
|
-
|
12
|
+
body = [{ 'name' => 'dcm_unsubscribe',
|
13
|
+
'string_fields' => [],
|
14
|
+
'array_fields' => ['dcm_account_codes'] },
|
15
|
+
{ 'name' => 'dcm_subscribe',
|
16
|
+
'string_fields' => ['dcm_account_code'],
|
17
|
+
'array_fields' => ['dcm_topic_codes'] },
|
18
|
+
{ 'name' => 'forward',
|
19
|
+
'string_fields' => %w(http_method username password url),
|
20
|
+
'array_fields' => [] }]
|
21
21
|
expect(@command_types.client).to receive(:get).and_return(double('response', body: body, status: 200, headers: {}))
|
22
22
|
@command_types.get
|
23
23
|
expect(@command_types.collection.length).to eq(3)
|
24
|
-
ct = @command_types.collection.find{|c| c.name ==
|
25
|
-
expect(ct.array_fields).to eq([
|
26
|
-
expect(ct.string_fields).to eq([
|
24
|
+
ct = @command_types.collection.find { |c| c.name == 'dcm_subscribe' }
|
25
|
+
expect(ct.array_fields).to eq(['dcm_topic_codes'])
|
26
|
+
expect(ct.string_fields).to eq(['dcm_account_code'])
|
27
27
|
end
|
28
28
|
end
|
29
|
-
end
|
29
|
+
end
|
data/spec/email_message_spec.rb
CHANGED
@@ -1,51 +1,50 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GovDelivery::TMS::EmailMessage do
|
4
|
-
context
|
4
|
+
context 'creating a new message' do
|
5
5
|
let(:client) do
|
6
6
|
double('client')
|
7
7
|
end
|
8
8
|
before do
|
9
|
-
@message = GovDelivery::TMS::EmailMessage.new(client, '/messages/email',
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
reply_to: 'replyto@evotest.govdelivery.com'})
|
9
|
+
@message = GovDelivery::TMS::EmailMessage.new(client, '/messages/email', body: '12345678',
|
10
|
+
subject: 'blah',
|
11
|
+
created_at: 'BAAAAAD',
|
12
|
+
from_email: 'eric@evotest.govdelivery.com',
|
13
|
+
errors_to: 'errors@evotest.govdelivery.com',
|
14
|
+
reply_to: 'replyto@evotest.govdelivery.com')
|
16
15
|
end
|
17
16
|
it 'should not render readonly attrs in json hash' do
|
18
17
|
expect(@message.to_json[:body]).to eq('12345678')
|
19
18
|
expect(@message.to_json[:created_at]).to eq(nil)
|
20
19
|
end
|
21
20
|
it 'should initialize with attrs and collections' do
|
22
|
-
expect(@message.body).to
|
23
|
-
expect(@message.subject).to
|
24
|
-
expect(@message.from_email).to
|
25
|
-
expect(@message.reply_to).to
|
26
|
-
expect(@message.errors_to).to
|
21
|
+
expect(@message.body).to eq('12345678')
|
22
|
+
expect(@message.subject).to eq('blah')
|
23
|
+
expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
|
24
|
+
expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
|
25
|
+
expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
|
27
26
|
expect(@message.recipients.class).to eq(GovDelivery::TMS::EmailRecipients)
|
28
27
|
end
|
29
28
|
it 'should post successfully' do
|
30
29
|
response = {
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
body: 'processed',
|
31
|
+
subject: 'blah',
|
32
|
+
from_email: 'eric@evotest.govdelivery.com',
|
33
|
+
errors_to: 'errors@evotest.govdelivery.com',
|
34
|
+
reply_to: 'replyto@evotest.govdelivery.com',
|
35
|
+
recipients: [{ email: 'billy@evotest.govdelivery.com' }],
|
36
|
+
failed: [{ email: 'billy@evotest.govdelivery.com' }],
|
37
|
+
sent: [{ email: 'billy@evotest.govdelivery.com' }],
|
38
|
+
created_at: 'time'
|
40
39
|
}
|
41
40
|
expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 201, body: response))
|
42
41
|
@message.post
|
43
|
-
expect(@message.body).to
|
44
|
-
expect(@message.created_at).to
|
45
|
-
expect(@message.from_email).to
|
46
|
-
expect(@message.reply_to).to
|
47
|
-
expect(@message.errors_to).to
|
48
|
-
expect(@message.recipients.class).to
|
42
|
+
expect(@message.body).to eq('processed')
|
43
|
+
expect(@message.created_at).to eq('time')
|
44
|
+
expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
|
45
|
+
expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
|
46
|
+
expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
|
47
|
+
expect(@message.recipients.class).to eq(GovDelivery::TMS::EmailRecipients)
|
49
48
|
expect(@message.recipients.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
|
50
49
|
expect(@message.sent.class).to eq(GovDelivery::TMS::EmailRecipients)
|
51
50
|
expect(@message.sent.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
|
@@ -53,21 +52,21 @@ describe GovDelivery::TMS::EmailMessage do
|
|
53
52
|
expect(@message.failed.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
|
54
53
|
end
|
55
54
|
it 'should handle errors' do
|
56
|
-
response = {'errors' => {body: "can't be nil"}}
|
55
|
+
response = { 'errors' => { body: "can't be nil" } }
|
57
56
|
expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 422, body: response))
|
58
57
|
@message.post
|
59
58
|
expect(@message.body).to eq('12345678')
|
60
|
-
expect(@message.errors).to eq(
|
59
|
+
expect(@message.errors).to eq(body: "can't be nil")
|
61
60
|
end
|
62
61
|
|
63
62
|
it 'should handle 401 errors' do
|
64
63
|
expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 401))
|
65
|
-
expect {@message.post}.to raise_error(StandardError,
|
64
|
+
expect { @message.post }.to raise_error(StandardError, '401 Not Authorized')
|
66
65
|
end
|
67
66
|
|
68
67
|
it 'should handle 404 errors' do
|
69
68
|
expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 404))
|
70
|
-
expect {@message.post}.to raise_error(StandardError, "Can't POST to /messages/email")
|
69
|
+
expect { @message.post }.to raise_error(StandardError, "Can't POST to /messages/email")
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
@@ -80,23 +79,21 @@ describe GovDelivery::TMS::EmailMessage do
|
|
80
79
|
@message = GovDelivery::TMS::EmailMessage.new(client, '/messages/99', {})
|
81
80
|
end
|
82
81
|
it 'should GET cleanly' do
|
83
|
-
response = {body: 'processed',
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
82
|
+
response = { body: 'processed',
|
83
|
+
subject: 'hey',
|
84
|
+
from_email: 'eric@evotest.govdelivery.com',
|
85
|
+
errors_to: 'errors@evotest.govdelivery.com',
|
86
|
+
reply_to: 'replyto@evotest.govdelivery.com',
|
87
|
+
recipients: [{ email: 'billy@evotest.govdelivery.com' }],
|
88
|
+
created_at: 'time' }
|
90
89
|
expect(@message.client).to receive('get').with(@message.href).and_return(double('response', status: 200, body: response))
|
91
90
|
@message.get
|
92
|
-
expect(@message.body).to
|
93
|
-
expect(@message.subject).to
|
91
|
+
expect(@message.body).to eq('processed')
|
92
|
+
expect(@message.subject).to eq('hey')
|
94
93
|
expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
|
95
|
-
expect(@message.reply_to).to
|
96
|
-
expect(@message.errors_to).to
|
94
|
+
expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
|
95
|
+
expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
|
97
96
|
expect(@message.created_at).to eq('time')
|
98
97
|
end
|
99
98
|
end
|
100
|
-
|
101
|
-
|
102
99
|
end
|
data/spec/email_template_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GovDelivery::TMS::EmailTemplate do
|
4
|
-
context
|
4
|
+
context 'creating a list of email templates' do
|
5
5
|
let(:client) do
|
6
6
|
double('client')
|
7
7
|
end
|
@@ -12,15 +12,15 @@ describe GovDelivery::TMS::EmailTemplate do
|
|
12
12
|
it 'should be able to get a list of email templates' do
|
13
13
|
response = [
|
14
14
|
{
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
'id' => '1',
|
16
|
+
'body' => 'Template 1',
|
17
|
+
'subject' => 'This is the template 1 subject',
|
18
|
+
'link_tracking_parameters' => 'test=ok&hello=world',
|
19
|
+
'macros' => { 'MACRO1' => '1' },
|
20
|
+
'open_tracking_enabled' => true,
|
21
|
+
'click_tracking_enabled' => true,
|
22
|
+
'created_at' => 'sometime',
|
23
|
+
'_links' => { 'self' => '/templates/email/1', 'account' => '/accounts/1', 'from_address' => '/from_addresses/1' }
|
24
24
|
}
|
25
25
|
]
|
26
26
|
|
@@ -30,31 +30,29 @@ describe GovDelivery::TMS::EmailTemplate do
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
33
|
+
context 'creating an email template' do
|
34
34
|
let(:client) do
|
35
35
|
double('client')
|
36
36
|
end
|
37
37
|
before do
|
38
|
-
@template = GovDelivery::TMS::EmailTemplate.new(client, '/templates/email',
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
click_tracking_enabled: true,
|
45
|
-
})
|
38
|
+
@template = GovDelivery::TMS::EmailTemplate.new(client, '/templates/email', body: 'Template 1',
|
39
|
+
subject: 'This is the template 1 subject',
|
40
|
+
link_tracking_parameters: 'test=ok&hello=world',
|
41
|
+
macros: { 'MACRO1' => '1' },
|
42
|
+
open_tracking_enabled: true,
|
43
|
+
click_tracking_enabled: true)
|
46
44
|
end
|
47
45
|
|
48
46
|
it 'should render linkable attrs in json hash' do
|
49
|
-
@template.links[:from_address] =
|
50
|
-
@template.links[:invalid] =
|
47
|
+
@template.links[:from_address] = '1'
|
48
|
+
@template.links[:invalid] = '2'
|
51
49
|
links = @template.to_json[:_links]
|
52
50
|
expect(links[:from_address]).to eq('1')
|
53
51
|
expect(links[:invalid]).to be_nil
|
54
52
|
end
|
55
53
|
|
56
54
|
it 'should clear the links property after a successful post' do
|
57
|
-
@template.links[:from_address] =
|
55
|
+
@template.links[:from_address] = '1'
|
58
56
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 201, body: {}))
|
59
57
|
@template.post
|
60
58
|
links = @template.to_json[:_links]
|
@@ -62,40 +60,40 @@ describe GovDelivery::TMS::EmailTemplate do
|
|
62
60
|
end
|
63
61
|
|
64
62
|
it 'should not clear the links property after an invalid post' do
|
65
|
-
@template.links[:from_address] =
|
63
|
+
@template.links[:from_address] = '1'
|
66
64
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 400, body: {}))
|
67
65
|
@template.post
|
68
66
|
links = @template.to_json[:_links]
|
69
|
-
expect(links[:from_address]).to eq(
|
67
|
+
expect(links[:from_address]).to eq('1')
|
70
68
|
end
|
71
69
|
|
72
70
|
it 'should post successfully' do
|
73
71
|
response = {
|
74
|
-
'id' =>
|
75
|
-
'body' =>
|
76
|
-
'subject' =>
|
77
|
-
'link_tracking_parameters' =>
|
78
|
-
'macros' => {
|
72
|
+
'id' => '1',
|
73
|
+
'body' => 'Template 1',
|
74
|
+
'subject' => 'This is the template 1 subject',
|
75
|
+
'link_tracking_parameters' => 'test=ok&hello=world',
|
76
|
+
'macros' => { 'MACRO1' => '1' },
|
79
77
|
'open_tracking_enabled' => true,
|
80
78
|
'click_tracking_enabled' => true,
|
81
|
-
'created_at' =>
|
82
|
-
'_links' => {
|
79
|
+
'created_at' => 'sometime',
|
80
|
+
'_links' => { 'self' => '/templates/email/1', 'account' => '/accounts/1', 'from_address' => '/from_addresses/1' }
|
83
81
|
}
|
84
82
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 201, body: response))
|
85
83
|
@template.post
|
86
|
-
expect(@template.id).to
|
87
|
-
expect(@template.body).to
|
88
|
-
expect(@template.subject).to
|
89
|
-
expect(@template.link_tracking_parameters).to
|
90
|
-
expect(@template.macros).to
|
91
|
-
expect(@template.open_tracking_enabled).to
|
92
|
-
expect(@template.click_tracking_enabled).to
|
93
|
-
expect(@template.created_at).to
|
94
|
-
expect(@template.from_address).to
|
84
|
+
expect(@template.id).to eq('1')
|
85
|
+
expect(@template.body).to eq('Template 1')
|
86
|
+
expect(@template.subject).to eq('This is the template 1 subject')
|
87
|
+
expect(@template.link_tracking_parameters).to eq('test=ok&hello=world')
|
88
|
+
expect(@template.macros).to eq('MACRO1' => '1')
|
89
|
+
expect(@template.open_tracking_enabled).to eq(true)
|
90
|
+
expect(@template.click_tracking_enabled).to eq(true)
|
91
|
+
expect(@template.created_at).to eq('sometime')
|
92
|
+
expect(@template.from_address).to be_a(GovDelivery::TMS::FromAddress)
|
95
93
|
end
|
96
94
|
end
|
97
95
|
|
98
|
-
context
|
96
|
+
context 'handling errors at the template level' do
|
99
97
|
let(:client) do
|
100
98
|
double('client')
|
101
99
|
end
|
@@ -104,24 +102,24 @@ describe GovDelivery::TMS::EmailTemplate do
|
|
104
102
|
end
|
105
103
|
|
106
104
|
it 'should handle errors' do
|
107
|
-
response = {'errors' => {body: "can't be nil"}}
|
105
|
+
response = { 'errors' => { body: "can't be nil" } }
|
108
106
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 422, body: response))
|
109
107
|
@template.post
|
110
|
-
expect(@template.errors).to eq(
|
108
|
+
expect(@template.errors).to eq(body: "can't be nil")
|
111
109
|
end
|
112
110
|
|
113
111
|
it 'should handle 401 errors' do
|
114
112
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 401))
|
115
|
-
expect {@template.post}.to raise_error(
|
113
|
+
expect { @template.post }.to raise_error('401 Not Authorized')
|
116
114
|
end
|
117
115
|
|
118
116
|
it 'should handle 404 errors' do
|
119
117
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 404))
|
120
|
-
expect {@template.post}.to raise_error("Can't POST to /templates/email/1")
|
118
|
+
expect { @template.post }.to raise_error("Can't POST to /templates/email/1")
|
121
119
|
end
|
122
120
|
end
|
123
121
|
|
124
|
-
context
|
122
|
+
context 'handling errors at the email_templates root level' do
|
125
123
|
let(:client) do
|
126
124
|
double('client')
|
127
125
|
end
|
@@ -130,20 +128,20 @@ describe GovDelivery::TMS::EmailTemplate do
|
|
130
128
|
end
|
131
129
|
|
132
130
|
it 'should handle errors' do
|
133
|
-
response = {'errors' => {body: "can't be nil"}}
|
131
|
+
response = { 'errors' => { body: "can't be nil" } }
|
134
132
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 422, body: response))
|
135
133
|
@template.post
|
136
|
-
expect(@template.errors).to eq(
|
134
|
+
expect(@template.errors).to eq(body: "can't be nil")
|
137
135
|
end
|
138
136
|
|
139
137
|
it 'should handle 401 errors' do
|
140
138
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 401))
|
141
|
-
expect {@template.post}.to raise_error(
|
139
|
+
expect { @template.post }.to raise_error('401 Not Authorized')
|
142
140
|
end
|
143
141
|
|
144
142
|
it 'should handle 404 errors' do
|
145
143
|
expect(@template.client).to receive('post').with(@template).and_return(double('response', status: 404))
|
146
|
-
expect {@template.post}.to raise_error("Can't POST to /templates/email")
|
144
|
+
expect { @template.post }.to raise_error("Can't POST to /templates/email")
|
147
145
|
end
|
148
146
|
end
|
149
|
-
end
|
147
|
+
end
|
data/spec/errors_spec.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GovDelivery::TMS::Errors do
|
4
|
-
context
|
4
|
+
context 'an errors hash' do
|
5
5
|
let(:object_with_errors) do
|
6
|
-
double('instance', href: 'href', errors: {
|
6
|
+
double('instance', href: 'href', errors: { 'body' => ["can't be blank"], 'subject' => ["can't be blank"] })
|
7
7
|
end
|
8
8
|
subject { GovDelivery::TMS::Errors::InvalidVerb.new(object_with_errors) }
|
9
9
|
it 'should work' do
|
10
10
|
expect(subject.message).to match(/body can't be blank, subject can't be blank/)
|
11
11
|
end
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
data/spec/from_address_spec.rb
CHANGED
@@ -1,64 +1,65 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GovDelivery::TMS::FromAddress do
|
4
|
-
context
|
4
|
+
context 'creating a list of from addresses' do
|
5
5
|
let(:client) do
|
6
6
|
double('client')
|
7
7
|
end
|
8
8
|
before do
|
9
|
-
@fromaddresses = GovDelivery::TMS::
|
9
|
+
@fromaddresses = GovDelivery::TMS::FromAddresses.new(client, '/from_addresses')
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should be able to get a list of email templates' do
|
13
13
|
response = [{
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
'from_email' => 'something@evotest.govdelivery.com',
|
15
|
+
'reply_to_email' => 'something@evotest.govdelivery.com',
|
16
|
+
'bounce_email' => 'something@evotest.govdelivery.com',
|
17
|
+
'is_default' => true,
|
18
|
+
'created_at' => 'sometime',
|
19
|
+
'_links' => { 'self' => '/from_addresses/1' }
|
20
20
|
}]
|
21
21
|
|
22
|
-
expect(@fromaddresses.client).to receive('get').with('/from_addresses').and_return(double('/from_addresses', status: 200, body:
|
23
|
-
@fromaddresses.get
|
24
|
-
expect(
|
22
|
+
expect(@fromaddresses.client).to receive('get').with('/from_addresses').and_return(double('/from_addresses', status: 200, body: response, headers: {}))
|
23
|
+
addresses = @fromaddresses.get
|
24
|
+
expect(addresses.collection.length).to eq(1)
|
25
|
+
expect(addresses.collection.first.class).to eq(GovDelivery::TMS::FromAddress)
|
26
|
+
expect(addresses.collection.first.from_email).to eq('something@evotest.govdelivery.com')
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
context
|
30
|
+
context 'creating a from address' do
|
29
31
|
let(:client) do
|
30
32
|
double('client')
|
31
33
|
end
|
32
34
|
|
33
35
|
before do
|
34
|
-
@fromaddress = GovDelivery::TMS::FromAddress.new(client, '/from_addresses',
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
is_default: true})
|
36
|
+
@fromaddress = GovDelivery::TMS::FromAddress.new(client, '/from_addresses', from_email: 'something@evotest.govdelivery.com',
|
37
|
+
reply_to_email: 'something@evotest.govdelivery.com',
|
38
|
+
bounce_email: 'something@evotest.govdelivery.com',
|
39
|
+
is_default: true)
|
39
40
|
end
|
40
41
|
|
41
42
|
it 'should post successfully' do
|
42
43
|
response = {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
'from_email' => 'something@evotest.govdelivery.com',
|
45
|
+
'reply_to_email' => 'something@evotest.govdelivery.com',
|
46
|
+
'bounce_email' => 'something@evotest.govdelivery.com',
|
47
|
+
'is_default' => true,
|
48
|
+
'created_at' => 'sometime',
|
49
|
+
'_links' => { 'self' => '/from_addresses/1' }
|
49
50
|
}
|
50
|
-
expect(@fromaddress.client).to receive('post').with(@fromaddress).and_return(double('response', status: 201, body: response
|
51
|
+
expect(@fromaddress.client).to receive('post').with(@fromaddress).and_return(double('response', status: 201, body: response))
|
51
52
|
@fromaddress.post
|
52
|
-
expect(@fromaddress.from_email).to
|
53
|
-
expect(@fromaddress.reply_to_email).to
|
54
|
-
expect(@fromaddress.bounce_email).to
|
55
|
-
expect(@fromaddress.is_default).to
|
56
|
-
expect(@fromaddress.created_at).to
|
57
|
-
expect(@fromaddress.href).to
|
53
|
+
expect(@fromaddress.from_email).to eq('something@evotest.govdelivery.com')
|
54
|
+
expect(@fromaddress.reply_to_email).to eq('something@evotest.govdelivery.com')
|
55
|
+
expect(@fromaddress.bounce_email).to eq('something@evotest.govdelivery.com')
|
56
|
+
expect(@fromaddress.is_default).to eq(true)
|
57
|
+
expect(@fromaddress.created_at).to eq('sometime')
|
58
|
+
expect(@fromaddress.href).to eq('/from_addresses/1')
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
|
-
context
|
62
|
+
context 'handling errors' do
|
62
63
|
let(:client) do
|
63
64
|
double('client')
|
64
65
|
end
|
@@ -67,20 +68,20 @@ describe GovDelivery::TMS::FromAddress do
|
|
67
68
|
end
|
68
69
|
|
69
70
|
it 'should handle errors' do
|
70
|
-
response = {'errors' => {from_email: "can't be nil"}}
|
71
|
+
response = { 'errors' => { from_email: "can't be nil" } }
|
71
72
|
expect(@fromaddress.client).to receive('post').with(@fromaddress).and_return(double('response', status: 422, body: response))
|
72
73
|
@fromaddress.post
|
73
|
-
expect(@fromaddress.errors).to eq(
|
74
|
+
expect(@fromaddress.errors).to eq(from_email: "can't be nil")
|
74
75
|
end
|
75
76
|
|
76
77
|
it 'should handle 401 errors' do
|
77
78
|
expect(@fromaddress.client).to receive('post').with(@fromaddress).and_return(double('response', status: 401))
|
78
|
-
expect {@fromaddress.post}.to raise_error(
|
79
|
+
expect { @fromaddress.post }.to raise_error('401 Not Authorized')
|
79
80
|
end
|
80
81
|
|
81
82
|
it 'should handle 404 errors' do
|
82
83
|
expect(@fromaddress.client).to receive('post').with(@fromaddress).and_return(double('response', status: 404))
|
83
|
-
expect {@fromaddress.post}.to raise_error("Can't POST to /from_addresses/1")
|
84
|
+
expect { @fromaddress.post }.to raise_error("Can't POST to /from_addresses/1")
|
84
85
|
end
|
85
86
|
end
|
86
|
-
end
|
87
|
+
end
|