postageapp 1.3.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +6 -0
- data/.travis.yml +9 -39
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +117 -13
- data/Rakefile +15 -4
- data/VERSION +1 -0
- data/app/ingresses/action_mailbox/ingresses/postage_app/inbound_emails_controller.rb +52 -0
- data/app/ingresses/action_mailbox/ingresses/postage_app.rb +4 -0
- data/config/routes.rb +8 -0
- data/exe/postageapp +37 -0
- data/lib/generators/postageapp/postageapp_generator.rb +9 -6
- data/lib/postageapp/cli/command/config.rb +74 -0
- data/lib/postageapp/cli/command/create_mailbox.rb +21 -0
- data/lib/postageapp/cli/command/env.rb +58 -0
- data/lib/postageapp/cli/command/get_project_info.rb +3 -0
- data/lib/postageapp/cli/command.rb +110 -0
- data/lib/postageapp/cli.rb +14 -0
- data/lib/postageapp/configuration.rb +237 -74
- data/lib/postageapp/engine.rb +11 -0
- data/lib/postageapp/env.rb +9 -0
- data/lib/postageapp/mailer/mailer_4.rb +30 -14
- data/lib/postageapp/mailer.rb +1 -11
- data/lib/postageapp/rails/railtie.rb +1 -3
- data/lib/postageapp/request.rb +6 -1
- data/lib/postageapp.rb +53 -35
- data/log/.gitignore +1 -0
- data/postageapp.gemspec +7 -10
- data/script/with +2 -2
- data/test/gemfiles/Gemfile.rails-2.3.x +1 -1
- data/test/gemfiles/Gemfile.rails-3.0.x +1 -1
- data/test/gemfiles/Gemfile.rails-3.1.x +1 -1
- data/test/gemfiles/Gemfile.rails-3.2.x +1 -1
- data/test/gemfiles/Gemfile.rails-4.0.x +1 -1
- data/test/gemfiles/Gemfile.rails-4.1.x +1 -1
- data/test/gemfiles/Gemfile.rails-4.2.x +1 -2
- data/test/gemfiles/Gemfile.rails-5.0.x +2 -3
- data/test/gemfiles/Gemfile.rails-5.2.x +12 -0
- data/test/gemfiles/Gemfile.rails-6.0.x +12 -0
- data/test/gemfiles/Gemfile.rails-6.1.x +12 -0
- data/test/gemfiles/Gemfile.ruby +2 -3
- data/test/helper.rb +5 -3
- data/test/log/.gitignore +1 -0
- data/test/mailer/action_mailer_3/notifier.rb +1 -1
- data/test/tmp/.gitignore +1 -0
- data/test/travis_test.rb +58 -40
- data/test/{configuration_test.rb → unit/configuration_test.rb} +18 -12
- data/test/{failed_request_test.rb → unit/failed_request_test.rb} +6 -6
- data/test/{live_test.rb → unit/live_test.rb} +4 -39
- data/test/{mail_delivery_method_test.rb → unit/mail_delivery_method_test.rb} +1 -1
- data/test/{mailer_4_test.rb → unit/mailer_4_test.rb} +2 -2
- data/test/{mailer_helper_methods_test.rb → unit/mailer_helper_methods_test.rb} +4 -4
- data/test/{postageapp_test.rb → unit/postageapp_test.rb} +7 -1
- data/test/{rails_initialization_test.rb → unit/rails_initialization_test.rb} +2 -2
- data/test/{request_test.rb → unit/request_test.rb} +18 -17
- data/test/{response_test.rb → unit/response_test.rb} +4 -4
- data/test/unit/tmp/.gitignore +1 -0
- data/tmp/.gitignore +1 -0
- metadata +41 -48
- data/lib/postageapp/mailer/mailer_2.rb +0 -140
- data/lib/postageapp/mailer/mailer_3.rb +0 -190
- data/lib/postageapp/version.rb +0 -3
- data/test/mailer/action_mailer_2/notifier/with_body_and_attachment.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.html.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_custom_postage_variables.text.plain.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.html.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_html_and_text_views.text.plain.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_simple_view.erb +0 -1
- data/test/mailer/action_mailer_2/notifier/with_text_only_view.text.plain.erb +0 -1
- data/test/mailer/action_mailer_2/notifier.rb +0 -77
- data/test/mailer_2_test.rb +0 -95
- data/test/mailer_3_test.rb +0 -118
data/test/helper.rb
CHANGED
@@ -10,8 +10,10 @@ Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
|
|
10
10
|
|
11
11
|
require 'fileutils'
|
12
12
|
|
13
|
-
$LOAD_PATH.unshift(
|
14
|
-
$LOAD_PATH.unshift(File.join(
|
13
|
+
$LOAD_PATH.unshift(__dir__)
|
14
|
+
$LOAD_PATH.unshift(File.join(__dir__, '..', 'lib'))
|
15
|
+
|
16
|
+
ENV['POSTAGEAPP_API_KEY'] ||= '__TEST_API_KEY__'
|
15
17
|
|
16
18
|
require 'mail'
|
17
19
|
|
@@ -45,7 +47,7 @@ class MiniTest::Test
|
|
45
47
|
def setup
|
46
48
|
# Resetting to default configuration
|
47
49
|
|
48
|
-
PostageApp.configure(:
|
50
|
+
PostageApp.configure(reset: true) do |config|
|
49
51
|
config.requests_to_resend = %w( send_message )
|
50
52
|
config.project_root = File.expand_path('../', __FILE__)
|
51
53
|
config.logger = nil
|
data/test/log/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*
|
data/test/tmp/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*
|
data/test/travis_test.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
+
require 'open3'
|
5
|
+
require 'shellwords'
|
4
6
|
|
5
|
-
|
7
|
+
require_relative './with_environment'
|
6
8
|
|
7
9
|
class TravisTest
|
8
10
|
extend WithEnvironment
|
9
11
|
|
10
12
|
ENV_VARIABLE = {
|
11
|
-
:
|
12
|
-
:
|
13
|
+
rvm: 'RBENV_VERSION',
|
14
|
+
version: 'RBENV_VERSION',
|
15
|
+
gemfile: 'BUNDLE_GEMFILE'
|
13
16
|
}
|
14
17
|
|
15
18
|
def self.bash_env(env)
|
@@ -20,30 +23,44 @@ class TravisTest
|
|
20
23
|
end.compact.join(' ')
|
21
24
|
end
|
22
25
|
|
23
|
-
def self.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
]
|
26
|
+
def self.environment(env)
|
27
|
+
env.map do |key, value|
|
28
|
+
[ ENV_VARIABLE[key], value ]
|
29
|
+
end.to_h
|
29
30
|
end
|
30
31
|
|
31
|
-
def self.
|
32
|
-
commands =
|
32
|
+
def self.shell!(commands, env)
|
33
|
+
commands = commands.collect do |s|
|
33
34
|
s % env
|
34
35
|
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
shell_cmds = [
|
38
|
+
'eval "$(rbenv init -)"',
|
39
|
+
'set -e',
|
40
|
+
*commands
|
41
|
+
].join('; ')
|
42
|
+
|
43
|
+
# p environment(env)
|
44
|
+
# puts shell_cmds
|
45
|
+
|
46
|
+
Open3.popen3(
|
47
|
+
environment(env),
|
48
|
+
shell_cmds
|
49
|
+
) do |_sin, sout, serr, proc|
|
50
|
+
status = proc.value.exitstatus
|
43
51
|
|
44
|
-
yield(
|
52
|
+
yield(status) if (block_given?)
|
45
53
|
|
46
|
-
|
54
|
+
status.tap do |status|
|
55
|
+
if (status != 0)
|
56
|
+
$stderr.puts 'Error code: %d' % status
|
57
|
+
end
|
58
|
+
|
59
|
+
if (status != 0 or ENV['VERBOSE'])
|
60
|
+
puts sout.read
|
61
|
+
puts serr.read
|
62
|
+
end
|
63
|
+
end
|
47
64
|
end
|
48
65
|
end
|
49
66
|
|
@@ -52,15 +69,15 @@ class TravisTest
|
|
52
69
|
|
53
70
|
travis_test.matrix.collect do |entry|
|
54
71
|
{
|
55
|
-
:
|
72
|
+
rvm: entry[:rvm]
|
56
73
|
}
|
57
74
|
end.uniq.each do |entry|
|
58
|
-
puts
|
75
|
+
puts 'Ruby %{rvm}' % entry
|
59
76
|
|
60
|
-
|
77
|
+
shell!(
|
61
78
|
[
|
62
|
-
|
63
|
-
|
79
|
+
'rbenv install %{version}',
|
80
|
+
'gem install bundler'
|
64
81
|
],
|
65
82
|
entry
|
66
83
|
)
|
@@ -77,9 +94,9 @@ class TravisTest
|
|
77
94
|
|
78
95
|
versions[entry[:rvm]] = true
|
79
96
|
|
80
|
-
|
97
|
+
shell!(
|
81
98
|
[
|
82
|
-
|
99
|
+
%q[ruby -e 'puts RUBY_VERSION']
|
83
100
|
],
|
84
101
|
entry
|
85
102
|
)
|
@@ -103,14 +120,15 @@ class TravisTest
|
|
103
120
|
results = { }
|
104
121
|
|
105
122
|
travis_test.matrix.each do |entry|
|
106
|
-
puts
|
123
|
+
puts 'RBENV_VERSION=%{rvm} BUNDLE_GEMFILE=%{gemfile}' % entry
|
107
124
|
|
108
125
|
gemfile_lock_remove!(entry[:gemfile])
|
109
126
|
|
110
|
-
|
127
|
+
shell!(
|
111
128
|
[
|
112
|
-
|
113
|
-
|
129
|
+
'gem install bundler --no-doc',
|
130
|
+
'bundle install --quiet',
|
131
|
+
'bundle exec rake test'
|
114
132
|
],
|
115
133
|
entry
|
116
134
|
) do |code|
|
@@ -125,13 +143,13 @@ class TravisTest
|
|
125
143
|
puts '%-20s %-24s %-6s' % [
|
126
144
|
entry[:rvm],
|
127
145
|
File.basename(entry[:gemfile]).sub(/\AGemfile\./,''),
|
128
|
-
code
|
146
|
+
code ? 'Pass' : 'Fail'
|
129
147
|
]
|
130
148
|
end
|
131
149
|
end
|
132
150
|
|
133
151
|
def travis_config_path
|
134
|
-
@travis_config_path ||= File.expand_path('../.travis.yml',
|
152
|
+
@travis_config_path ||= File.expand_path('../.travis.yml', __dir__)
|
135
153
|
end
|
136
154
|
|
137
155
|
def travis_config
|
@@ -143,24 +161,24 @@ class TravisTest
|
|
143
161
|
end
|
144
162
|
|
145
163
|
def ruby_versions
|
146
|
-
travis_config['rvm']
|
164
|
+
travis_config['rvm'].sort
|
147
165
|
end
|
148
166
|
|
149
167
|
def matrix_exclusions
|
150
|
-
travis_config
|
168
|
+
travis_config.dig('matrix', 'exclude')&.collect do |entry|
|
151
169
|
{
|
152
|
-
:
|
153
|
-
:
|
170
|
+
rvm: entry['rvm'],
|
171
|
+
gemfile: entry['gemfile']
|
154
172
|
}
|
155
|
-
end
|
173
|
+
end or [ ]
|
156
174
|
end
|
157
175
|
|
158
176
|
def matrix
|
159
177
|
ruby_versions.flat_map do |version|
|
160
178
|
gemfiles.collect do |gemfile|
|
161
179
|
{
|
162
|
-
:
|
163
|
-
:
|
180
|
+
rvm: version,
|
181
|
+
gemfile: gemfile
|
164
182
|
}
|
165
183
|
end
|
166
184
|
end - matrix_exclusions
|
@@ -1,28 +1,33 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
class ConfigurationTest < MiniTest::Test
|
4
4
|
def test_initialization_defaults
|
5
5
|
config = PostageApp::Configuration.new
|
6
|
-
|
6
|
+
|
7
7
|
assert_equal true, config.secure
|
8
|
-
|
8
|
+
|
9
|
+
if (ENV['POSTAGEAPP_API_KEY'])
|
10
|
+
assert_equal ENV['POSTAGEAPP_API_KEY'], config.api_key
|
11
|
+
end
|
12
|
+
|
9
13
|
assert_equal 'https', config.scheme
|
10
14
|
assert_equal ENV['POSTAGEAPP_API_HOST'] || 'api.postageapp.com', config.host
|
11
15
|
assert_equal 443, config.port
|
12
16
|
|
13
|
-
|
17
|
+
assert_nil config.proxy_host
|
14
18
|
assert_equal 1080, config.proxy_port
|
15
|
-
|
16
|
-
|
19
|
+
assert_nil config.proxy_user
|
20
|
+
assert_nil config.proxy_pass
|
21
|
+
|
22
|
+
assert_equal 5, config.http_open_timeout
|
23
|
+
assert_equal 10, config.http_read_timeout
|
17
24
|
|
18
|
-
|
19
|
-
assert_equal 10, config.http_read_timeout
|
20
|
-
assert_equal nil, config.recipient_override
|
25
|
+
assert_nil config.recipient_override
|
21
26
|
assert_equal %w( send_message ), config.requests_to_resend
|
22
|
-
|
27
|
+
refute_nil config.project_root
|
23
28
|
assert_equal 'production', config.environment
|
24
|
-
|
25
|
-
|
29
|
+
assert_nil config.logger
|
30
|
+
assert_match 'Ruby', config.framework
|
26
31
|
end
|
27
32
|
|
28
33
|
def test_initialization_overrides
|
@@ -52,6 +57,7 @@ class ConfigurationTest < MiniTest::Test
|
|
52
57
|
config = PostageApp::Configuration.new
|
53
58
|
|
54
59
|
config.secure = false
|
60
|
+
|
55
61
|
assert_equal false, config.secure
|
56
62
|
assert_equal 'http', config.scheme
|
57
63
|
assert_equal 80, config.port
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
class FailedRequestTest < MiniTest::Test
|
4
4
|
def setup
|
5
5
|
super
|
6
6
|
|
7
|
-
PostageApp.configuration.project_root =
|
7
|
+
PostageApp.configuration.project_root = __dir__
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_store_and_initialize
|
@@ -87,12 +87,12 @@ class FailedRequestTest < MiniTest::Test
|
|
87
87
|
request = PostageApp::Request.new(:get_project_info)
|
88
88
|
|
89
89
|
message_receipt_response = stub(
|
90
|
-
|
91
|
-
|
92
|
-
|
90
|
+
fail?: false,
|
91
|
+
ok?: false,
|
92
|
+
not_found?: true
|
93
93
|
)
|
94
94
|
|
95
|
-
message_receipt_request = stub(:
|
95
|
+
message_receipt_request = stub(send: message_receipt_response)
|
96
96
|
|
97
97
|
PostageApp::Request.stubs(:new).with do |a,b|
|
98
98
|
a == :get_message_receipt
|
@@ -1,51 +1,16 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
class LiveTest < MiniTest::Test
|
4
4
|
# Note: Need access to a live PostageApp.com account
|
5
5
|
# See helper.rb to set host / api key
|
6
6
|
|
7
|
-
if (ENV['POSTAGEAPP_API_KEY'])
|
7
|
+
if (ENV['POSTAGEAPP_API_KEY'] and ENV['POSTAGEAPP_API_KEY'] != '__TEST_API_KEY__')
|
8
8
|
def test_configuration
|
9
9
|
config = PostageApp.config
|
10
10
|
|
11
11
|
assert config
|
12
12
|
assert_equal ENV['POSTAGEAPP_API_KEY'], config.api_key
|
13
13
|
end
|
14
|
-
|
15
|
-
def test_request_get_method_list
|
16
|
-
request = PostageApp::Request.new(:get_method_list)
|
17
|
-
response = request.send
|
18
|
-
|
19
|
-
assert_equal 'PostageApp::Response', response.class.name
|
20
|
-
assert_equal 'ok', response.status
|
21
|
-
assert_match(/^\w{40}$/, response.uid)
|
22
|
-
assert_equal nil, response.message
|
23
|
-
assert_equal(
|
24
|
-
{
|
25
|
-
'methods' => %w[
|
26
|
-
get_account_info
|
27
|
-
get_message_receipt
|
28
|
-
get_message_transmissions
|
29
|
-
get_messages
|
30
|
-
get_method_list
|
31
|
-
get_metrics
|
32
|
-
get_project_info
|
33
|
-
get_recipients_list
|
34
|
-
get_suppression_list
|
35
|
-
message_delivery_status
|
36
|
-
message_status
|
37
|
-
messages_history
|
38
|
-
project_create
|
39
|
-
project_destroy
|
40
|
-
project_info
|
41
|
-
send_message
|
42
|
-
test_mail_server
|
43
|
-
test_recipient
|
44
|
-
].join(', ')
|
45
|
-
},
|
46
|
-
response.data
|
47
|
-
)
|
48
|
-
end
|
49
14
|
|
50
15
|
def test_request_send_message
|
51
16
|
request = PostageApp::Request.new(
|
@@ -67,7 +32,7 @@ class LiveTest < MiniTest::Test
|
|
67
32
|
assert_equal 'ok', response.status
|
68
33
|
|
69
34
|
assert_match(/^\w{40}$/, response.uid)
|
70
|
-
|
35
|
+
assert_nil response.message
|
71
36
|
assert_match(/\d+/, response.data['message']['id'].to_s)
|
72
37
|
|
73
38
|
receipt = PostageApp::Request.new(
|
@@ -95,7 +60,7 @@ class LiveTest < MiniTest::Test
|
|
95
60
|
|
96
61
|
assert_match(/\A\w{40}$/, response.uid)
|
97
62
|
assert_match(/\ARequest could not be processed/, response.message)
|
98
|
-
|
63
|
+
assert_nil response.data
|
99
64
|
end
|
100
65
|
|
101
66
|
# Testable under ruby 1.9.2 Probably OK in production too... Probably
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
class Mailer4Test < MiniTest::Test
|
4
4
|
require_action_mailer(4) do
|
5
|
-
require File.expand_path('mailer/action_mailer_3/notifier',
|
5
|
+
require File.expand_path('mailer/action_mailer_3/notifier', __dir__)
|
6
6
|
|
7
7
|
puts "\e[0m\e[32mRunning #{File.basename(__FILE__)} for action_mailer #{ActionMailer::VERSION::STRING}\e[0m"
|
8
8
|
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
class MailerHelperMethodsTest < MiniTest::Test
|
4
4
|
def test_mailer_helper_methods
|
5
5
|
request = PostageApp::Request.new(
|
6
6
|
:send_message,
|
7
|
-
:
|
7
|
+
headers: {
|
8
8
|
'from' => 'sender@test.test',
|
9
9
|
'subject' => 'Test Message'
|
10
10
|
},
|
11
|
-
:
|
12
|
-
:
|
11
|
+
recipients: 'test@test.test',
|
12
|
+
content: {
|
13
13
|
'text/plain' => 'text content',
|
14
14
|
'text/html' => 'html content'
|
15
15
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
class PostageAppTest < MiniTest::Test
|
4
4
|
def test_method_configure
|
@@ -13,6 +13,12 @@ class PostageAppTest < MiniTest::Test
|
|
13
13
|
ensure
|
14
14
|
PostageApp.configuration_reset!
|
15
15
|
end
|
16
|
+
|
17
|
+
def test_version
|
18
|
+
assert PostageApp.version.match(/\A\d+\.\d+\.\d+\z/), -> {
|
19
|
+
"%s is not a valid version number" % PostageApp.version.inspect
|
20
|
+
}
|
21
|
+
end
|
16
22
|
|
17
23
|
def test_logger
|
18
24
|
assert PostageApp.logger.is_a?(Logger)
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
|
-
|
3
|
+
require_relative '../../lib/postageapp/rails/rails'
|
4
4
|
|
5
5
|
class RailsInitializationTest < MiniTest::Test
|
6
6
|
def test_initialization
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative '../helper'
|
2
2
|
|
3
3
|
class RequestTest < MiniTest::Test
|
4
4
|
def test_method_uid
|
@@ -10,15 +10,15 @@ class RequestTest < MiniTest::Test
|
|
10
10
|
assert_equal uid, request.uid
|
11
11
|
assert uid != request.uid(true)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def test_method_url
|
15
15
|
request = PostageApp::Request.new('test_method')
|
16
16
|
|
17
17
|
assert_equal 'api.postageapp.com', request.url.host
|
18
18
|
assert_equal 443, request.url.port
|
19
|
-
assert_equal '/v.1.
|
19
|
+
assert_equal '/v.1.1/test_method.json', request.url.path
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def test_method_arguments_to_send
|
23
23
|
request = PostageApp::Request.new('send_message',
|
24
24
|
'headers' => {
|
@@ -34,9 +34,10 @@ class RequestTest < MiniTest::Test
|
|
34
34
|
|
35
35
|
args = request.arguments_to_send
|
36
36
|
|
37
|
+
assert args['api_key']
|
37
38
|
assert !args['api_key'].empty?
|
38
39
|
assert_match(/^\w{40}$/, args['uid'])
|
39
|
-
|
40
|
+
|
40
41
|
payload = args['arguments']
|
41
42
|
|
42
43
|
assert_equal 'sender@test.test', payload['headers']['from']
|
@@ -44,7 +45,7 @@ class RequestTest < MiniTest::Test
|
|
44
45
|
assert_equal 'test@test.test', payload['recipients']
|
45
46
|
assert_equal 'text content', payload['content']['text/plain']
|
46
47
|
assert_equal 'html content', payload['content']['text/html']
|
47
|
-
|
48
|
+
|
48
49
|
request.arguments = { 'data' => 'content' }
|
49
50
|
|
50
51
|
args = request.arguments_to_send
|
@@ -53,37 +54,37 @@ class RequestTest < MiniTest::Test
|
|
53
54
|
assert_match(/^\w{40}$/, args['uid'])
|
54
55
|
assert_equal 'content', args['arguments']['data']
|
55
56
|
end
|
56
|
-
|
57
|
+
|
57
58
|
def test_uid_is_enforceable
|
58
59
|
request = PostageApp::Request.new('test_method')
|
59
60
|
|
60
61
|
assert_match(/^\w{40}$/, request.arguments_to_send['uid'])
|
61
|
-
|
62
|
+
|
62
63
|
request.uid = 'my_uid'
|
63
64
|
|
64
65
|
assert_equal 'my_uid', request.arguments_to_send['uid']
|
65
|
-
|
66
|
+
|
66
67
|
request = PostageApp::Request.new('test_method', 'uid' => 'new_uid', 'data' => 'value')
|
67
68
|
|
68
69
|
assert_equal 'new_uid', request.uid
|
69
70
|
assert_equal({ 'data' => 'value' }, request.arguments)
|
70
71
|
end
|
71
|
-
|
72
|
+
|
72
73
|
def test_api_key
|
73
74
|
request = PostageApp::Request.new('test_method')
|
74
75
|
|
75
76
|
assert_equal PostageApp.configuration.api_key, request.api_key
|
76
|
-
|
77
|
+
|
77
78
|
request = PostageApp::Request.new('test_method', {
|
78
79
|
'api_key' => 'custom_api_key'
|
79
80
|
})
|
80
81
|
|
81
82
|
assert_equal 'custom_api_key', request.api_key
|
82
83
|
end
|
83
|
-
|
84
|
+
|
84
85
|
def test_send
|
85
86
|
mock_successful_send
|
86
|
-
|
87
|
+
|
87
88
|
request = PostageApp::Request.new('send_message',
|
88
89
|
'headers' => {
|
89
90
|
'from' => 'sender@test.test',
|
@@ -102,10 +103,10 @@ class RequestTest < MiniTest::Test
|
|
102
103
|
assert_equal 'sha1hashuid23456789012345678901234567890', response.uid
|
103
104
|
assert_equal({ 'message' => { 'id' => 999 } }, response.data)
|
104
105
|
end
|
105
|
-
|
106
|
+
|
106
107
|
def test_send_failure
|
107
108
|
mock_failed_send
|
108
|
-
|
109
|
+
|
109
110
|
request = PostageApp::Request.new(
|
110
111
|
'send_message',
|
111
112
|
'headers' => {
|
@@ -122,7 +123,7 @@ class RequestTest < MiniTest::Test
|
|
122
123
|
response = request.send
|
123
124
|
|
124
125
|
assert_equal 'fail', response.status
|
125
|
-
|
126
|
-
|
126
|
+
assert_nil response.uid
|
127
|
+
assert_nil response.data
|
127
128
|
end
|
128
129
|
end
|