action_smser 3.4.1 → 4.0.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.
- checksums.yaml +4 -4
- data/lib/action_smser/base.rb +1 -1
- data/lib/action_smser/version.rb +1 -1
- metadata +25 -120
- data/test/action_smser_test.rb +0 -8
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/config/manifest.js +0 -1
- data/test/dummy/app/assets/javascripts/application.js +0 -7
- data/test/dummy/app/assets/stylesheets/application.css +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/mailers/hello_smser.rb +0 -14
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config/application.rb +0 -40
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -26
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -32
- data/test/dummy/config/environments/production.rb +0 -60
- data/test/dummy/config/environments/test.rb +0 -42
- data/test/dummy/config/initializers/action_smser.rb +0 -11
- data/test/dummy/config/initializers/assets.rb +0 -12
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/git_ignored_passwords.rb +0 -15
- data/test/dummy/config/initializers/inflections.rb +0 -10
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -4
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/config.ru +0 -4
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/production.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +0 -34
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +0 -9632
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/functional/action_smser/delivery_reports_controller_test.rb +0 -148
- data/test/integration/navigation_test.rb +0 -11
- data/test/test_helper.rb +0 -28
- data/test/unit/action_smser/base_test.rb +0 -105
- data/test/unit/action_smser/delivery_methods/delayed_job_test.rb +0 -53
- data/test/unit/action_smser/delivery_methods/nexmo_test.rb +0 -97
- data/test/unit/action_smser/delivery_methods/simple_http_test.rb +0 -48
- data/test/unit/action_smser/delivery_methods/smstrade_test.rb +0 -68
- data/test/unit/action_smser/delivery_methods/test_array_test.rb +0 -42
- data/test/unit/action_smser/delivery_report_test.rb +0 -100
data/test/dummy/public/404.html
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
|
5
|
-
<style type="text/css">
|
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
-
div.dialog {
|
|
8
|
-
width: 25em;
|
|
9
|
-
padding: 0 4em;
|
|
10
|
-
margin: 4em auto 0 auto;
|
|
11
|
-
border: 1px solid #ccc;
|
|
12
|
-
border-right-color: #999;
|
|
13
|
-
border-bottom-color: #999;
|
|
14
|
-
}
|
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
<!-- This file lives in public/404.html -->
|
|
21
|
-
<div class="dialog">
|
|
22
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
|
23
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
|
24
|
-
</div>
|
|
25
|
-
</body>
|
|
26
|
-
</html>
|
data/test/dummy/public/422.html
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>The change you wanted was rejected (422)</title>
|
|
5
|
-
<style type="text/css">
|
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
-
div.dialog {
|
|
8
|
-
width: 25em;
|
|
9
|
-
padding: 0 4em;
|
|
10
|
-
margin: 4em auto 0 auto;
|
|
11
|
-
border: 1px solid #ccc;
|
|
12
|
-
border-right-color: #999;
|
|
13
|
-
border-bottom-color: #999;
|
|
14
|
-
}
|
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
<!-- This file lives in public/422.html -->
|
|
21
|
-
<div class="dialog">
|
|
22
|
-
<h1>The change you wanted was rejected.</h1>
|
|
23
|
-
<p>Maybe you tried to change something you didn't have access to.</p>
|
|
24
|
-
</div>
|
|
25
|
-
</body>
|
|
26
|
-
</html>
|
data/test/dummy/public/500.html
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>We're sorry, but something went wrong (500)</title>
|
|
5
|
-
<style type="text/css">
|
|
6
|
-
body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
|
|
7
|
-
div.dialog {
|
|
8
|
-
width: 25em;
|
|
9
|
-
padding: 0 4em;
|
|
10
|
-
margin: 4em auto 0 auto;
|
|
11
|
-
border: 1px solid #ccc;
|
|
12
|
-
border-right-color: #999;
|
|
13
|
-
border-bottom-color: #999;
|
|
14
|
-
}
|
|
15
|
-
h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
|
|
16
|
-
</style>
|
|
17
|
-
</head>
|
|
18
|
-
|
|
19
|
-
<body>
|
|
20
|
-
<!-- This file lives in public/500.html -->
|
|
21
|
-
<div class="dialog">
|
|
22
|
-
<h1>We're sorry, but something went wrong.</h1>
|
|
23
|
-
<p>We've been notified about this issue and we'll take a look at it shortly.</p>
|
|
24
|
-
</div>
|
|
25
|
-
</body>
|
|
26
|
-
</html>
|
|
File without changes
|
data/test/dummy/script/rails
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
-
|
|
4
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
-
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
-
require 'rails/commands'
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
require './test/test_helper'
|
|
2
|
-
|
|
3
|
-
class ActionSmser::DeliveryReportsControllerTest < ActionController::TestCase
|
|
4
|
-
|
|
5
|
-
class SmsTestSetup
|
|
6
|
-
def self.admin_access(controller)
|
|
7
|
-
if controller.session[:admin_logged].blank?
|
|
8
|
-
return controller.session[:admin_logged]
|
|
9
|
-
else
|
|
10
|
-
return true
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def self.process_delivery_report(request)
|
|
15
|
-
processable_array = []
|
|
16
|
-
params = request.params
|
|
17
|
-
if params["DeliveryReport"] && params["DeliveryReport"]["message"]
|
|
18
|
-
reports = params["DeliveryReport"]["message"]
|
|
19
|
-
reports = [reports] unless reports.is_a?(Array)
|
|
20
|
-
reports.each do |report|
|
|
21
|
-
processable_array << {'msg_id' => report['id'], 'status' => report['status']}
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
return processable_array
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def self.after_gateway_commit(delivery_reports)
|
|
29
|
-
return true
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
setup do
|
|
35
|
-
ActionSmser.delivery_options[:gateway_commit_observers] = []
|
|
36
|
-
@routes = ActionSmser::Engine.routes
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
test "gateway_commit with existing dr" do
|
|
40
|
-
@msg_id = "102010314204056202"
|
|
41
|
-
@dr = ActionSmser::DeliveryReport.create(:msg_id => @msg_id, :status => 'ORIGINAL_STATUS')
|
|
42
|
-
|
|
43
|
-
ActionSmser.delivery_options[:gateway_commit] = {'test_gateway' => SmsTestSetup}
|
|
44
|
-
ActionSmser.gateway_commit_observer_add(SmsTestSetup)
|
|
45
|
-
|
|
46
|
-
SmsTestSetup.expects(:after_gateway_commit).once.with(){|var| var.is_a?(Array) && var.first.is_a?(ActionSmser::DeliveryReport)}
|
|
47
|
-
|
|
48
|
-
get 'gateway_commit', params: {:gateway => 'test_gateway',
|
|
49
|
-
"DeliveryReport" => {"message" => {"id" => @msg_id, "donedate" => "2012/01/03 14:20:45",
|
|
50
|
-
"sentdate" => "2012/01/03 14:20:40", "status" => "DELIVERED"}}}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
assert_response :success
|
|
54
|
-
assert @response.body.downcase.include?("update"), "should have responsed about saving"
|
|
55
|
-
@dr.reload
|
|
56
|
-
assert_equal "DELIVERED", @dr.status
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
test "gateway_commit with multiple records" do
|
|
60
|
-
@msg_id = "102010314204056202"
|
|
61
|
-
@msg_id2 = "99999999999999999"
|
|
62
|
-
@dr = ActionSmser::DeliveryReport.create(:msg_id => @msg_id, :status => 'ORIGINAL_STATUS')
|
|
63
|
-
@dr2 = ActionSmser::DeliveryReport.create(:msg_id => @msg_id2, :status => 'ORIGINAL_STATUS')
|
|
64
|
-
|
|
65
|
-
ActionSmser.delivery_options[:gateway_commit] = {'test_gateway' => SmsTestSetup}
|
|
66
|
-
|
|
67
|
-
get 'gateway_commit', params: {:gateway => 'test_gateway',
|
|
68
|
-
"DeliveryReport" =>
|
|
69
|
-
{"message" => [{"id" => @msg_id.to_s, "status" => "DELIVERED"},
|
|
70
|
-
{"id" => @msg_id2, "status" => "DELIVERED"}]}}
|
|
71
|
-
|
|
72
|
-
assert_response :success
|
|
73
|
-
assert @response.body.downcase.include?("update"), "should have responded about saving"
|
|
74
|
-
@dr.reload
|
|
75
|
-
@dr2.reload
|
|
76
|
-
assert_equal "DELIVERED", @dr.status, "should have updated first record"
|
|
77
|
-
assert_equal "DELIVERED", @dr2.status, "should have updated second record"
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
test "gateway_commit without dr" do
|
|
83
|
-
ActionSmser.delivery_options[:gateway_commit] = {'test_gateway' => SmsTestSetup}
|
|
84
|
-
|
|
85
|
-
get 'gateway_commit', params: {:gateway => 'test_gateway',
|
|
86
|
-
"DeliveryReport" => {"message" => {"id" => "wrongid", "donedate" => "2012/01/03 14:20:45",
|
|
87
|
-
"sentdate" => "2012/01/03 14:20:40", "status" => "DELIVERED"}}}
|
|
88
|
-
|
|
89
|
-
assert_response :success
|
|
90
|
-
assert @response.body =~ /not/i, "should have responded not saved"
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
test "gateway_commit without any parser" do
|
|
94
|
-
get 'gateway_commit', params: {:gateway => 'gateway_not_found',
|
|
95
|
-
"DeliveryReport" => {"message" => {"id" => "wrongid", "donedate" => "2012/01/03 14:20:45",
|
|
96
|
-
"sentdate" => "2012/01/03 14:20:40", "status" => "DELIVERED"}}}
|
|
97
|
-
|
|
98
|
-
assert_response :success
|
|
99
|
-
assert @response.body =~ /not/i, "should have responded not saved"
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
test "index with forbidden admin_access (default access mode)" do
|
|
104
|
-
get 'index'
|
|
105
|
-
assert_response 403
|
|
106
|
-
assert_template nil
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
test "index with admin_access lambda with right login info" do
|
|
110
|
-
default = ActionSmser.delivery_options[:admin_access]
|
|
111
|
-
ActionSmser.delivery_options[:admin_access] = SmsTestSetup
|
|
112
|
-
2.times do
|
|
113
|
-
ActionSmser::DeliveryReport.create(:msg_id => "idtest_#{rand(10)}")
|
|
114
|
-
end
|
|
115
|
-
session[:admin_logged] = true
|
|
116
|
-
get 'index'
|
|
117
|
-
|
|
118
|
-
assert_response :success
|
|
119
|
-
assert_template :index
|
|
120
|
-
|
|
121
|
-
ActionSmser.delivery_options[:admin_access] = default
|
|
122
|
-
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
test "index with always enabled admin" do
|
|
127
|
-
2.times do
|
|
128
|
-
ActionSmser::DeliveryReport.create(:msg_id => "idtest_#{rand(10)}")
|
|
129
|
-
end
|
|
130
|
-
ActionSmser::DeliveryReportsController.any_instance.stubs(:admin_access_only).returns(true)
|
|
131
|
-
get 'index'
|
|
132
|
-
assert_response :success
|
|
133
|
-
assert_template :index
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
test "list with always enabled admin" do
|
|
137
|
-
2.times do
|
|
138
|
-
ActionSmser::DeliveryReport.create(:msg_id => "idtest_#{rand(10)}")
|
|
139
|
-
end
|
|
140
|
-
ActionSmser::DeliveryReportsController.any_instance.stubs(:admin_access_only).returns(true)
|
|
141
|
-
get 'list'
|
|
142
|
-
assert_response :success
|
|
143
|
-
assert_template :list
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class NavigationTest < ActionDispatch::IntegrationTest
|
|
4
|
-
fixtures :all
|
|
5
|
-
|
|
6
|
-
test "basic gateway_commit delivery_report" do
|
|
7
|
-
get '/action_smser/delivery_reports/gateway_commit/example_gateway'
|
|
8
|
-
assert_response :success
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
data/test/test_helper.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
# Configure Rails Environment
|
|
4
|
-
ENV["RAILS_ENV"] = "test"
|
|
5
|
-
|
|
6
|
-
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
|
7
|
-
require "rails/test_help"
|
|
8
|
-
# require "minitest/autorun"
|
|
9
|
-
require 'minitest/mock'
|
|
10
|
-
require 'mocha/minitest'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Rails.backtrace_cleaner.remove_silencers!
|
|
14
|
-
|
|
15
|
-
# Load support files
|
|
16
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
17
|
-
|
|
18
|
-
#ActiveRecord::Base.establish_connection :adapter => 'sqlite3', :database => ':memory:'
|
|
19
|
-
#
|
|
20
|
-
#silence_stream(STDOUT) do
|
|
21
|
-
# ActiveRecord::Migrator.migrate File.expand_path('../../db/migrate/', __FILE__)
|
|
22
|
-
#end
|
|
23
|
-
|
|
24
|
-
#def drop_all_tables
|
|
25
|
-
# ActiveRecord::Base.connection.tables.each do |table|
|
|
26
|
-
# ActiveRecord::Base.connection.drop_table(table)
|
|
27
|
-
# end
|
|
28
|
-
#end
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require './test/test_helper'
|
|
3
|
-
|
|
4
|
-
class ActionSmser::BaseTest < ActiveSupport::TestCase
|
|
5
|
-
class MockSms<ActionSmser::Base
|
|
6
|
-
def basic_sms(to, from, body)
|
|
7
|
-
sms(:to => to, :from => from, :body => body)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def before_delivery
|
|
11
|
-
return true
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def after_delivery(result)
|
|
15
|
-
return true
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
setup do
|
|
21
|
-
@receivers = ["555123555", "123", "+358123555123", "004915112341234", "04917332341111"]
|
|
22
|
-
@sender = "555666"
|
|
23
|
-
@body = "Body with ääkköset end"
|
|
24
|
-
@sms = MockSms.basic_sms(@receivers, @sender, @body)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
test "receivers should be joined by commas" do
|
|
28
|
-
assert_equal "555123555,123,358123555123,4915112341234,4917332341111", @sms.to_encoded
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
test "should be ok with single receivers" do
|
|
32
|
-
str = "123123"
|
|
33
|
-
@sms = MockSms.basic_sms(str, @sender, @body)
|
|
34
|
-
assert_equal [str], @sms.to_as_array
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
test "from_encoded should remove leading + and 0" do
|
|
38
|
-
@sms = MockSms.basic_sms("+358555", "+358123" , @body)
|
|
39
|
-
assert_equal "358123", @sms.from_encoded
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
test "body should be possible to encode" do
|
|
43
|
-
assert_equal "Body+with+%E4%E4kk%F6set+end", @sms.body_encoded_escaped
|
|
44
|
-
|
|
45
|
-
@sms = MockSms.basic_sms(@receivers, @sender, "ääkköset - euro=€ - ...=…")
|
|
46
|
-
assert_equal "%E4%E4kk%F6set+-+euro%3D%A4+-+...%3D_", @sms.body_encoded_escaped, "should use '_' in place of unknown chars"
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
test "body should be cropped to 500 chars, limit extra looong messages" do
|
|
50
|
-
@sms.body = (1..1000).map{'a'}.join
|
|
51
|
-
assert_equal 500, @sms.body_encoded_escaped.size
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
test "ttl should be 24 hours by default" do
|
|
55
|
-
assert_equal 24.hours, @sms.ttl_to_i
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
test "should be able to change ttl" do
|
|
59
|
-
@sms.ttl = "60"
|
|
60
|
-
assert_equal 1.minute, @sms.ttl_to_i
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
test "should be valid sms" do
|
|
64
|
-
assert @sms.valid?
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
test "should not be valid if no recipients" do
|
|
68
|
-
@sms = MockSms.basic_sms([nil, ""], @sender, @body)
|
|
69
|
-
assert !@sms.valid?
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
test "should have saved sms_type" do
|
|
73
|
-
assert_equal "ActionSmser::BaseTest::MockSms.basic_sms", @sms.sms_type
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
test "should have copied the delivery_options when initializing" do
|
|
77
|
-
assert @sms.delivery_options == ActionSmser.delivery_options
|
|
78
|
-
assert @sms.delivery_options.object_id != ActionSmser.delivery_options.object_id
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
test "should have test_array as delivery method" do
|
|
82
|
-
assert_equal ActionSmser::DeliveryMethods::TestArray, @sms.delivery_method
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
test "before delivery should be called if it's present" do
|
|
86
|
-
@sms.expects(:before_delivery).once
|
|
87
|
-
assert @sms.deliver
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
test "after delivery should be called if it's present" do
|
|
91
|
-
@sms.expects(:after_delivery).once
|
|
92
|
-
assert @sms.deliver
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
test "message_real_length should return real sms lenght" do
|
|
96
|
-
assert_equal 4, ActionSmser::Base.message_real_length("a[a")
|
|
97
|
-
end
|
|
98
|
-
test "message_real_crop should return cropped message with sms chars taken account" do
|
|
99
|
-
assert_equal "a[a[", ActionSmser::Base.message_real_cropped("a[a[", 6)
|
|
100
|
-
assert_equal "a[a", ActionSmser::Base.message_real_cropped("a[a[", 5)
|
|
101
|
-
assert_equal "a[a", ActionSmser::Base.message_real_cropped("a[a[", 4)
|
|
102
|
-
assert_equal "a[", ActionSmser::Base.message_real_cropped("a[a[", 3)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require './test/test_helper'
|
|
3
|
-
|
|
4
|
-
# We mock delayed_job
|
|
5
|
-
module Delayed
|
|
6
|
-
class Job
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
class ActionSmser::DelayedJobTest < ActiveSupport::TestCase
|
|
11
|
-
class MockSms<ActionSmser::Base
|
|
12
|
-
def basic_sms(to, from, body)
|
|
13
|
-
sms(:to => to, :from => from, :body => body)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
setup do
|
|
18
|
-
@receivers = ["555123555", "123555123"]
|
|
19
|
-
@sender = "555666"
|
|
20
|
-
@body = "Body with ääkköset end"
|
|
21
|
-
@sms = MockSms.basic_sms(@receivers, @sender, @body)
|
|
22
|
-
|
|
23
|
-
@sms.delivery_options[:delivery_method] = :delayed_job
|
|
24
|
-
@sms.delivery_options[:delayed_job] = {:delivery_method => :nexmo, :priority => 5}
|
|
25
|
-
assert_equal ActionSmser::DeliveryMethods::DelayedJob, @sms.delivery_method, "cant run tests, wrong delivery method"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
test "should be able to deliver and call enqueue for all receivers" do
|
|
29
|
-
|
|
30
|
-
::Delayed::Job.expects(:enqueue).twice().returns(1)
|
|
31
|
-
@sms_delivery = @sms.deliver
|
|
32
|
-
assert @sms_delivery
|
|
33
|
-
assert_equal 2, @sms_delivery.count
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
test "test that serializing is ok" do
|
|
37
|
-
smsdj = ActionSmser::DeliveryMethods::DelayedJob::SmsDeliverJob.new(@sms, @sms.to_numbers_array.first)
|
|
38
|
-
|
|
39
|
-
[:body, :from, :sms_type, :re_delivery_of_delivery_report_id, :ttl, :delivery_info].each do |var|
|
|
40
|
-
assert_equal [var, smsdj.send(var)], [var, @sms.send(var)]
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
assert smsdj.body.object_id != @sms.body.object_id, "It should make copy of all values, not use the same objects."
|
|
44
|
-
|
|
45
|
-
assert_equal smsdj.delivery_options, @sms.delivery_options.merge(:delivery_method => @sms.delivery_options[:delayed_job][:delivery_method])
|
|
46
|
-
|
|
47
|
-
assert_equal smsdj.to, @sms.to_numbers_array.first
|
|
48
|
-
|
|
49
|
-
assert_equal :nexmo, smsdj.delivery_options[:delivery_method], "Should set the deliverymethod to nexmo"
|
|
50
|
-
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require './test/test_helper'
|
|
3
|
-
|
|
4
|
-
class ActionSmser::NexmoTest < ActiveSupport::TestCase
|
|
5
|
-
class MockSms<ActionSmser::Base
|
|
6
|
-
def basic_sms(to, from, body)
|
|
7
|
-
sms(:to => to, :from => from, :body => body)
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
setup do
|
|
12
|
-
@receivers = ["555123555", "123555123"]
|
|
13
|
-
@sender = "555666"
|
|
14
|
-
@body = "Body with ääkköset end"
|
|
15
|
-
@sms = MockSms.basic_sms(@receivers, @sender, @body)
|
|
16
|
-
|
|
17
|
-
@sms.delivery_options[:delivery_method] = :nexmo
|
|
18
|
-
@sms.delivery_options[:nexmo] = {:username => 'user', :password => 'pass'}
|
|
19
|
-
assert_equal ActionSmser::DeliveryMethods::Nexmo, @sms.delivery_method, "cant run tests, wrong delivery method"
|
|
20
|
-
|
|
21
|
-
@http_mock = stub(
|
|
22
|
-
:body => '{"message-count":"1","messages":[{"message-price":"0.02500000","status":"0","message-id":"0778DE88","remaining-balance":"1.77500000"}]}')
|
|
23
|
-
ActionSmser::DeliveryMethods::Nexmo.stubs(:deliver_http_request).returns(@http_mock)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
test "should be able to deliver" do
|
|
27
|
-
ActionSmser::DeliveryMethods::Nexmo.expects(:deliver_http_request).twice().returns(@http_mock)
|
|
28
|
-
@sms_delivery = @sms.deliver
|
|
29
|
-
assert @sms_delivery
|
|
30
|
-
assert_equal 2, @sms_delivery.count
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test "delivery path should have unicode set when needed" do
|
|
34
|
-
assert !ActionSmser::DeliveryMethods::Nexmo.deliver_path(@sms, @sms.to, @sms.delivery_options[:nexmo]).include?('&type')
|
|
35
|
-
@sms.delivery_options[:nexmo][:type] = 'unicode'
|
|
36
|
-
assert ActionSmser::DeliveryMethods::Nexmo.deliver_path(@sms, @sms.to, @sms.delivery_options[:nexmo]).include?('&type=unicode')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
test "with saving delivery_reports" do
|
|
40
|
-
@sms.delivery_options[:save_delivery_reports] = true
|
|
41
|
-
@delivery_reports_count = ActionSmser::DeliveryReport.count
|
|
42
|
-
|
|
43
|
-
ActionSmser::DeliveryMethods::Nexmo.stubs(:deliver_http_request).returns(@http_mock)
|
|
44
|
-
|
|
45
|
-
@sms_delivery = @sms.deliver
|
|
46
|
-
|
|
47
|
-
assert @sms_delivery.is_a?(Array)
|
|
48
|
-
assert @sms_delivery.first.is_a?(ActionSmser::DeliveryReport), "should return delivery report array"
|
|
49
|
-
|
|
50
|
-
assert_equal @delivery_reports_count + 2, ActionSmser::DeliveryReport.count, "should have saved 2 delivery reports"
|
|
51
|
-
|
|
52
|
-
@dr1 = @sms_delivery.first
|
|
53
|
-
assert_equal "nexmo", @dr1.gateway
|
|
54
|
-
assert_equal "555123555", @dr1.to, "receiver wrong"
|
|
55
|
-
assert_equal "LOCAL_SENT", @dr1.status
|
|
56
|
-
|
|
57
|
-
@dr2 = @sms_delivery.last
|
|
58
|
-
assert_equal "123555123", @dr2.to, "receiver wrong"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
test "gateway process_delivery_report(request)" do
|
|
62
|
-
@msg_id = "msg_id_asdf"
|
|
63
|
-
|
|
64
|
-
request_mock = ::Minitest::Mock.new
|
|
65
|
-
request_mock.expect(:params, {"messageId" => @msg_id, "status" => "EXPIRED"})
|
|
66
|
-
result_array = ActionSmser::DeliveryMethods::Nexmo.process_delivery_report(request_mock)
|
|
67
|
-
|
|
68
|
-
assert_equal @msg_id, result_array.first['msg_id']
|
|
69
|
-
assert_equal "EXPIRED", result_array.first['status']
|
|
70
|
-
assert request_mock.verify
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
# curl -is "http://rest.nexmo.com/sms/json?username=...&password=...&from=ActionSmser&to=...&text=msg"
|
|
75
|
-
NEXMO_ERROR_RESPONSE_BODY='{"message-count":"1","messages":[{"error-text":"Message rejected by upstream path","message-price":"0.02500000","status":"6","message-id":"0778D302","remaining-balance":"1.87500000"}]}'
|
|
76
|
-
NEXMO_ERROR_RESPONSE=<<eos
|
|
77
|
-
HTTP/1.1 200 OK
|
|
78
|
-
Cache-Control: max-age=1
|
|
79
|
-
Content-Type: application/json;charset=ISO-8859-1
|
|
80
|
-
Transfer-Encoding: chunked
|
|
81
|
-
Server: Jetty(7.5.1.v20110908)
|
|
82
|
-
|
|
83
|
-
{"message-count":"1","messages":[{"error-text":"Message rejected by upstream path","message-price":"0.02500000","status":"6","message-id":"0778D302","remaining-balance":"1.87500000"}]}
|
|
84
|
-
eos
|
|
85
|
-
NEXMO_OK_RESPONSE_BODY='{"message-count":"1","messages":[{"message-price":"0.02500000","status":"0","message-id":"0778DE88","remaining-balance":"1.77500000"}]}'
|
|
86
|
-
NEXMO_OK_RESPONSE=<<eos
|
|
87
|
-
HTTP/1.1 200 OK
|
|
88
|
-
Cache-Control: max-age=1
|
|
89
|
-
Content-Type: application/json;charset=ISO-8859-1
|
|
90
|
-
Transfer-Encoding: chunked
|
|
91
|
-
Server: Jetty(7.5.1.v20110908)
|
|
92
|
-
|
|
93
|
-
{"message-count":"1","messages":[{"message-price":"0.02500000","status":"0","message-id":"0778DE88","remaining-balance":"1.77500000"}]}
|
|
94
|
-
eos
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
end
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require './test/test_helper'
|
|
3
|
-
|
|
4
|
-
class ActionSmser::SimpleHttpTest < ActiveSupport::TestCase
|
|
5
|
-
class MockSms<ActionSmser::Base
|
|
6
|
-
def basic_sms(to, from, body)
|
|
7
|
-
sms(:to => to, :from => from, :body => body)
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
setup do
|
|
12
|
-
@receivers = ["555123555", "123555123"]
|
|
13
|
-
@sender = "555666"
|
|
14
|
-
@body = "Body with ääkköset end"
|
|
15
|
-
@sms = MockSms.basic_sms(@receivers, @sender, @body)
|
|
16
|
-
|
|
17
|
-
@sms.delivery_options[:delivery_method] = :simple_http
|
|
18
|
-
@sms.delivery_options[:simple_http] = {:username => 'user', :password => 'pass'}
|
|
19
|
-
assert_equal ActionSmser::DeliveryMethods::SimpleHttp, @sms.delivery_method, "cant run tests, wrong delivery method"
|
|
20
|
-
|
|
21
|
-
http_mock = stub(:body => "id_1234\nid_6666")
|
|
22
|
-
ActionSmser::DeliveryMethods::SimpleHttp.stubs(:deliver_http_request).returns(http_mock)
|
|
23
|
-
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
test "should be able to deliver" do
|
|
27
|
-
@sms_delivery = @sms.deliver
|
|
28
|
-
assert @sms_delivery
|
|
29
|
-
assert_equal @sms_delivery.count, 2, "two messages"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test "with saving delivery_reports" do
|
|
33
|
-
@sms.delivery_options[:save_delivery_reports] = true
|
|
34
|
-
#debugger
|
|
35
|
-
@delivery_reports_count = ActionSmser::DeliveryReport.count
|
|
36
|
-
@sms_delivery = @sms.deliver
|
|
37
|
-
|
|
38
|
-
assert @sms_delivery.is_a?(Array)
|
|
39
|
-
assert @sms_delivery.first.is_a?(ActionSmser::DeliveryReport), "should return deliveryreport array"
|
|
40
|
-
|
|
41
|
-
assert_equal @delivery_reports_count + 2, ActionSmser::DeliveryReport.count
|
|
42
|
-
|
|
43
|
-
@dr = @sms_delivery.last
|
|
44
|
-
assert_equal "123555123", @dr.to, "receiver wrong"
|
|
45
|
-
assert_equal "id_6666", @dr.msg_id, "id wrong"
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
end
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require './test/test_helper'
|
|
3
|
-
|
|
4
|
-
class ActionSmser::SmstradeTest < ActiveSupport::TestCase
|
|
5
|
-
class MockSms < ActionSmser::Base
|
|
6
|
-
def basic_sms(to, from, body)
|
|
7
|
-
sms(:to => to, :from => from, :body => body)
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
setup do
|
|
12
|
-
@receivers = ["4915112341234", "4917812341234"]
|
|
13
|
-
@sender = "4917212341234"
|
|
14
|
-
@body = "Body with ümläüts."
|
|
15
|
-
@sms = MockSms.basic_sms(@receivers, @sender, @body)
|
|
16
|
-
|
|
17
|
-
@sms.delivery_options[:delivery_method] = :smstrade
|
|
18
|
-
@sms.delivery_options[:smstrade] = {:key => 'api-key-here', :route => 'gold', :debug => true}
|
|
19
|
-
assert_equal ActionSmser::DeliveryMethods::Smstrade, @sms.delivery_method, "cant run tests, wrong delivery method"
|
|
20
|
-
|
|
21
|
-
@http_mock = stub(:body => "100\n123456789\n0.064\n1")
|
|
22
|
-
ActionSmser::DeliveryMethods::Smstrade.stubs(:deliver_http_request).returns(@http_mock)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
test "should be able to deliver" do
|
|
26
|
-
ActionSmser::DeliveryMethods::Smstrade.expects(:deliver_http_request).twice().returns(@http_mock)
|
|
27
|
-
@sms_delivery = @sms.deliver
|
|
28
|
-
assert @sms_delivery
|
|
29
|
-
assert_equal 2, @sms_delivery.count
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test "should only receive numbers not prepended with zeros or plus signs" do
|
|
33
|
-
prepended_receivers = ["004915112341234", "+4917812341234", "04917332341111"]
|
|
34
|
-
sms = MockSms.basic_sms(prepended_receivers, @sender, @body)
|
|
35
|
-
|
|
36
|
-
assert_equal ["4915112341234", "4917812341234", "4917332341111"], sms.to_numbers_array
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
test "should append 00 to phone numbers before sending" do
|
|
40
|
-
@receivers.each do |to|
|
|
41
|
-
ActionSmser::DeliveryMethods::Smstrade.expects(:deliver_path).with(anything(), "00#{to}", anything())
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
@sms.deliver
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
test "with saving delivery_reports" do
|
|
48
|
-
@sms.delivery_options[:save_delivery_reports] = true
|
|
49
|
-
@delivery_reports_count = ActionSmser::DeliveryReport.count
|
|
50
|
-
|
|
51
|
-
ActionSmser::DeliveryMethods::Smstrade.stubs(:deliver_http_request).returns(@http_mock)
|
|
52
|
-
|
|
53
|
-
@sms_delivery = @sms.deliver
|
|
54
|
-
|
|
55
|
-
assert @sms_delivery.is_a?(Array)
|
|
56
|
-
assert @sms_delivery.first.is_a?(ActionSmser::DeliveryReport), "should return delivery report array"
|
|
57
|
-
|
|
58
|
-
assert_equal @delivery_reports_count + 2, ActionSmser::DeliveryReport.count, "should have saved 2 delivery reports"
|
|
59
|
-
|
|
60
|
-
@dr1 = @sms_delivery.first
|
|
61
|
-
assert_equal "smstrade", @dr1.gateway
|
|
62
|
-
assert_equal "004915112341234", @dr1.to, "receiver wrong"
|
|
63
|
-
assert_equal "LOCAL_SENT", @dr1.status
|
|
64
|
-
|
|
65
|
-
@dr2 = @sms_delivery.last
|
|
66
|
-
assert_equal "004917812341234", @dr2.to, "receiver wrong"
|
|
67
|
-
end
|
|
68
|
-
end
|