defra_ruby_email 1.0.0 → 1.1.0

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.
@@ -0,0 +1,38 @@
1
+ example_id | status | run_time |
2
+ -------------------------------------------------- | ------ | --------------- |
3
+ ./spec/defra_ruby_email_spec.rb[1:1:1] | passed | 0.00413 seconds |
4
+ ./spec/defra_ruby_email_spec.rb[1:2:1:1] | passed | 0.00548 seconds |
5
+ ./spec/defra_ruby_email_spec.rb[1:2:2:1] | passed | 0.00015 seconds |
6
+ ./spec/lib/last_email_cache_spec.rb[1:1:1:1] | passed | 0.00025 seconds |
7
+ ./spec/lib/last_email_cache_spec.rb[1:1:1:2] | passed | 0.00016 seconds |
8
+ ./spec/lib/last_email_cache_spec.rb[1:1:2:1:1] | passed | 0.006 seconds |
9
+ ./spec/lib/last_email_cache_spec.rb[1:1:2:1:2] | passed | 0.00465 seconds |
10
+ ./spec/lib/last_email_cache_spec.rb[1:1:2:1:3] | passed | 0.16939 seconds |
11
+ ./spec/lib/last_email_cache_spec.rb[1:1:2:2:1] | passed | 0.00418 seconds |
12
+ ./spec/lib/last_email_cache_spec.rb[1:1:2:2:2] | passed | 0.00217 seconds |
13
+ ./spec/lib/last_email_cache_spec.rb[1:1:2:2:3] | passed | 0.00255 seconds |
14
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:1:1] | passed | 0.00681 seconds |
15
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:1:2] | passed | 0.00816 seconds |
16
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:1:3] | passed | 0.00772 seconds |
17
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:2:1] | passed | 0.01331 seconds |
18
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:2:2] | passed | 0.01288 seconds |
19
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:2:3] | passed | 0.01322 seconds |
20
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:3:1] | passed | 0.01055 seconds |
21
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:3:2] | passed | 0.01425 seconds |
22
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:3:3] | passed | 0.01011 seconds |
23
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:4:1] | passed | 0.00944 seconds |
24
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:4:2] | passed | 0.0113 seconds |
25
+ ./spec/lib/last_email_cache_spec.rb[1:1:3:4:3] | passed | 0.01069 seconds |
26
+ ./spec/lib/last_email_cache_spec.rb[1:1:4:1] | passed | 0.00774 seconds |
27
+ ./spec/lib/last_email_cache_spec.rb[1:1:4:2] | passed | 0.00763 seconds |
28
+ ./spec/lib/last_email_cache_spec.rb[1:1:4:3] | passed | 0.00662 seconds |
29
+ ./spec/lib/last_email_cache_spec.rb[1:1:4:4] | passed | 0.0138 seconds |
30
+ ./spec/lib/last_notify_message_spec.rb[1:1:1] | passed | 0.01227 seconds |
31
+ ./spec/lib/last_notify_message_spec.rb[1:2:1:1] | passed | 0.00018 seconds |
32
+ ./spec/lib/last_notify_message_spec.rb[1:2:1:2] | passed | 0.00024 seconds |
33
+ ./spec/lib/last_notify_message_spec.rb[1:2:2:1] | passed | 0.00066 seconds |
34
+ ./spec/lib/last_notify_message_spec.rb[1:2:2:2] | passed | 0.0005 seconds |
35
+ ./spec/requests/last_email_spec.rb[1:1:1] | passed | 0.02328 seconds |
36
+ ./spec/requests/last_email_spec.rb[1:2:1] | passed | 0.02231 seconds |
37
+ ./spec/requests/last_notify_message_spec.rb[1:1:1] | passed | 0.05642 seconds |
38
+ ./spec/requests/last_notify_message_spec.rb[1:2:1] | passed | 0.01434 seconds |
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+
5
+ module DefraRubyEmail
6
+ RSpec.describe LastNotifyMessage do
7
+ subject(:instance) { described_class.instance }
8
+
9
+ before(:each) { instance.reset }
10
+
11
+ let(:client) { double(:client, get_notifications: notifications) }
12
+ let(:notifications) { double(:notifications, collection: collection) }
13
+ let(:collection) { double(:collection, first: notification) }
14
+ let(:notification) do
15
+ double(:notification,
16
+ type: "email",
17
+ template: "template",
18
+ subject: "Subject",
19
+ body: "Body",
20
+ sent_at: "datetime",
21
+ email_address: "test@example.com",
22
+ phone_number: nil,
23
+ line_1: nil,
24
+ line_2: nil,
25
+ line_3: nil,
26
+ line_4: nil,
27
+ line_5: nil,
28
+ line_6: nil,
29
+ postcode: nil)
30
+ end
31
+
32
+ let(:expected_keys) { %w[type template subject body date to line_1 line_2 line_3 line_4 line_5 line_6 postcode] }
33
+
34
+ describe "#retrieve_last_notify_message" do
35
+ it "makes a call to the Notify client" do
36
+ expect(Notifications::Client).to receive(:new).with(DefraRubyEmail.configuration.notify_api_key).and_return(client)
37
+ expect(client).to receive(:get_notifications).and_return(notifications)
38
+
39
+ expect(instance.last_notify_message).to eq(nil)
40
+
41
+ instance.retrieve_last_notify_message
42
+
43
+ expect(instance.last_notify_message).to eq(notification)
44
+ end
45
+ end
46
+
47
+ describe "#last_notify_message_json" do
48
+ context "when no messages have been sent" do
49
+ let(:expected_keys) { %w[error] }
50
+
51
+ it "returns a JSON string" do
52
+ result = instance.last_notify_message_json
53
+
54
+ expect(result).to be_a(String)
55
+ expect { JSON.parse(result) }.to_not raise_error
56
+ end
57
+
58
+ it "responds with an error message" do
59
+ result = JSON.parse(instance.last_notify_message_json)
60
+
61
+ expect(result.keys).to match_array(expected_keys)
62
+ end
63
+ end
64
+
65
+ context "when a message has been sent" do
66
+ before(:each) do
67
+ instance.last_notify_message = notification
68
+ end
69
+
70
+ it "returns a JSON string" do
71
+ result = instance.last_notify_message_json
72
+
73
+ expect(result).to be_a(String)
74
+ expect { JSON.parse(result) }.to_not raise_error
75
+ end
76
+
77
+ it "contains the attributes of the message" do
78
+ result = JSON.parse(instance.last_notify_message_json)
79
+
80
+ expect(result["last_notify_message"].keys).to match_array(expected_keys)
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_helper"
4
+ require "notifications/client"
5
+
6
+ module DefraRubyEmail
7
+ RSpec.describe "LastNotifyMessage", type: :request do
8
+ after(:all) { Helpers::Configuration.reset_for_tests }
9
+
10
+ let(:path) { "/defra_ruby_email/last-notify-message" }
11
+
12
+ let(:notify_api_key) { "hello-i-am-a-key" }
13
+ let(:client) { double(:client, get_notifications: notifications) }
14
+ let(:notifications) { double(:notifications, collection: collection) }
15
+ let(:collection) { double(:collection, first: notification) }
16
+ let(:notification) do
17
+ double(:notification,
18
+ type: "email",
19
+ template: "template",
20
+ subject: "Subject",
21
+ body: "Body",
22
+ sent_at: "datetime",
23
+ email_address: "test@example.com",
24
+ phone_number: nil,
25
+ line_1: nil,
26
+ line_2: nil,
27
+ line_3: nil,
28
+ line_4: nil,
29
+ line_5: nil,
30
+ line_6: nil,
31
+ postcode: nil)
32
+ end
33
+
34
+ context "when the API is enabled" do
35
+ let(:expected_data) do
36
+ {
37
+ last_notify_message: {
38
+ type: "email",
39
+ template: "template",
40
+ subject: "Subject",
41
+ body: "Body",
42
+ date: "datetime",
43
+ to: "test@example.com",
44
+ line_1: nil,
45
+ line_2: nil,
46
+ line_3: nil,
47
+ line_4: nil,
48
+ line_5: nil,
49
+ line_6: nil,
50
+ postcode: nil
51
+ }
52
+ }.to_json
53
+ end
54
+
55
+ before(:each) do
56
+ Helpers::Configuration.prep_for_tests
57
+
58
+ expect(DefraRubyEmail.configuration).to receive(:notify_api_key).and_return(notify_api_key)
59
+
60
+ expect(Notifications::Client).to receive(:new).with(notify_api_key).and_return(client)
61
+ expect(client).to receive(:get_notifications).and_return(notifications)
62
+ end
63
+
64
+ it "returns a JSON response with a 200 code containing details of the last Notify message sent" do
65
+ get path
66
+
67
+ expect(response.content_type).to eq("application/json")
68
+ expect(response.code).to eq("200")
69
+
70
+ expect(response.body).to eq(expected_data)
71
+ end
72
+ end
73
+
74
+ context "when the API is disabled" do
75
+ before(:all) { DefraRubyEmail.configuration.enable = false }
76
+
77
+ it "cannot load the page" do
78
+ expect { get path }.to raise_error(ActionController::RoutingError)
79
+ end
80
+ end
81
+ end
82
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-04 00:00:00.000000000 Z
11
+ date: 2020-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: notifications-ruby-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: github_changelog_generator
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,7 @@ files:
122
136
  - app/assets/images/defra_ruby_email/govuk_logotype_email.png
