tms_client 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. data/Gemfile +3 -2
  2. data/README.md +43 -1
  3. data/Rakefile +16 -4
  4. data/bin/autospec +16 -0
  5. data/bin/htmldiff +16 -0
  6. data/bin/ldiff +16 -0
  7. data/bin/rake +16 -0
  8. data/bin/redcarpet +16 -0
  9. data/bin/rspec +16 -0
  10. data/bin/tt +16 -0
  11. data/bin/yard +16 -0
  12. data/bin/yardoc +16 -0
  13. data/bin/yri +16 -0
  14. data/lib/tms_client/client.rb +4 -2
  15. data/lib/tms_client/errors.rb +1 -1
  16. data/lib/tms_client/instance_resource.rb +5 -2
  17. data/lib/tms_client/resource/collections.rb +20 -0
  18. data/lib/tms_client/resource/email_message.rb +16 -8
  19. data/lib/tms_client/resource/ipaws_acknowledgement.rb +9 -0
  20. data/lib/tms_client/resource/ipaws_alert.rb +38 -0
  21. data/lib/tms_client/resource/ipaws_category.rb +7 -0
  22. data/lib/tms_client/resource/ipaws_cog_profile.rb +29 -0
  23. data/lib/tms_client/resource/ipaws_event_code.rb +7 -0
  24. data/lib/tms_client/resource/ipaws_nwem_area.rb +18 -0
  25. data/lib/tms_client/resource/ipaws_nwem_authorization.rb +9 -0
  26. data/lib/tms_client/resource/ipaws_nwem_auxilary_data.rb +8 -0
  27. data/lib/tms_client/resource/ipaws_response_type.rb +7 -0
  28. data/lib/tms_client/resource/ipaws_static_resource.rb +8 -0
  29. data/lib/tms_client/resource/sms_message.rb +14 -5
  30. data/lib/tms_client/resource/voice_message.rb +16 -7
  31. data/lib/tms_client/version.rb +1 -1
  32. data/lib/tms_client.rb +10 -2
  33. data/spec/client_spec.rb +6 -2
  34. data/spec/email_message_spec.rb +25 -9
  35. data/spec/instance_resource_spec.rb +19 -2
  36. data/spec/ipaws_acknowledgement_spec.rb +16 -0
  37. data/spec/ipaws_alerts_spec.rb +192 -0
  38. data/spec/ipaws_cog_profile_spec.rb +75 -0
  39. data/spec/ipaws_event_codes_spec.rb +35 -0
  40. data/spec/ipaws_nwem_areas_spec.rb +58 -0
  41. data/spec/ipaws_nwem_authorization_spec.rb +16 -0
  42. data/spec/mail/delivery_method_spec.rb +1 -1
  43. data/spec/sms_message_spec.rb +9 -1
  44. data/spec/spec_helper.rb +1 -0
  45. data/spec/voice_message_spec.rb +63 -0
  46. data/spec/voice_messages_spec.rb +21 -0
  47. data/tms_client.gemspec +3 -1
  48. metadata +66 -7
  49. checksums.yaml +0 -15
data/lib/tms_client.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module TMS #:nodoc:
2
2
  end
3
3
 
4
- require 'active_support'
4
+ require 'active_support/core_ext/hash'
5
5
  require 'tms_client/version'
6
6
  require 'faraday'
7
7
  require 'faraday_middleware'
@@ -30,4 +30,12 @@ require 'tms_client/resource/command_type'
30
30
  require 'tms_client/resource/command_action'
31
31
  require 'tms_client/resource/command'
32
32
  require 'tms_client/resource/keyword'
