govdelivery-tms 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.md +8 -8
- data/govdelivery-tms.gemspec +2 -2
- data/lib/{govdelivery-tms → govdelivery/tms}/base.rb +4 -4
- data/lib/{govdelivery-tms → govdelivery/tms}/client.rb +9 -9
- data/lib/{govdelivery-tms → govdelivery/tms}/collection_resource.rb +2 -2
- data/lib/{govdelivery-tms → govdelivery/tms}/connection.rb +4 -4
- data/lib/{govdelivery-tms → govdelivery/tms}/errors.rb +1 -1
- data/lib/govdelivery/tms/instance_resource.rb +219 -0
- data/lib/{govdelivery-tms → govdelivery/tms}/link_header.rb +0 -0
- data/lib/{govdelivery-tms → govdelivery/tms}/logger.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/mail/delivery_method.rb +11 -11
- data/lib/govdelivery/tms/resource/collections.rb +98 -0
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/command.rb +7 -7
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/command_action.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/command_type.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_message.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_recipient.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_recipient_click.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_recipient_open.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/email_template.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/from_address.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/inbound_sms_message.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_acknowledgement.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_alert.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_category.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_cog_profile.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_event_code.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_nwem_area.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_nwem_authorization.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_nwem_auxilary_data.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_response_type.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/ipaws_static_resource.rb +2 -2
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/keyword.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/recipient.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/sms_message.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/resource/webhook.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/util/core_ext.rb +1 -1
- data/lib/{govdelivery-tms → govdelivery/tms}/util/hal_link_parser.rb +2 -2
- data/lib/govdelivery/tms/version.rb +5 -0
- data/lib/govdelivery-tms/instance_resource.rb +7 -7
- data/lib/govdelivery-tms.rb +38 -36
- data/spec/client_spec.rb +18 -18
- data/spec/command_types_spec.rb +6 -6
- data/spec/email_message_spec.rb +58 -58
- data/spec/email_template_spec.rb +39 -39
- data/spec/errors_spec.rb +3 -3
- data/spec/from_address_spec.rb +22 -22
- data/spec/inbound_sms_messages_spec.rb +5 -5
- data/spec/instance_resource_spec.rb +14 -14
- data/spec/ipaws_acknowledgement_spec.rb +6 -6
- data/spec/ipaws_alerts_spec.rb +31 -31
- data/spec/ipaws_cog_profile_spec.rb +26 -26
- data/spec/ipaws_event_codes_spec.rb +5 -5
- data/spec/ipaws_nwem_areas_spec.rb +22 -22
- data/spec/ipaws_nwem_authorization_spec.rb +6 -6
- data/spec/keyword_spec.rb +23 -23
- data/spec/keywords_spec.rb +5 -5
- data/spec/mail/delivery_method_spec.rb +19 -19
- data/spec/sms_message_spec.rb +29 -29
- data/spec/sms_messages_spec.rb +7 -7
- data/spec/spec_helper.rb +2 -3
- data/spec/tms_spec.rb +2 -2
- metadata +50 -41
- checksums.yaml +0 -15
- data/lib/govdelivery-tms/resource/collections.rb +0 -98
- data/lib/govdelivery-tms/version.rb +0 -3
@@ -1,7 +1,7 @@
|
|
1
|
-
module TMS
|
1
|
+
module GovDelivery::TMS
|
2
2
|
module IpawsStaticResource
|
3
3
|
def self.included(base)
|
4
|
-
base.send(:include, TMS::InstanceResource)
|
4
|
+
base.send(:include, GovDelivery::TMS::InstanceResource)
|
5
5
|
base.readonly_attributes :value, :description, :cap_exchange, :core_ipaws_profile, :nwem, :eas_and_public, :cmas
|
6
6
|
end
|
7
7
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module TMS #:nodoc:
|
1
|
+
module GovDelivery::TMS #:nodoc:
|
2
2
|
# A Keyword is a word that TMS will detect in an incoming SMS message. Keywords can have Commands, and
|
3
3
|
# when an incoming text message has a keyword, TMS will execute the keyword's Commands. Keywords may
|
4
4
|
# also have a response text field. If the response text is not blank, the system will send an SMS reply to the user
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module TMS::Util
|
1
|
+
module GovDelivery::TMS::Util
|
2
2
|
module HalLinkParser
|
3
3
|
|
4
4
|
def parse_links(_links)
|
@@ -39,7 +39,7 @@ module TMS::Util
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def relation_class(rel)
|
42
|
-
::TMS.const_get(classify(rel)) rescue nil
|
42
|
+
::GovDelivery::TMS.const_get(classify(rel)) rescue nil
|
43
43
|
end
|
44
44
|
|
45
45
|
def setup_subresource(link)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module TMS::InstanceResource
|
1
|
+
module GovDelivery::TMS::InstanceResource
|
2
2
|
def self.included(base)
|
3
3
|
base.send(:include, TMS::Base)
|
4
4
|
base.extend(ClassMethods)
|
@@ -73,12 +73,12 @@ module TMS::InstanceResource
|
|
73
73
|
def collection_attribute(attr, tms_class)
|
74
74
|
@collection_attributes ||= []
|
75
75
|
@collection_attributes.push(attr).uniq!
|
76
|
-
setup_collection(attr, TMS.const_get(tms_class))
|
76
|
+
setup_collection(attr, GovDelivery::TMS.const_get(tms_class))
|
77
77
|
end
|
78
78
|
|
79
79
|
##
|
80
|
-
# Read-only collection attributes don't get POSTed.
|
81
|
-
# Use this for collections that are represented as attributes, but cannot be modified.
|
80
|
+
# Read-only collection attributes don't get POSTed.
|
81
|
+
# Use this for collections that are represented as attributes, but cannot be modified.
|
82
82
|
#
|
83
83
|
# @example
|
84
84
|
# readonly_collection_attribute :opens
|
@@ -86,7 +86,7 @@ module TMS::InstanceResource
|
|
86
86
|
def readonly_collection_attribute(attr, tms_class)
|
87
87
|
@readonly_collection_attributes ||= []
|
88
88
|
@readonly_collection_attributes.push(attr).uniq!
|
89
|
-
setup_collection(attr, TMS.const_get(tms_class))
|
89
|
+
setup_collection(attr, GovDelivery::TMS.const_get(tms_class))
|
90
90
|
end
|
91
91
|
|
92
92
|
def setup_attributes(attrs, readonly=false)
|
@@ -100,7 +100,7 @@ module TMS::InstanceResource
|
|
100
100
|
if klass
|
101
101
|
custom_class_names[property] = klass
|
102
102
|
else
|
103
|
-
klass ||= TMS.const_get(property.to_s.capitalize)
|
103
|
+
klass ||= GovDelivery::TMS.const_get(property.to_s.capitalize)
|
104
104
|
end
|
105
105
|
|
106
106
|
self.send :define_method, property.to_sym, &lambda { @attributes[property] ||= klass.new(self.client, nil, nil) }
|
@@ -205,7 +205,7 @@ module TMS::InstanceResource
|
|
205
205
|
def set_attributes_from_hash(hash)
|
206
206
|
hash.reject { |k, _| k=~/^_/ }.each do |property, value|
|
207
207
|
if self.class.collection_attributes.include?(property.to_sym)
|
208
|
-
klass = self.class.custom_class_names[property] || TMS.const_get(property.to_s.capitalize)
|
208
|
+
klass = self.class.custom_class_names[property] || GovDelivery::TMS.const_get(property.to_s.capitalize)
|
209
209
|
@attributes[property.to_sym] = klass.new(client, nil, value)
|
210
210
|
else
|
211
211
|
@attributes[property.to_sym] = value
|
data/lib/govdelivery-tms.rb
CHANGED
@@ -1,43 +1,45 @@
|
|
1
|
-
module
|
1
|
+
module GovDelivery
|
2
|
+
module TMS #:nodoc:
|
3
|
+
end
|
2
4
|
end
|
3
5
|
|
4
6
|
require 'active_support/core_ext/hash'
|
5
|
-
require 'govdelivery
|
7
|
+
require 'govdelivery/tms/version'
|
6
8
|
require 'faraday'
|
7
9
|
require 'faraday_middleware'
|
8
10
|
|
9
|
-
require 'govdelivery
|
10
|
-
require 'govdelivery
|
11
|
-
require 'govdelivery
|
12
|
-
require 'govdelivery
|
13
|
-
require 'govdelivery
|
14
|
-
require 'govdelivery
|
15
|
-
require 'govdelivery
|
16
|
-
require 'govdelivery
|
17
|
-
require 'govdelivery
|
18
|
-
require 'govdelivery
|
11
|
+
require 'govdelivery/tms/link_header'
|
12
|
+
require 'govdelivery/tms/util/hal_link_parser'
|
13
|
+
require 'govdelivery/tms/util/core_ext'
|
14
|
+
require 'govdelivery/tms/connection'
|
15
|
+
require 'govdelivery/tms/client'
|
16
|
+
require 'govdelivery/tms/logger'
|
17
|
+
require 'govdelivery/tms/base'
|
18
|
+
require 'govdelivery/tms/instance_resource'
|
19
|
+
require 'govdelivery/tms/collection_resource'
|
20
|
+
require 'govdelivery/tms/errors'
|
19
21
|
|
20
|
-
require 'govdelivery
|
21
|
-
require 'govdelivery
|
22
|
-
require 'govdelivery
|
23
|
-
require 'govdelivery
|
24
|
-
require 'govdelivery
|
25
|
-
require 'govdelivery
|
26
|
-
require 'govdelivery
|
27
|
-
require 'govdelivery
|
28
|
-
require 'govdelivery
|
29
|
-
require 'govdelivery
|
30
|
-
require 'govdelivery
|
31
|
-
require 'govdelivery
|
32
|
-
require 'govdelivery
|
33
|
-
require 'govdelivery
|
34
|
-
require 'govdelivery
|
35
|
-
require 'govdelivery
|
36
|
-
require 'govdelivery
|
37
|
-
require 'govdelivery
|
38
|
-
require 'govdelivery
|
39
|
-
require 'govdelivery
|
40
|
-
require 'govdelivery
|
41
|
-
require 'govdelivery
|
42
|
-
require 'govdelivery
|
43
|
-
require 'govdelivery
|
22
|
+
require 'govdelivery/tms/resource/collections'
|
23
|
+
require 'govdelivery/tms/resource/recipient'
|
24
|
+
require 'govdelivery/tms/resource/email_recipient'
|
25
|
+
require 'govdelivery/tms/resource/email_recipient_open'
|
26
|
+
require 'govdelivery/tms/resource/email_recipient_click'
|
27
|
+
require 'govdelivery/tms/resource/from_address'
|
28
|
+
require 'govdelivery/tms/resource/email_template'
|
29
|
+
require 'govdelivery/tms/resource/sms_message'
|
30
|
+
require 'govdelivery/tms/resource/email_message'
|
31
|
+
require 'govdelivery/tms/resource/inbound_sms_message'
|
32
|
+
require 'govdelivery/tms/resource/command_type'
|
33
|
+
require 'govdelivery/tms/resource/command_action'
|
34
|
+
require 'govdelivery/tms/resource/command'
|
35
|
+
require 'govdelivery/tms/resource/keyword'
|
36
|
+
require 'govdelivery/tms/resource/ipaws_static_resource'
|
37
|
+
require 'govdelivery/tms/resource/ipaws_category'
|
38
|
+
require 'govdelivery/tms/resource/ipaws_event_code'
|
39
|
+
require 'govdelivery/tms/resource/ipaws_response_type'
|
40
|
+
require 'govdelivery/tms/resource/ipaws_acknowledgement'
|
41
|
+
require 'govdelivery/tms/resource/ipaws_cog_profile'
|
42
|
+
require 'govdelivery/tms/resource/ipaws_nwem_authorization'
|
43
|
+
require 'govdelivery/tms/resource/ipaws_nwem_area'
|
44
|
+
require 'govdelivery/tms/resource/ipaws_alert'
|
45
|
+
require 'govdelivery/tms/resource/webhook'
|
data/spec/client_spec.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
describe TMS::Client do
|
2
|
+
describe GovDelivery::TMS::Client do
|
3
3
|
context "creating a new client" do
|
4
4
|
before do
|
5
|
-
response = double('response', :
|
6
|
-
@raw_connection = double('raw_connection', :
|
7
|
-
@connection = TMS::Connection.
|
8
|
-
@client = TMS::Client.new('auth_token', :
|
5
|
+
response = double('response', status: 200, body: {"_links" => [{"self" => "/"}, {"horse" => "/horses/new"}, {"rabbits" => "/rabbits"}]})
|
6
|
+
@raw_connection = double('raw_connection', get: response)
|
7
|
+
@connection = allow(GovDelivery::TMS::Connection).to receive(:new).and_return(double('connection', connection: @raw_connection))
|
8
|
+
@client = GovDelivery::TMS::Client.new('auth_token', api_root: 'null_url')
|
9
9
|
end
|
10
10
|
it 'should set up logging' do
|
11
|
-
@client.logger.
|
12
|
-
@client.logger.level.
|
11
|
+
expect(@client.logger).not_to be_nil
|
12
|
+
expect(@client.logger.level).to eq(Logger::INFO)
|
13
13
|
end
|
14
14
|
it 'should discover endpoints for known services' do
|
15
|
-
@client.horse.
|
16
|
-
@client.rabbits.
|
15
|
+
expect(@client.horse).to be_kind_of(GovDelivery::TMS::Horse)
|
16
|
+
expect(@client.rabbits).to be_kind_of(GovDelivery::TMS::Rabbits)
|
17
17
|
end
|
18
18
|
it 'should handle 4xx responses' do
|
19
|
-
@raw_connection.
|
20
|
-
expect { @client.get('/blargh') }.to raise_error(TMS::Request::Error)
|
19
|
+
allow(@raw_connection).to receive(:get).and_return(double('response', status: 404, body: {'message' => 'hi'}))
|
20
|
+
expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::Error)
|
21
21
|
end
|
22
22
|
it 'should handle 5xx responses' do
|
23
|
-
@raw_connection.
|
24
|
-
expect { @client.get('/blargh') }.to raise_error(TMS::Request::Error)
|
23
|
+
allow(@raw_connection).to receive(:get).and_return(double('response', status: 503, body: {'message' => 'oops'}))
|
24
|
+
expect { @client.get('/blargh') }.to raise_error(GovDelivery::TMS::Request::Error)
|
25
25
|
end
|
26
26
|
it 'should handle 202 responses' do
|
27
|
-
@raw_connection.
|
28
|
-
expect { @client.get('/blargh') }.to raise_error(TMS::Request::InProgress)
|
27
|
+
allow(@raw_connection).to receive(:get).and_return(double('response', status: 202, body: {'message' => 'hi'}))
|
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
|
-
subject { TMS::Client.new('auth_token', api_root: 'null_url', logger: false) }
|
32
|
+
subject { GovDelivery::TMS::Client.new('auth_token', api_root: 'null_url', logger: false) }
|
33
33
|
its(:logger){ should be_falsey }
|
34
|
-
its(:horse) { should be_kind_of(TMS::Horse) }
|
34
|
+
its(:horse) { should be_kind_of(GovDelivery::TMS::Horse) }
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'defaults to the public API URL' do
|
38
|
-
expect(TMS::Client.new('auth_token').api_root).to eq('https://tms.govdelivery.com')
|
38
|
+
expect(GovDelivery::TMS::Client.new('auth_token').api_root).to eq('https://tms.govdelivery.com')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/spec/command_types_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe TMS::CommandTypes do
|
3
|
+
describe GovDelivery::TMS::CommandTypes do
|
4
4
|
context "loading command types" do
|
5
5
|
let(:client) do
|
6
6
|
double('client')
|
7
7
|
end
|
8
8
|
before do
|
9
|
-
@command_types = TMS::CommandTypes.new(client, '/command_types')
|
9
|
+
@command_types = GovDelivery::TMS::CommandTypes.new(client, '/command_types')
|
10
10
|
end
|
11
11
|
it 'should GET ok' do
|
12
12
|
body = [{"name"=>"dcm_unsubscribe",
|
@@ -18,12 +18,12 @@ describe TMS::CommandTypes do
|
|
18
18
|
{"name"=>"forward",
|
19
19
|
"string_fields"=>["http_method", "username", "password", "url"],
|
20
20
|
"array_fields"=>[]}]
|
21
|
-
@command_types.client.
|
21
|
+
expect(@command_types.client).to receive(:get).and_return(double('response', body: body, status: 200, headers: {}))
|
22
22
|
@command_types.get
|
23
|
-
@command_types.collection.length.
|
23
|
+
expect(@command_types.collection.length).to eq(3)
|
24
24
|
ct = @command_types.collection.find{|c| c.name == "dcm_subscribe"}
|
25
|
-
ct.array_fields.
|
26
|
-
ct.string_fields.
|
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
29
|
end
|
data/spec/email_message_spec.rb
CHANGED
@@ -1,72 +1,72 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe TMS::EmailMessage do
|
3
|
+
describe GovDelivery::TMS::EmailMessage do
|
4
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 = TMS::EmailMessage.new(client, '/messages/email', {
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
9
|
+
@message = GovDelivery::TMS::EmailMessage.new(client, '/messages/email', {
|
10
|
+
body: '12345678',
|
11
|
+
subject: 'blah',
|
12
|
+
created_at: 'BAAAAAD',
|
13
|
+
from_email: 'eric@evotest.govdelivery.com',
|
14
|
+
errors_to: 'errors@evotest.govdelivery.com',
|
15
|
+
reply_to: 'replyto@evotest.govdelivery.com'})
|
16
16
|
end
|
17
17
|
it 'should not render readonly attrs in json hash' do
|
18
|
-
@message.to_json[:body].
|
19
|
-
@message.to_json[:created_at].
|
18
|
+
expect(@message.to_json[:body]).to eq('12345678')
|
19
|
+
expect(@message.to_json[:created_at]).to eq(nil)
|
20
20
|
end
|
21
21
|
it 'should initialize with attrs and collections' do
|
22
|
-
@message.body.
|
23
|
-
@message.subject.
|
24
|
-
@message.from_email.
|
25
|
-
@message.reply_to.
|
26
|
-
@message.errors_to.
|
27
|
-
@message.recipients.class.
|
22
|
+
expect(@message.body).to eq('12345678')
|
23
|
+
expect(@message.subject).to eq('blah')
|
24
|
+
expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
|
25
|
+
expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
|
26
|
+
expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
|
27
|
+
expect(@message.recipients.class).to eq(GovDelivery::TMS::EmailRecipients)
|
28
28
|
end
|
29
29
|
it 'should post successfully' do
|
30
30
|
response = {
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
31
|
+
body: 'processed',
|
32
|
+
subject: 'blah',
|
33
|
+
from_email: 'eric@evotest.govdelivery.com',
|
34
|
+
errors_to: 'errors@evotest.govdelivery.com',
|
35
|
+
reply_to: 'replyto@evotest.govdelivery.com',
|
36
|
+
recipients: [{email: 'billy@evotest.govdelivery.com'}],
|
37
|
+
failed: [{email: 'billy@evotest.govdelivery.com'}],
|
38
|
+
sent: [{email: 'billy@evotest.govdelivery.com'}],
|
39
|
+
created_at: 'time'
|
40
40
|
}
|
41
|
-
@message.client.
|
41
|
+
expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 201, body: response))
|
42
42
|
@message.post
|
43
|
-
@message.body.
|
44
|
-
@message.created_at.
|
45
|
-
@message.from_email.
|
46
|
-
@message.reply_to.
|
47
|
-
@message.errors_to.
|
48
|
-
@message.recipients.class.
|
49
|
-
@message.recipients.collection.first.class.
|
50
|
-
@message.sent.class.
|
51
|
-
@message.sent.collection.first.class.
|
52
|
-
@message.failed.class.
|
53
|
-
@message.failed.collection.first.class.
|
43
|
+
expect(@message.body).to eq('processed')
|
44
|
+
expect(@message.created_at).to eq('time')
|
45
|
+
expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
|
46
|
+
expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
|
47
|
+
expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
|
48
|
+
expect(@message.recipients.class).to eq(GovDelivery::TMS::EmailRecipients)
|
49
|
+
expect(@message.recipients.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
|
50
|
+
expect(@message.sent.class).to eq(GovDelivery::TMS::EmailRecipients)
|
51
|
+
expect(@message.sent.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
|
52
|
+
expect(@message.failed.class).to eq(GovDelivery::TMS::EmailRecipients)
|
53
|
+
expect(@message.failed.collection.first.class).to eq(GovDelivery::TMS::EmailRecipient)
|
54
54
|
end
|
55
55
|
it 'should handle errors' do
|
56
|
-
response = {'errors' => {:
|
57
|
-
@message.client.
|
56
|
+
response = {'errors' => {body: "can't be nil"}}
|
57
|
+
expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 422, body: response))
|
58
58
|
@message.post
|
59
|
-
@message.body.
|
60
|
-
@message.errors.
|
59
|
+
expect(@message.body).to eq('12345678')
|
60
|
+
expect(@message.errors).to eq({body: "can't be nil"})
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should handle 401 errors' do
|
64
|
-
@message.client.
|
64
|
+
expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 401))
|
65
65
|
expect {@message.post}.to raise_error(StandardError, "401 Not Authorized")
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'should handle 404 errors' do
|
69
|
-
@message.client.
|
69
|
+
expect(@message.client).to receive('post').with(@message).and_return(double('response', status: 404))
|
70
70
|
expect {@message.post}.to raise_error(StandardError, "Can't POST to /messages/email")
|
71
71
|
end
|
72
72
|
end
|
@@ -77,24 +77,24 @@ describe TMS::EmailMessage do
|
|
77
77
|
end
|
78
78
|
before do
|
79
79
|
# blank hash prevents the client from doing a GET in the initialize method
|
80
|
-
@message = TMS::EmailMessage.new(client, '/messages/99', {})
|
80
|
+
@message = GovDelivery::TMS::EmailMessage.new(client, '/messages/99', {})
|
81
81
|
end
|
82
82
|
it 'should GET cleanly' do
|
83
|
-
response = {:
|
84
|
-
:
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
@message.client.
|
83
|
+
response = {body: 'processed',
|
84
|
+
subject: 'hey',
|
85
|
+
from_email: 'eric@evotest.govdelivery.com',
|
86
|
+
errors_to: 'errors@evotest.govdelivery.com',
|
87
|
+
reply_to: 'replyto@evotest.govdelivery.com',
|
88
|
+
recipients: [{email: 'billy@evotest.govdelivery.com'}],
|
89
|
+
created_at: 'time'}
|
90
|
+
expect(@message.client).to receive('get').with(@message.href).and_return(double('response', status: 200, body: response))
|
91
91
|
@message.get
|
92
|
-
@message.body.
|
93
|
-
@message.subject.
|
94
|
-
@message.from_email.
|
95
|
-
@message.reply_to.
|
96
|
-
@message.errors_to.
|
97
|
-
@message.created_at.
|
92
|
+
expect(@message.body).to eq('processed')
|
93
|
+
expect(@message.subject).to eq('hey')
|
94
|
+
expect(@message.from_email).to eq('eric@evotest.govdelivery.com')
|
95
|
+
expect(@message.reply_to).to eq('replyto@evotest.govdelivery.com')
|
96
|
+
expect(@message.errors_to).to eq('errors@evotest.govdelivery.com')
|
97
|
+
expect(@message.created_at).to eq('time')
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|