123
137
  - app/controllers/defra_ruby_email/application_controller.rb
124
138
  - app/controllers/defra_ruby_email/last_email_controller.rb
139
+ - app/controllers/defra_ruby_email/last_notify_message_controller.rb
125
140
  - app/mailers/defra_ruby_email/test_mailer.rb
126
141
  - config/routes.rb
127
142
  - lib/defra_ruby_email.rb
@@ -129,6 +144,7 @@ files:
129
144
  - lib/defra_ruby_email/engine.rb
130
145
  - lib/defra_ruby_email/last_email_cache.rb
131
146
  - lib/defra_ruby_email/last_email_observer.rb
147
+ - lib/defra_ruby_email/last_notify_message.rb
132
148
  - lib/defra_ruby_email/version.rb
133
149
  - lib/tasks/changelog.rake
134
150
  - lib/tasks/defra_ruby_email.rake
@@ -155,6 +171,7 @@ files:
155
171
  - spec/dummy/config/initializers/assets.rb
156
172
  - spec/dummy/config/initializers/backtrace_silencers.rb
157
173
  - spec/dummy/config/initializers/cookies_serializer.rb
174
+ - spec/dummy/config/initializers/defra_ruby_email.rb
158
175
  - spec/dummy/config/initializers/filter_parameter_logging.rb