33
-
33
+ require 'tms_client/resource/ipaws_static_resource'
34
+ require 'tms_client/resource/ipaws_category'
35
+ require 'tms_client/resource/ipaws_event_code'
36
+ require 'tms_client/resource/ipaws_response_type'
37
+ require 'tms_client/resource/ipaws_acknowledgement'
38
+ require 'tms_client/resource/ipaws_cog_profile'
39
+ require 'tms_client/resource/ipaws_nwem_authorization'
40
+ require 'tms_client/resource/ipaws_nwem_area'
41
+ require 'tms_client/resource/ipaws_alert'
data/spec/client_spec.rb CHANGED
@@ -27,7 +27,11 @@ describe TMS::Client do
27
27
  @raw_connection.stub(:get).and_return(double('response', :status => 202, :body => {'message' => 'hi'}))
28
28
  expect { @client.get('/blargh') }.to raise_error(TMS::Request::InProgress)
29
29
  end
30
- end
31
-
32
30
 
31
+ context 'creating a new client without output' do
32
+ subject { TMS::Client.new('auth_token', api_root: 'null_url', logger: false) }
33
+ its(:logger){ should be_falsey }
34
+ its(:horse) { should be_kind_of(TMS::Horse) }
35
+ end
36
+ end
33
37
  end
@@ -6,9 +6,9 @@ describe TMS::EmailMessage do
6
6
  double('client')
7
7
  end
8
8
  before do