159
176
  - spec/dummy/config/initializers/inflections.rb
160
177
  - spec/dummy/config/initializers/mime_types.rb
@@ -169,9 +186,12 @@ files:
169
186
  - spec/dummy/public/422.html
170
187
  - spec/dummy/public/500.html
171
188
  - spec/dummy/public/favicon.ico
189
+ - spec/examples.txt
172
190
  - spec/lib/last_email_cache_spec.rb
191
+ - spec/lib/last_notify_message_spec.rb
173
192
  - spec/rails_helper.rb
174
193
  - spec/requests/last_email_spec.rb
194
+ - spec/requests/last_notify_message_spec.rb
175
195
  - spec/spec_helper.rb
176
196
  - spec/support/helpers/configuration.rb
177
197
  - spec/support/pry.rb
@@ -226,6 +246,7 @@ test_files:
226
246
  - spec/dummy/config/initializers/wrap_parameters.rb
227
247
  - spec/dummy/config/initializers/assets.rb
228
248
  - spec/dummy/config/initializers/cookies_serializer.rb
249
+ - spec/dummy/config/initializers/defra_ruby_email.rb
229
250
  - spec/dummy/config/initializers/to_time_preserves_timezone.rb
230
251
  - spec/dummy/config/initializers/inflections.rb
231
252
  - spec/dummy/config.ru
@@ -236,10 +257,13 @@ test_files:
236
257
  - spec/dummy/public/404.html
237
258
  - spec/dummy/log/test.log
238
259
  - spec/dummy/README.rdoc
260
+ - spec/examples.txt
239
261
  - spec/requests/last_email_spec.rb
262
+ - spec/requests/last_notify_message_spec.rb
240
263
  - spec/support/simplecov.rb
241
264
  - spec/support/pry.rb
242
265
  - spec/support/helpers/configuration.rb
243
266
  - spec/lib/last_email_cache_spec.rb
267
+ - spec/lib/last_notify_message_spec.rb
244
268
  - spec/rails_helper.rb
245
269
  - spec/defra_ruby_email_spec.rb