9
- @message = TMS::EmailMessage.new(client, nil, {
10
- :body => '12345678',
11
- :subject => 'blah',
9
+ @message = TMS::EmailMessage.new(client, '/messages/email', {
10
+ :body => '12345678',
11
+ :subject => 'blah',
12
12
  :created_at => 'BAAAAAD',
13
13
  :from_email => 'eric@evotest.govdelivery.com',
14
14
  :errors_to => 'errors@evotest.govdelivery.com',
@@ -28,12 +28,14 @@ describe TMS::EmailMessage do
28
28
  end
29
29
  it 'should post successfully' do
30
30
  response = {
31
- :body => 'processed',
32
- :subject => 'blah',
33
- :from_email => 'eric@evotest.govdelivery.com',
31
+ :body => 'processed',
32
+ :subject => 'blah',
33
+ :from_email => 'eric@evotest.govdelivery.com',
34
34
  :errors_to => 'errors@evotest.govdelivery.com',
35
35
  :reply_to => 'replyto@evotest.govdelivery.com',
36
- :recipients => [{:email => 'billy@evotest.govdelivery.com'}],
36
+ :recipients => [{:email => 'billy@evotest.govdelivery.com'}],
37
+ :failed => [{:email => 'billy@evotest.govdelivery.com'}],
38
+ :sent => [{:email => 'billy@evotest.govdelivery.com'}],
37
39
  :created_at => 'time'
38
40
  }
39
41
  @message.client.should_receive('post').with(@message).and_return(double('response', :status => 201, :body => response))
@@ -45,6 +47,10 @@ describe TMS::EmailMessage do
45
47
  @message.errors_to.should == 'errors@evotest.govdelivery.com'
46
48
  @message.recipients.class.should == TMS::EmailRecipients
47
49
  @message.recipients.collection.first.class.should == TMS::EmailRecipient
50
+ @message.sent.class.should == TMS::EmailRecipients
51
+ @message.sent.collection.first.class.should == TMS::EmailRecipient
52
+ @message.failed.class.should == TMS::EmailRecipients
53
+ @message.failed.collection.first.class.should == TMS::EmailRecipient
48
54
  end
49
55
  it 'should handle errors' do
50
56
  response = {'errors' => {:body => "can't be nil"}}
@@ -53,6 +59,16 @@ describe TMS::EmailMessage do
53
59
  @message.body.should == '12345678'
54
60
  @message.errors.should == {:body => "can't be nil"}
55
61
  end
62
+
63
+ it 'should handle 401 errors' do
64
+ @message.client.should_receive('post').with(@message).and_return(double('response', :status => 401))
65
+ expect {@message.post}.to raise_error(StandardError, "401 Not Authorized")
66
+ end
67
+
68
+ it 'should handle 404 errors' do
69
+ @message.client.should_receive('post').with(@message).and_return(double('response', :status => 404))
70
+ expect {@message.post}.to raise_error(StandardError, "Can't POST to /messages/email")
71
+ end
56
72
  end
57
73
 
58
74
  context 'an existing message' do
@@ -64,12 +80,12 @@ describe TMS::EmailMessage do
64
80
  @message = TMS::EmailMessage.new(client, '/messages/99', {})
65
81
  end
66
82
  it 'should GET cleanly' do
67
- response = {:body => 'processed',
83
+ response = {:body => 'processed',
68
84
  :subject => 'hey',
69
85
  :from_email => 'eric@evotest.govdelivery.com',
70
86
  :errors_to => 'errors@evotest.govdelivery.com',
71
87
  :reply_to => 'replyto@evotest.govdelivery.com',
72
- :recipients => [{:email => 'billy@evotest.govdelivery.com'}],
88
+ :recipients => [{:email => 'billy@evotest.govdelivery.com'}],
73
89
  :created_at => 'time'}
74
90
  @message.client.should_receive('get').with(@message.href).and_return(double('response', :status => 200, :body => response))
75
91
  @message.get
@@ -13,7 +13,7 @@ describe TMS::InstanceResource do
13
13
  end
14
14
 
15
15
  let(:client) do
16
- double('client', :post => happy_response)
16
+ double('client', :post => happy_response, :get => happy_response)
17
17
  end
18
18
 
19
19
 
@@ -23,12 +23,29 @@ describe TMS::InstanceResource do
23
23
 
24
24
  it 'should POST' do
25
25
  @instance_resource.bar = "OMG"
26
- @instance_resource.post.should be_true
26
+ @instance_resource.post.should be_truthy
27
27
  end
28
28
 
29
29
  it 'should correctly reflect on collection resources' do
30
30
  @instance_resource.blah.class.should == TMS::EmailMessage
31
31
  @instance_resource.shah.class.should == TMS::EmailMessage
32
32
  end
33
+
34
+ it 'should not GET on initialization' do
35
+ client.should_not receive(:get)
36
+ Foo.new(client, 'https://example.com/foos/1')
37
+ end
38
+
39
+ it 'should return self on successful get' do
40
+ client.should receive(:get)
41
+ foo = Foo.new(client, 'https://example.com/foos/1')
42
+ foo.should_not be_new_record
43
+ foo.get.should == foo
44
+ end
45
+
46
+ it 'it exposes its attributes hash' do
47
+ @instance_resource.attributes.should == {}
48
+ end
49
+
33
50
  end
34
51
  end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMS::IpawsAcknowledgement do
4
+
5
+ it 'gets IPAWS acknowledgement from client' do
6
+ client = double(:client)
7
+ response_body = { "ACK" => "PONG" }
8
+ ipaws_acknowledgement = TMS::IpawsAcknowledgement.new(client, '/ipaws/acknowledgement', {})
9
+ ipaws_acknowledgement.client.should_receive('get').with(ipaws_acknowledgement.href).and_return(
10
+ double('response', :status => 200, :body => response_body)
11
+ )
12
+ ipaws_acknowledgement.get.should == ipaws_acknowledgement
13
+ ipaws_acknowledgement.ACK.should == "PONG"
14
+ end
15
+
16
+ end
@@ -0,0 +1,192 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMS::IpawsAlert do
4
+
5
+ it 'post new IPAWS alerts to client, and capture status response from IPAWS' do
6
+ client = double(:client)
7
+
8
+ response_body = {
9
+ "identifier"=>"CAP12-TEST-1397743203",
10
+ "statuses"=> [
11
+ {
12
+ "CHANNELNAME"=>"CAPEXCH",
13
+ "STATUSITEMID"=>"200",
14
+ "ERROR"=>"N",
15
+ "STATUS"=>"Ack"
16
+ },
17
+ {
18
+ "CHANNELNAME"=>"CAPEXCH",
19
+ "STATUSITEMID"=>"202",
20
+ "ERROR"=>"N",
21
+ "STATUS"=>"alert-signature-is-valid"
22
+ },
23
+ {
24
+ "CHANNELNAME"=>"IPAWS",
25
+ "STATUSITEMID"=>"300",
26
+ "ERROR"=>"N",
27
+ "STATUS"=>"Ack"
28
+ },
29
+ {
30
+ "CHANNELNAME"=>"NWEM",
31
+ "STATUSITEMID"=>"401",
32
+ "ERROR"=>"N",
33
+ "STATUS"=>"message-not-disseminated-as-NWEM"
34
+ },
35
+ {
36
+ "CHANNELNAME"=>"EAS",
37
+ "STATUSITEMID"=>"501",
38
+ "ERROR"=>"N",
39
+ "STATUS"=>"message-not-disseminated-as-EAS"
40
+ },
41
+ {
42
+ "CHANNELNAME"=>"CMAS",
43
+ "STATUSITEMID"=>"600",
44
+ "ERROR"=>"N",
45
+ "STATUS"=>"Ack"
46
+ },
47
+ {
48
+ "CHANNELNAME"=>"PUBLIC",
49
+ "STATUSITEMID"=>"800",
50
+ "ERROR"=>"N",
51
+ "STATUS"=>"Ack"
52
+ }
53
+ ]
54
+ }
55
+
56
+ alert_attributes = {
57
+ identifier: "CAP12-TEST-123",
58
+ sender: 'test@open.com',
59
+ sent: "2014-04-18T15:02:26-05:00",
60
+ status: 'Actual',
61
+ msgType: 'Alert',
62
+ source: 'IPAWS-TEST',
63
+ scope: 'Public',
64
+ addresses: '999',
65
+ code: ['IPAWSv1.0'],
66
+ note: 'test',
67
+ incidents: 'IPAWS-9999',
68
+ info: [
69
+ {
70
+ language: 'en-US',
71
+ category: ['Safety'],
72
+ event: 'CIVIL EMERGENCY MESSAGE',
73
+ responseType: ['Shelter'],
74
+ urgency: 'Immediate',
75
+ severity: 'Extreme',
76
+ certainty: 'Observed',
77
+ audience: 'Public',
78
+ eventCode: [
79
+ { valueName: 'SAME', value: 'SVR'}
80
+ ],
81
+ effective: "2014-04-18T15:02:26-05:00",
82
+ expires: "2014-04-18T15:02:26-05:00",
83
+ senderName: 'IPAWS-Test',
84
+ headline: 'FLash Flood Warning',
85
+ description: 'Severe Weather Warning - Flooding',
86
+ instruction: 'Take Shelter',
87
+ parameter: [
88
+ { valueName: 'timezone', value: 'CST' }
89
+ ],
90
+ area: [
91
+ {
92
+ areaDesc: 'Fairfax County',
93
+ geocode: { valueName: 'SAME', value: '039035' }
94
+ }
95
+ ]
96
+ }
97
+ ]
98
+ }
99
+
100
+ alerts = TMS::IpawsAlerts.new(client, '/ipaws/alerts')
101
+ alert = alerts.build(alert_attributes)
102
+
103
+ alert.identifier.should == "CAP12-TEST-123"
104
+ alert.sender.should == 'test@open.com'
105
+ alert.sent.should == "2014-04-18T15:02:26-05:00"
106
+ alert.status.should == 'Actual'
107
+ alert.msgType.should == 'Alert'
108
+ alert.source.should == 'IPAWS-TEST'
109
+ alert.scope.should == 'Public'
110
+ alert.addresses.should == '999'
111
+ alert.code.should == ['IPAWSv1.0']
112
+ alert.note.should == 'test'
113
+ alert.incidents.should == 'IPAWS-9999'
114
+ alert.info.should == [
115
+ {
116
+ language: 'en-US',
117
+ category: ['Safety'],
118
+ event: 'CIVIL EMERGENCY MESSAGE',
119
+ responseType: ['Shelter'],
120
+ urgency: 'Immediate',
121
+ severity: 'Extreme',
122
+ certainty: 'Observed',
123
+ audience: 'Public',
124
+ eventCode: [
125
+ { valueName: 'SAME', value: 'SVR'}
126
+ ],
127
+ effective: "2014-04-18T15:02:26-05:00",
128
+ expires: "2014-04-18T15:02:26-05:00",
129
+ senderName: 'IPAWS-Test',
130
+ headline: 'FLash Flood Warning',
131
+ description: 'Severe Weather Warning - Flooding',
132
+ instruction: 'Take Shelter',
133
+ parameter: [
134
+ { valueName: 'timezone', value: 'CST' }
135
+ ],
136
+ area: [
137
+ {
138
+ areaDesc: 'Fairfax County',
139
+ geocode: { valueName: 'SAME', value: '039035' }
140
+ }
141
+ ]
142
+ }
143
+ ]
144
+
145
+ alert.client.should_receive('post').with(alert).and_return(double('response', :status => 200, :body => response_body))
146
+ alert.post.should == true
147
+ alert.ipaws_response.should == response_body
148
+
149
+ alert.identifier.should == "CAP12-TEST-123"
150
+ alert.sender.should == 'test@open.com'
151
+ alert.sent.should == "2014-04-18T15:02:26-05:00"
152
+ alert.status.should == 'Actual'
153
+ alert.msgType.should == 'Alert'
154
+ alert.source.should == 'IPAWS-TEST'
155
+ alert.scope.should == 'Public'
156
+ alert.addresses.should == '999'
157
+ alert.code.should == ['IPAWSv1.0']
158
+ alert.note.should == 'test'
159
+ alert.incidents.should == 'IPAWS-9999'
160
+ alert.info.should == [
161
+ {
162
+ language: 'en-US',
163
+ category: ['Safety'],
164
+ event: 'CIVIL EMERGENCY MESSAGE',
165
+ responseType: ['Shelter'],
166
+ urgency: 'Immediate',
167
+ severity: 'Extreme',
168
+ certainty: 'Observed',
169
+ audience: 'Public',
170
+ eventCode: [
171
+ { valueName: 'SAME', value: 'SVR'}
172
+ ],
173
+ effective: "2014-04-18T15:02:26-05:00",
174
+ expires: "2014-04-18T15:02:26-05:00",
175
+ senderName: 'IPAWS-Test',
176
+ headline: 'FLash Flood Warning',
177
+ description: 'Severe Weather Warning - Flooding',
178
+ instruction: 'Take Shelter',
179
+ parameter: [
180
+ { valueName: 'timezone', value: 'CST' }
181
+ ],
182
+ area: [
183
+ {
184
+ areaDesc: 'Fairfax County',
185
+ geocode: { valueName: 'SAME', value: '039035' }
186
+ }
187
+ ]
188
+ }
189
+ ]
190
+ end
191
+
192
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMS::IpawsCogProfile do
4
+
5
+ it 'gets IPAWS cog profile from client' do
6
+ client = double(:client)
7
+ response_body = {
8
+ "cogid"=>"120082",
9
+ "name"=>"GovDelivery",
10
+ "description"=>"GovDelivery",
11
+ "categoryName"=>"IPAWS-OPEN",
12
+ "organizationName"=>"CIV",
13
+ "cogEnabled"=>"Y",
14
+ "caeAuthorized"=>"Y",
15
+ "caeCmasAuthorized"=>"Y",
16
+ "eanAuthorized"=>"N",
17
+ "allEventCode"=>"N",
18
+ "allGeoCode"=>"N",
19
+ "easAuthorized"=>"Y",
20
+ "cmasAlertAuthorized"=>"Y",
21
+ "cmamTextAuthorized"=>"Y",
22
+ "publicAlertAuthorized"=>"Y",
23
+ "broadcastAuthorized"=>"N",
24
+ "email"=>"joe.bloom@govdelivery.com",
25
+ "eventCodes" => [
26
+ {"ALL"=>"FRW"},
27
+ {"ALL"=>"SVR"},
28
+ {"ALL"=>"SPW"},
29
+ {"ALL"=>"LAE"},
30
+ {"ALL"=>"CAE"},
31
+ {"ALL"=>"WSW"},
32
+ {"ALL"=>"CEM"}
33
+ ],
34
+ "geoCodes" => [
35
+ {"SAME"=>"039035"}
36
+ ]
37
+ }
38
+ cog_profile = TMS::IpawsCogProfile.new(client, '/ipaws/cog_profile', {})
39
+ cog_profile.client.should_receive('get').with(cog_profile.href).and_return(
40
+ double('response', :status => 200, :body => response_body)
41
+ )
42
+ cog_profile.get.should == cog_profile
43
+ cog_profile.cogid.should == "120082"
44
+
45
+ cog_profile.name.should == "GovDelivery"
46
+ cog_profile.description.should == "GovDelivery"
47
+ cog_profile.categoryName.should == "IPAWS-OPEN"
48
+ cog_profile.organizationName.should == "CIV"
49
+ cog_profile.cogEnabled.should == "Y"
50
+ cog_profile.caeAuthorized.should == "Y"
51
+ cog_profile.caeCmasAuthorized.should == "Y"
52
+ cog_profile.eanAuthorized.should == "N"
53
+ cog_profile.allEventCode.should == "N"
54
+ cog_profile.allGeoCode.should == "N"
55
+ cog_profile.easAuthorized.should == "Y"
56
+ cog_profile.cmasAlertAuthorized.should == "Y"
57
+ cog_profile.cmamTextAuthorized.should == "Y"
58
+ cog_profile.publicAlertAuthorized.should == "Y"
59
+ cog_profile.broadcastAuthorized.should == "N"
60
+ cog_profile.email.should == "joe.bloom@govdelivery.com"
61
+ cog_profile.eventCodes.should == [
62
+ {"ALL"=>"FRW"},
63
+ {"ALL"=>"SVR"},
64
+ {"ALL"=>"SPW"},
65
+ {"ALL"=>"LAE"},
66
+ {"ALL"=>"CAE"},
67
+ {"ALL"=>"WSW"},
68
+ {"ALL"=>"CEM"}
69
+ ]
70
+ cog_profile.geoCodes.should == [
71
+ {"SAME"=>"039035"}
72
+ ]
73
+ end
74
+
75
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMS::IpawsEventCodes do
4
+ context "loading Ipaws event codes" do
5
+ let(:client) { double('client') }
6
+ let(:event_codes) { TMS::IpawsEventCodes.new(client, '/ipaws/event_codes') }
7
+ it 'should GET itself' do
8
+ body = [
9
+ {
10
+ value: 'ADR',
11
+ description: 'Administrative Message/Follow up Statement',
12
+ cap_exchange: true,
13
+ core_ipaws_profile: true,
14
+ nwem: true,
15
+ eas_and_public: true,
16
+ cmas: true
17
+ },
18
+ {
19
+ value: 'AVA',
20
+ description: 'Avalanche Watch',
21
+ cap_exchange: true,
22
+ core_ipaws_profile: true,
23
+ nwem: true,
24
+ eas_and_public: true,
25
+ cmas: false }
26
+ ]
27
+ client.should_receive(:get).and_return(double('response', :body => body, :status => 200, :headers => {}))
28
+ event_codes.get
29
+ event_codes.collection.length.should == 2
30
+ event_codes.collection.each do |event_code|
31
+ event_code.should be_an_instance_of(TMS::IpawsEventCode)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMS::IpawsNwemAreas do
4
+
5
+ it 'gets IPAWS NWEM areas from client' do
6
+ client = double(:client)
7
+ response_body = [
8
+ {
9
+ "countyFipsCd"=>"51013",
10
+ "countyName"=>"Arlington",
11
+ "geoType"=>"C",
12
+ "stateCd"=>"VA",
13
+ "stateFips"=>"51",
14
+ "stateName"=>"Virginia",
15
+ "zoneCd"=>"054",
16
+ "zoneName"=>"Arlington/Falls Church/Alexandria"
17
+ },
18
+ {
19
+ "countyFipsCd"=>"51510",
20
+ "countyName"=>"City of Alexandria",
21
+ "geoType"=>"C",
22
+ "stateCd"=>"VA",
23
+ "stateFips"=>"51",
24
+ "stateName"=>"Virginia",
25
+ "zoneCd"=>"054",
26
+ "zoneName"=>"Arlington/Falls Church/Alexandria"
27
+ }
28
+ ]
29
+ nwem_areas = TMS::IpawsNwemAreas.new(client, '/ipaws/nwem_areas')
30
+
31
+ nwem_areas.client.should_receive('get').with(nwem_areas.href).and_return(
32
+ double('response', :status => 200, :body => response_body, :headers => {})
33
+ )
34
+ nwem_areas.get.should == nwem_areas
35
+ nwem_areas.collection.size.should == 2
36
+
37
+ nwem_area = nwem_areas.collection[0]
38
+ nwem_area.countyFipsCd.should == '51013'
39
+ nwem_area.countyName.should == 'Arlington'
40
+ nwem_area.geoType.should == 'C'
41
+ nwem_area.stateCd.should == 'VA'
42
+ nwem_area.stateFips.should == '51'
43
+ nwem_area.stateName.should == 'Virginia'
44
+ nwem_area.zoneCd.should == '054'
45
+ nwem_area.zoneName.should == 'Arlington/Falls Church/Alexandria'
46
+
47
+ nwem_area = nwem_areas.collection[1]
48
+ nwem_area.countyFipsCd.should == '51510'
49
+ nwem_area.countyName.should == 'City of Alexandria'
50
+ nwem_area.geoType.should == 'C'
51
+ nwem_area.stateCd.should == 'VA'
52
+ nwem_area.stateFips.should == '51'
53
+ nwem_area.stateName.should == 'Virginia'
54
+ nwem_area.zoneCd.should == '054'
55
+ nwem_area.zoneName.should == 'Arlington/Falls Church/Alexandria'
56
+ end
57
+
58
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMS::IpawsNwemAuthorization do
4
+
5
+ it 'gets IPAWS NWEM Authorization from client' do
6
+ client = double(:client)
7
+ response_body = { "cogid" => "true" }
8
+ nwem_authorization = TMS::IpawsNwemAuthorization.new(client, '/ipaws/nwem_authorization', {})
9
+ nwem_authorization.client.should_receive('get').with(nwem_authorization.href).and_return(
10
+ double('response', :status => 200, :body => response_body)
11
+ )
12
+ nwem_authorization.get.should == nwem_authorization
13
+ nwem_authorization.cogid.should == "true"
14
+ end
15
+
16
+ end
@@ -3,7 +3,7 @@ require 'mail'
3
3
  require 'tms_client/mail/delivery_method'
4
4
  describe TMS::Mail::DeliveryMethod do
5
5
  subject { TMS::Mail::DeliveryMethod.new({}) }
6
- let(:client) { stub('TMS::Client') }
6
+ let(:client) { double('TMS::Client') }
7
7
  let(:email_messages) { double('email_messages') }
8
8
  let(:tms_message) { double('tms_message', :recipients => double(:build => TMS::Recipient.new('href'))) }
9
9
 
@@ -17,13 +17,21 @@ describe TMS::SmsMessage do
17
17
  @message.recipients.class.should == TMS::Recipients
18
18
  end
19
19
  it 'should post successfully' do
20
- response = {:body => 'processed', :recipients => [{:phone => '22345678'}], :created_at => 'time'}
20
+ response = { :body => 'processed',
21
+ :recipients => [{:phone => '22345678'}],
22
+ :failed => [{:phone => '22345678'}],
23
+ :sent => [{:phone => '22345678'}],
24
+ :created_at => 'time'}
21
25
  @message.client.should_receive('post').with(@message).and_return(double('response', :status => 201, :body => response))
22
26
  @message.post
23
27
  @message.body.should == 'processed'
24
28
  @message.created_at.should == 'time'
25
29
  @message.recipients.class.should == TMS::Recipients
26
30
  @message.recipients.collection.first.class.should == TMS::Recipient
31
+ @message.sent.class.should == TMS::Recipients
32
+ @message.sent.collection.first.class.should == TMS::Recipient
33
+ @message.failed.class.should == TMS::Recipients
34
+ @message.failed.collection.first.class.should == TMS::Recipient
27
35
  end
28
36
  it 'should handle errors' do
29
37
  response = {'errors' => {:body => "can't be nil"}}
data/spec/spec_helper.rb CHANGED
@@ -17,6 +17,7 @@ end
17
17
  # loaded once.
18
18
  #
19
19
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
20
+ require 'rspec/its'
20
21
  RSpec.configure do |config|
21
22
  config.treat_symbols_as_metadata_keys_with_true_values = true
22
23
  config.run_all_when_everything_filtered = true
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe TMS::VoiceMessage do
4
+ context "creating a new message" do
5
+ let(:client) do
6
+ double('client')
7
+ end
8
+ before do
9
+ @message = TMS::VoiceMessage.new(client, nil, {:play_url => 'http://what.cd'})
10
+ end
11
+ it 'should not render readonly attrs in json hash' do
12
+ @message.to_json[:play_url].should == 'http://what.cd'
13
+ @message.to_json[:created_at].should == nil
14
+ end
15
+ it 'should initialize with attrs and collections' do
16
+ @message.play_url.should == 'http://what.cd'
17
+ @message.recipients.class.should == TMS::Recipients
18
+ end
19
+ it 'should post successfully' do
20
+ response = { :body => 'processed',
21
+ :recipients => [{:phone => '22345678'}],
22
+ :failed => [{:phone => '22345678'}],
23
+ :sent => [{:phone => '22345678'}],
24
+ :created_at => 'time'}
25
+ @message.client.should_receive('post').with(@message).and_return(double('response', :status => 201, :body => response))
26
+ @message.post
27
+ # @message.body.should == 'processed'
28
+ @message.created_at.should == 'time'
29
+ @message.recipients.class.should == TMS::Recipients
30
+ @message.recipients.collection.first.class.should == TMS::Recipient
31
+ @message.sent.class.should == TMS::Recipients
32
+ @message.sent.collection.first.class.should == TMS::Recipient
33
+ @message.failed.class.should == TMS::Recipients
34
+ @message.failed.collection.first.class.should == TMS::Recipient
35
+ end
36
+ it 'should handle errors' do
37
+ response = {'errors' => {:play_url => "can't be nil"}}
38
+ @message.client.should_receive('post').with(@message).and_return(double('response', :status => 422, :body => response))
39
+ @message.post
40
+ # @message.body.should == '12345678'
41
+ @message.errors.should == {:play_url => "can't be nil"}
42
+ end
43
+ end
44
+
45
+ context 'an existing message' do
46
+ let(:client) do
47
+ double('client')
48
+ end
49
+ before do
50
+ # blank hash prevents the client from doing a GET in the initialize method
51
+ @message = TMS::VoiceMessage.new(client, '/messages/99', {})
52
+ end
53
+ it 'should GET cleanly' do
54
+ response = {:play_url => 'processed', :recipients => [{:phone => '22345678'}], :created_at => 'time'}
55
+ @message.client.should_receive('get').with(@message.href).and_return(double('response', :status => 200, :body => response))
56
+ @message.get
57
+ @message.play_url.should == 'processed'
58
+ @message.created_at.should == 'time'
59
+ end
60
+ end
61
+
62
+
63
+ end