web47core 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{lib/app → app}/assets/stylesheets/status.sass +0 -0
- data/{lib/app → app}/controllers/status_controller.rb +0 -0
- data/{lib/app → app}/views/status/index.html.haml +0 -0
- metadata +6 -79
- data/.circleci/config.yml +0 -58
- data/.gitignore +0 -70
- data/.rubocop.yml +0 -33
- data/Gemfile +0 -5
- data/Gemfile.lock +0 -318
- data/Rakefile +0 -7
- data/bin/cron_server +0 -4
- data/test/controllers/status_controller_test.rb +0 -158
- data/test/factories/account_factories.rb +0 -9
- data/test/factories/notification_factories.rb +0 -14
- data/test/fixtures/mongoid.yml +0 -8
- data/test/fixtures/redis/host.yml +0 -5
- data/test/fixtures/redis/options.yml +0 -8
- data/test/fixtures/redis/sentinel.yml +0 -8
- data/test/fixtures/redis/url.yml +0 -2
- data/test/jobs/cron/server_test.rb +0 -160
- data/test/jobs/cron/switchboard_sync_configuration_test.rb +0 -64
- data/test/jobs/cron/trim_cron_servers_test.rb +0 -28
- data/test/jobs/cron/trim_failed_delayed_jobs_test.rb +0 -71
- data/test/models/concerns/app47_logger_test.rb +0 -88
- data/test/models/concerns/cdn_url_test.rb +0 -54
- data/test/models/concerns/email_able_test.rb +0 -145
- data/test/models/concerns/search_able_test.rb +0 -80
- data/test/models/concerns/standard_model_test.rb +0 -154
- data/test/models/concerns/system_configuration_test.rb +0 -212
- data/test/models/concerns/time_zone_able_test.rb +0 -77
- data/test/models/email_notification_test.rb +0 -297
- data/test/models/job_cron_tab_test.rb +0 -25
- data/test/models/notification_test.rb +0 -127
- data/test/models/redis_configuration_test.rb +0 -86
- data/test/models/slack_notification_test.rb +0 -91
- data/test/models/sms_notification_test.rb +0 -69
- data/test/models/smtp_configuration_test.rb +0 -66
- data/test/models/web47core_test.rb +0 -18
- data/test/notification_test_helper.rb +0 -146
- data/test/rails_setup.rb +0 -61
- data/test/shoulda_macros/mongoid.rb +0 -70
- data/test/test_helper.rb +0 -93
- data/test/test_models_helper.rb +0 -14
- data/web47core.gemspec +0 -58
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
# TODO: CMS add tests for clearing by account id as well as id
|
4
|
-
class StandardModelTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
context 'allowed_params' do
|
7
|
-
should 'return test form fields' do
|
8
|
-
allowed = TestForm.allowed_param_names
|
9
|
-
assert_equal 2, allowed.count
|
10
|
-
assert allowed.include?('name'), allowed.inspect
|
11
|
-
assert allowed.include?('password'), allowed.inspect
|
12
|
-
end
|
13
|
-
should 'return test input fields' do
|
14
|
-
allowed = TestInput.allowed_param_names
|
15
|
-
assert_equal 3, allowed.count
|
16
|
-
assert allowed.include?('input_type'), allowed.inspect
|
17
|
-
assert allowed.include?('test_form_id'), allowed.inspect
|
18
|
-
refute allowed.include?('test_input_field_ids'), allowed.inspect
|
19
|
-
end
|
20
|
-
should 'handle error' do
|
21
|
-
TestInput.expects(:all_associations).once.raises('Doh')
|
22
|
-
allowed = TestInput.allowed_param_names
|
23
|
-
assert_equal 3, allowed.count, allowed.inspect
|
24
|
-
assert allowed.include?('input_type'), allowed.inspect
|
25
|
-
assert allowed.include?('test_form_id'), allowed.inspect
|
26
|
-
assert allowed.include?('test_input_field_ids'), allowed.inspect
|
27
|
-
end
|
28
|
-
end
|
29
|
-
context 'update the model safely' do
|
30
|
-
setup do
|
31
|
-
@model = TestForm.create! name: 'name', password: 'abc123'
|
32
|
-
end
|
33
|
-
should 'update password' do
|
34
|
-
assert @model.update name: 'foo', password: 'bar'
|
35
|
-
assert_equal 'foo', @model.name
|
36
|
-
assert_equal 'bar', @model.password
|
37
|
-
end
|
38
|
-
should 'update not blank password' do
|
39
|
-
assert @model.update name: 'foo', password: ''
|
40
|
-
assert_equal 'foo', @model.name
|
41
|
-
assert_equal 'abc123', @model.password
|
42
|
-
end
|
43
|
-
should 'update not nil password' do
|
44
|
-
assert @model.update name: 'foo', password: nil
|
45
|
-
assert_equal 'foo', @model.name
|
46
|
-
assert_equal 'abc123', @model.password
|
47
|
-
end
|
48
|
-
should 'update! not blank password' do
|
49
|
-
assert @model.update! name: 'foo', password: ''
|
50
|
-
assert_equal 'foo', @model.name
|
51
|
-
assert_equal 'abc123', @model.password
|
52
|
-
end
|
53
|
-
should 'update_attributes! not blank password' do
|
54
|
-
assert @model.update_attributes! name: 'foo', password: ''
|
55
|
-
assert_equal 'foo', @model.name
|
56
|
-
assert_equal 'abc123', @model.password
|
57
|
-
end
|
58
|
-
should 'update_attributes not blank password' do
|
59
|
-
assert @model.update_attributes name: 'foo', password: ''
|
60
|
-
assert_equal 'foo', @model.name
|
61
|
-
assert_equal 'abc123', @model.password
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'Remove cache on save' do
|
66
|
-
setup do
|
67
|
-
@model = TestAutoClearCache.new
|
68
|
-
assert @model.save
|
69
|
-
@model.update_cache
|
70
|
-
end
|
71
|
-
should 'return the original url' do
|
72
|
-
assert Rails.cache.exist? @model.id.to_s
|
73
|
-
assert @model.save
|
74
|
-
refute Rails.cache.exist? @model.id.to_s
|
75
|
-
end
|
76
|
-
should 'handle error' do
|
77
|
-
Rails.cache.expects(:delete_matched).once.raises('Doh')
|
78
|
-
assert Rails.cache.exist? @model.id.to_s
|
79
|
-
assert @model.save
|
80
|
-
assert Rails.cache.exist? @model.id.to_s
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context 'skip call back' do
|
85
|
-
setup do
|
86
|
-
@model = TestCallBack.new value: 'foo'
|
87
|
-
end
|
88
|
-
should 'use call back' do
|
89
|
-
assert_equal 'foo', @model.value
|
90
|
-
@model.value = 'foobar'
|
91
|
-
assert @model.save
|
92
|
-
@model.reload
|
93
|
-
assert_equal 'bar', @model.value
|
94
|
-
end
|
95
|
-
should 'not use call back' do
|
96
|
-
assert_equal 'foo', @model.value
|
97
|
-
@model.value = 'foobar'
|
98
|
-
TestCallBack.without_callback(:save, :before, :bar_it) do
|
99
|
-
assert @model.save
|
100
|
-
end
|
101
|
-
@model.reload
|
102
|
-
assert_equal 'foobar', @model.value
|
103
|
-
end
|
104
|
-
end
|
105
|
-
context 'make_options' do
|
106
|
-
should 'return array' do
|
107
|
-
assert_equal [%w[one One], %w[two Two], %w[three Three]], TestForm.make_options(%w[one two three])
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
class TestForm
|
113
|
-
include StandardModel
|
114
|
-
field :name
|
115
|
-
field :password
|
116
|
-
has_many :test_inputs
|
117
|
-
|
118
|
-
def secure_fields
|
119
|
-
super + %i[password]
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
class TestInput
|
124
|
-
include StandardModel
|
125
|
-
field :input_type
|
126
|
-
belongs_to :test_form
|
127
|
-
has_and_belongs_to_many :test_input_field
|
128
|
-
end
|
129
|
-
|
130
|
-
class TestInputField
|
131
|
-
include StandardModel
|
132
|
-
field :input_type
|
133
|
-
belongs_to :test_form
|
134
|
-
has_and_belongs_to_many :test_input
|
135
|
-
end
|
136
|
-
|
137
|
-
class TestAutoClearCache
|
138
|
-
include StandardModel
|
139
|
-
|
140
|
-
def update_cache(value = 'abc123')
|
141
|
-
Rails.cache.write id.to_s, value, expires_in: 60
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
class TestCallBack
|
146
|
-
include StandardModel
|
147
|
-
|
148
|
-
field :value, type: String, default: 'foo'
|
149
|
-
before_save :bar_it
|
150
|
-
|
151
|
-
def bar_it
|
152
|
-
self.value = 'bar'
|
153
|
-
end
|
154
|
-
end
|
@@ -1,212 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Test the system configuration model object
|
5
|
-
#
|
6
|
-
class SystemConfigurationTest < ActiveSupport::TestCase
|
7
|
-
should_have_field :environment, type: String, klass: SystemConfiguration, default: 'test'
|
8
|
-
should_have_field :default_email, type: String, klass: SystemConfiguration, default: 'support@app47.com'
|
9
|
-
should_have_field :support_email, type: String, klass: SystemConfiguration, default: 'support@app47.com'
|
10
|
-
should_have_field :smtp_name, type: String, klass: SystemConfiguration
|
11
|
-
should_have_field :smtp_address, type: String, klass: SystemConfiguration
|
12
|
-
should_have_field :smtp_domain, type: String, klass: SystemConfiguration
|
13
|
-
should_have_field :smtp_port, type: Integer, klass: SystemConfiguration, default: 587
|
14
|
-
should_have_field :smtp_user_name, type: String, klass: SystemConfiguration
|
15
|
-
should_have_field :smtp_password, type: String, klass: SystemConfiguration
|
16
|
-
should_have_field :smtp_enable_starttls_auto, type: Mongoid::Boolean, klass: SystemConfiguration
|
17
|
-
should_have_field :mailgun_api_key, type: String, klass: SystemConfiguration
|
18
|
-
should_have_field :base_url, type: String, klass: SystemConfiguration
|
19
|
-
should_have_field :cdn_url, type: String, klass: SystemConfiguration
|
20
|
-
# Slack
|
21
|
-
should_have_field :slack_api_url, type: String, klass: SystemConfiguration
|
22
|
-
should_have_field :slack_support_channel, type: String, klass: SystemConfiguration, default: 'support'
|
23
|
-
should_have_field :slack_sales_channel, type: String, klass: SystemConfiguration, default: 'sales'
|
24
|
-
# Twillo
|
25
|
-
should_have_field :twilio_account_id, type: String, klass: SystemConfiguration
|
26
|
-
should_have_field :twilio_auth_token, type: String, klass: SystemConfiguration
|
27
|
-
should_have_field :twilio_phone_number, type: String, klass: SystemConfiguration
|
28
|
-
# Zendesk
|
29
|
-
should_have_field :zendesk_token, type: String, klass: SystemConfiguration
|
30
|
-
should_have_field :zendesk_base_url, type: String, default: 'https://app47.zendesk.com', klass: SystemConfiguration
|
31
|
-
should_have_field :zendesk_documentation_path, type: String, default: 'hc', klass: SystemConfiguration
|
32
|
-
should_have_field :zendesk_support_path, type: String, default: 'hc/en-us/requests', klass: SystemConfiguration
|
33
|
-
should_have_field :zendesk_updates_path, type: String, klass: SystemConfiguration, default: 'hc'
|
34
|
-
# AWS
|
35
|
-
should_have_field :aws_region, type: String, klass: SystemConfiguration
|
36
|
-
should_have_field :aws_secret_access_key, type: String, klass: SystemConfiguration
|
37
|
-
should_have_field :aws_secret_access_key, type: String, klass: SystemConfiguration
|
38
|
-
should_have_field :aws_auto_scaling_group_name, type: String, klass: SystemConfiguration
|
39
|
-
# Switchboard
|
40
|
-
should_have_field :switchboard_base_url, type: String, klass: SystemConfiguration, default: 'https://switchboard.app47.com'
|
41
|
-
should_have_field :switchboard_stack_id, type: String, klass: SystemConfiguration
|
42
|
-
should_have_field :switchboard_stack_api_token, type: String, klass: SystemConfiguration
|
43
|
-
|
44
|
-
teardown do
|
45
|
-
Rails.cache.delete 'SystemConfiguration::test'
|
46
|
-
end
|
47
|
-
|
48
|
-
context 'default behavior' do
|
49
|
-
should 'automatically create a system configuration' do
|
50
|
-
SystemConfiguration.destroy_all
|
51
|
-
assert_equal 0, SystemConfiguration.all.count
|
52
|
-
SystemConfiguration.configuration
|
53
|
-
assert_equal 1, SystemConfiguration.all.count
|
54
|
-
end
|
55
|
-
should 'have default values' do
|
56
|
-
assert_equal 587, SystemConfiguration.smtp_port
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'handle exception' do
|
61
|
-
should 'deal with rails catch throwing an exception' do
|
62
|
-
Rails.cache.expects(:fetch).once.raises(ArgumentError)
|
63
|
-
Rails.cache.expects(:delete).twice
|
64
|
-
SystemConfiguration.expects(:create).never
|
65
|
-
SystemConfiguration.base_url
|
66
|
-
Rails.cache.unstub(:fetch)
|
67
|
-
Rails.cache.unstub(:delete)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'handle' do
|
72
|
-
should 'respond_to_missing?' do
|
73
|
-
assert SystemConfiguration.respond_to? 'base_url'
|
74
|
-
refute SystemConfiguration.respond_to? 'url'
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'only call things once' do
|
79
|
-
setup do
|
80
|
-
if SystemConfiguration.all.blank?
|
81
|
-
SystemConfiguration.create!(base_url: 'http://somewhere.com',
|
82
|
-
environment: Rails.env,
|
83
|
-
smtp_name: 'SMTP')
|
84
|
-
end
|
85
|
-
SystemConfiguration.expects(:where).once.returns(SystemConfiguration.all)
|
86
|
-
end
|
87
|
-
should 'only call once' do
|
88
|
-
SystemConfiguration.base_url
|
89
|
-
SystemConfiguration.smtp_port
|
90
|
-
SystemConfiguration.smtp_name
|
91
|
-
end
|
92
|
-
should 'update base_url' do
|
93
|
-
url = 'http://something.new'
|
94
|
-
config = SystemConfiguration.all.first || SystemConfiguration.new
|
95
|
-
config.update_attributes!(base_url: url)
|
96
|
-
assert_equal url, SystemConfiguration.base_url
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context 'smtp configuration' do
|
101
|
-
should 'have smtp config' do
|
102
|
-
smtp_config = SystemConfiguration.smtp_configuration
|
103
|
-
assert_not_nil smtp_config
|
104
|
-
assert_not_empty smtp_config
|
105
|
-
end
|
106
|
-
should 'not be configured' do
|
107
|
-
refute SystemConfiguration.smtp_configured?
|
108
|
-
refute SystemConfiguration.mailgun_configured?
|
109
|
-
end
|
110
|
-
should 'be configured' do
|
111
|
-
assert SystemConfiguration.configuration.update smtp_name: 'app47', smtp_address: 'app47.com', smtp_domain: 'app47.com'
|
112
|
-
assert SystemConfiguration.smtp_configured?
|
113
|
-
refute SystemConfiguration.mailgun_configured?
|
114
|
-
end
|
115
|
-
should 'be configured with mailgun' do
|
116
|
-
assert SystemConfiguration.configuration.update smtp_name: 'app47', smtp_address: 'app47.com', smtp_domain: 'app47.com', mailgun_api_key: 'abc123'
|
117
|
-
assert SystemConfiguration.smtp_configured?
|
118
|
-
assert SystemConfiguration.mailgun_configured?
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
context 'aws configuration' do
|
123
|
-
should 'not be configured' do
|
124
|
-
refute SystemConfiguration.aws_configured?
|
125
|
-
refute SystemConfiguration.aws_auto_scaling_configured?
|
126
|
-
end
|
127
|
-
should 'aws is configured' do
|
128
|
-
assert SystemConfiguration.configuration.update aws_region: 'us'
|
129
|
-
refute SystemConfiguration.aws_configured?
|
130
|
-
refute SystemConfiguration.aws_auto_scaling_configured?
|
131
|
-
assert SystemConfiguration.configuration.update aws_access_key_id: 'key'
|
132
|
-
refute SystemConfiguration.aws_configured?
|
133
|
-
refute SystemConfiguration.aws_auto_scaling_configured?
|
134
|
-
assert SystemConfiguration.configuration.update aws_secret_access_key: 'abc123'
|
135
|
-
assert SystemConfiguration.aws_configured?
|
136
|
-
refute SystemConfiguration.aws_auto_scaling_configured?
|
137
|
-
assert SystemConfiguration.configuration.update aws_auto_scaling_group_name: 'g1'
|
138
|
-
assert SystemConfiguration.aws_configured?
|
139
|
-
assert SystemConfiguration.aws_auto_scaling_configured?
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
context 'twilio configuration' do
|
144
|
-
should 'not be configured' do
|
145
|
-
refute SystemConfiguration.twilio_configured?
|
146
|
-
end
|
147
|
-
should 'configured' do
|
148
|
-
assert SystemConfiguration.configuration.update twilio_account_id: 'us'
|
149
|
-
refute SystemConfiguration.twilio_configured?
|
150
|
-
assert SystemConfiguration.configuration.update twilio_auth_token: 'key'
|
151
|
-
refute SystemConfiguration.twilio_configured?
|
152
|
-
assert SystemConfiguration.configuration.update twilio_phone_number: 'abc123'
|
153
|
-
assert SystemConfiguration.twilio_configured?
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context 'switchboard configuration' do
|
158
|
-
should 'not be configured' do
|
159
|
-
refute SystemConfiguration.switchboard_configured?
|
160
|
-
end
|
161
|
-
should 'configured' do
|
162
|
-
assert SystemConfiguration.configuration.update switchboard_base_url: 'us'
|
163
|
-
refute SystemConfiguration.switchboard_configured?
|
164
|
-
assert SystemConfiguration.configuration.update switchboard_stack_api_token: 'key'
|
165
|
-
refute SystemConfiguration.switchboard_configured?
|
166
|
-
assert SystemConfiguration.configuration.update switchboard_stack_id: 'abc123'
|
167
|
-
assert SystemConfiguration.switchboard_configured?
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
context 'zendesk configuration' do
|
172
|
-
should 'not be configured' do
|
173
|
-
refute SystemConfiguration.zendesk_configured?
|
174
|
-
end
|
175
|
-
should 'configured' do
|
176
|
-
assert SystemConfiguration.configuration.update zendesk_token: 'us'
|
177
|
-
assert SystemConfiguration.zendesk_configured?
|
178
|
-
end
|
179
|
-
should 'zendesk url with no user' do
|
180
|
-
assert_equal 'https://app47.zendesk.com/hc', SystemConfiguration.zendesk_url
|
181
|
-
assert_equal 'https://app47.zendesk.com/hc', SystemConfiguration.zendesk_documentation_url
|
182
|
-
assert_equal 'https://app47.zendesk.com/hc/en-us/requests', SystemConfiguration.zendesk_requests_url
|
183
|
-
assert_equal 'https://app47.zendesk.com/hc/en-us/requests/new', SystemConfiguration.zendesk_new_request_url
|
184
|
-
assert_equal 'https://app47.zendesk.com/hc', SystemConfiguration.zendesk_updates_url
|
185
|
-
end
|
186
|
-
should 'zendesk url with user but not configured' do
|
187
|
-
user = MockUser.new email: 'foo@bar.com'
|
188
|
-
assert_equal 'https://app47.zendesk.com/hc', SystemConfiguration.zendesk_url(user: user)
|
189
|
-
assert_equal 'https://app47.zendesk.com/hc', SystemConfiguration.zendesk_documentation_url(user)
|
190
|
-
assert_equal 'https://app47.zendesk.com/hc/en-us/requests', SystemConfiguration.zendesk_requests_url(user)
|
191
|
-
assert_equal 'https://app47.zendesk.com/hc/en-us/requests/new', SystemConfiguration.zendesk_new_request_url(user)
|
192
|
-
assert_equal 'https://app47.zendesk.com/hc', SystemConfiguration.zendesk_updates_url(user)
|
193
|
-
end
|
194
|
-
should 'zendesk url with user and configured' do
|
195
|
-
assert SystemConfiguration.configuration.update zendesk_token: 'us'
|
196
|
-
user = MockUser.create(email: 'foo@bar.com', name: 'Foo')
|
197
|
-
assert_not_nil user
|
198
|
-
assert SystemConfiguration.zendesk_url(user: user).start_with?('https://app47.zendesk.com/access/jwt?jwt=')
|
199
|
-
assert SystemConfiguration.zendesk_documentation_url(user).start_with?('https://app47.zendesk.com/access/jwt?jwt=')
|
200
|
-
assert SystemConfiguration.zendesk_requests_url(user).start_with?('https://app47.zendesk.com/access/jwt?jwt=')
|
201
|
-
assert SystemConfiguration.zendesk_new_request_url(user).start_with?('https://app47.zendesk.com/access/jwt?jwt=')
|
202
|
-
assert SystemConfiguration.zendesk_updates_url(user).start_with?('https://app47.zendesk.com/access/jwt?jwt=')
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
class MockUser
|
208
|
-
include StandardModel
|
209
|
-
field :email, type: String
|
210
|
-
field :name, type: String
|
211
|
-
end
|
212
|
-
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
# Test the Searchable module
|
6
|
-
#
|
7
|
-
class TimeZoneAbleTest < ActiveSupport::TestCase
|
8
|
-
context 'have default' do
|
9
|
-
should 'set default' do
|
10
|
-
o = TimeZoneTestObject.new
|
11
|
-
assert_nil o.time_zone
|
12
|
-
assert o.save
|
13
|
-
assert_equal 'US/Eastern', o.time_zone
|
14
|
-
end
|
15
|
-
should 'have valid field values' do
|
16
|
-
o = TimeZoneTestObject.new
|
17
|
-
TZInfo::Timezone.all_identifiers.each do |tz|
|
18
|
-
o.time_zone = tz
|
19
|
-
assert o.valid?, o.errors.inspect
|
20
|
-
end
|
21
|
-
end
|
22
|
-
should 'invalid format' do
|
23
|
-
o = TimeZoneTestObject.new
|
24
|
-
o.time_zone = 'Eastern/US'
|
25
|
-
refute o.valid?
|
26
|
-
end
|
27
|
-
should 'pull from system configuration' do
|
28
|
-
assert SystemConfiguration.configuration.update default_time_zone: 'EST'
|
29
|
-
o = TimeZoneTestObject.new
|
30
|
-
assert_nil o.time_zone
|
31
|
-
assert o.save
|
32
|
-
assert_equal 'EST', o.time_zone
|
33
|
-
end
|
34
|
-
end
|
35
|
-
context 'return local time' do
|
36
|
-
setup do
|
37
|
-
@test_obj = TimeZoneTestObject.create!
|
38
|
-
@now = Time.now.utc
|
39
|
-
end
|
40
|
-
should 'give same as account' do
|
41
|
-
tz = TZInfo::Timezone.get('US/Eastern')
|
42
|
-
assert_equal I18n.l(@now.in_time_zone(tz), format: :medium), @test_obj.local_time(@now)
|
43
|
-
end
|
44
|
-
should 'handle error' do
|
45
|
-
TZInfo::Timezone.expects(:get).once.raises('Doh')
|
46
|
-
assert_equal 'Never now', @test_obj.local_time(@now, :medium, 'Never now')
|
47
|
-
end
|
48
|
-
should 'handle error with default' do
|
49
|
-
TZInfo::Timezone.expects(:get).once.raises('Doh')
|
50
|
-
assert_equal 'N/A', @test_obj.local_time(@now)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
context 'return updated_at' do
|
54
|
-
setup do
|
55
|
-
@test_obj = TimeZoneTestObject.create!
|
56
|
-
@now = Time.now.utc
|
57
|
-
end
|
58
|
-
should 'give same as account' do
|
59
|
-
tz = TZInfo::Timezone.get('US/Eastern')
|
60
|
-
assert_equal I18n.l(@now.in_time_zone(tz), format: :medium), @test_obj.local_updated_time(@test_obj)
|
61
|
-
end
|
62
|
-
should 'handle error' do
|
63
|
-
@test_obj.expects(:updated_at).once.raises('Doh')
|
64
|
-
assert_equal 'Never now', @test_obj.local_updated_time(@test_obj, :medium, 'Never now')
|
65
|
-
end
|
66
|
-
should 'handle error with default' do
|
67
|
-
@test_obj.expects(:updated_at).once.raises('Doh')
|
68
|
-
assert_equal 'N/A', @test_obj.local_updated_time(@test_obj)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class TimeZoneTestObject
|
74
|
-
include Mongoid::Document
|
75
|
-
include Mongoid::Timestamps
|
76
|
-
include TimeZoneAble
|
77
|
-
end
|
@@ -1,297 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'notification_test_helper'
|
3
|
-
|
4
|
-
class EmailNotificationTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
include Mail::Matchers
|
7
|
-
include NotificationTestHelper
|
8
|
-
|
9
|
-
setup do
|
10
|
-
@account = FactoryBot.create(:account)
|
11
|
-
assert_not_nil @account
|
12
|
-
assert @account.persisted?
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'Create simple account notification' do
|
16
|
-
setup do
|
17
|
-
@email = EmailNotification.new
|
18
|
-
@email.account = @account
|
19
|
-
@email.to = 'a@app47.com'
|
20
|
-
@email.message = 'Now is the time for all men to come to the aid of their country'
|
21
|
-
@email.subject = 'Testing'
|
22
|
-
assert @email.save
|
23
|
-
assert @email.send_notification
|
24
|
-
end
|
25
|
-
should 'Have one email notification that is successfully sent' do
|
26
|
-
mails = Mail::TestMailer.deliveries
|
27
|
-
assert_equal 1, mails.count, 'Should only send one email'
|
28
|
-
mail = mails.first
|
29
|
-
assert_equal 'support@app47.com', mail.from.first, 'Should send from default mailer'
|
30
|
-
end
|
31
|
-
|
32
|
-
# MAM-8438 Hide the image better
|
33
|
-
should 'have the notifications url in the email to track it' do
|
34
|
-
mail_body = Mail::TestMailer.deliveries.first.all_parts.first.body
|
35
|
-
assert mail_body.include?("notifications/#{@email.id}/img"), mail_body.inspect
|
36
|
-
assert mail_body.include?("style='height:0;width:0;border:none;display:none;'"), mail_body.inspect
|
37
|
-
end
|
38
|
-
end
|
39
|
-
# context 'MAM-5971' do
|
40
|
-
# should 'have mailgun smtp header when mailgun configured' do
|
41
|
-
# email = EmailNotification.new
|
42
|
-
# email.account = @account
|
43
|
-
# email.to = 'a@app47.com'
|
44
|
-
# email.message = 'Now is the time for all men to come to the aid of their country'
|
45
|
-
# email.subject = 'Testing'
|
46
|
-
# assert email.save
|
47
|
-
# assert email.send_notification
|
48
|
-
# mail = Mail::TestMailer.deliveries.first
|
49
|
-
# assert_equal 'yes', mail.header['X-Mailgun-Native-Send'].value, mail.header.inspect
|
50
|
-
# end
|
51
|
-
# should 'NOT have mailgun smtp header when mailgun not configured' do
|
52
|
-
# config = SystemConfiguration.configuration
|
53
|
-
# config.mailgun_api_key = nil
|
54
|
-
# assert config.save
|
55
|
-
# email = EmailNotification.new
|
56
|
-
# email.account = @account
|
57
|
-
# email.to = 'a@app47.com'
|
58
|
-
# email.message = 'Now is the time for all men to come to the aid of their country'
|
59
|
-
# email.subject = 'Testing'
|
60
|
-
# assert email.save
|
61
|
-
# assert email.send_notification
|
62
|
-
# mail = Mail::TestMailer.deliveries.first
|
63
|
-
# assert_nil mail.header['X-Mailgun-Native-Send'], mail.header.inspect
|
64
|
-
# end
|
65
|
-
# end
|
66
|
-
|
67
|
-
context 'Create an account notification with an array of addresses' do
|
68
|
-
setup {
|
69
|
-
email = EmailNotification.new
|
70
|
-
email.account = @account
|
71
|
-
email.to = ['a@app47.com', 'b@app47.com', 'c@app47.com']
|
72
|
-
email.message = 'Now is the time for all men to come to the aid of their country'
|
73
|
-
email.subject = 'Testing'
|
74
|
-
assert email.save
|
75
|
-
assert email.send_notification
|
76
|
-
}
|
77
|
-
should 'send three emails' do
|
78
|
-
mails = Mail::TestMailer.deliveries
|
79
|
-
email = mails.first
|
80
|
-
assert email.to.include?('a@app47.com'), email.to.inspect
|
81
|
-
assert email.to.include?('b@app47.com'), email.to.inspect
|
82
|
-
assert email.to.include?('c@app47.com'), email.to.inspect
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# context 'Create account notification with smtp configuration' do
|
87
|
-
# setup {
|
88
|
-
# smtp = @account.fetch_or_build_smtp_configuration
|
89
|
-
# smtp.email_address = "blue@red.com"
|
90
|
-
# smtp.active = true
|
91
|
-
# smtp.username = 'purple'
|
92
|
-
# smtp.server_name = 'lost.in.space'
|
93
|
-
# assert smtp.save!
|
94
|
-
# # Need to set the confirmation manually as it's reset every time the smtp
|
95
|
-
# # config is saved
|
96
|
-
# smtp.set(confirmed: true)
|
97
|
-
#
|
98
|
-
# email = EmailNotification.new
|
99
|
-
# email.account = @account
|
100
|
-
# email.to = 'a@app47.com'
|
101
|
-
# email.message = 'Now is the time for all men to come to the aid of their country'
|
102
|
-
# email.subject = 'Testing'
|
103
|
-
# assert email.save
|
104
|
-
# Mail::TestMailer.deliveries.clear
|
105
|
-
# assert email.deliver
|
106
|
-
# }
|
107
|
-
# should 'Have one email notification that is successfully sent' do
|
108
|
-
# mails = Mail::TestMailer.deliveries
|
109
|
-
# assert_equal 1, mails.count, "Should only send one email"
|
110
|
-
# mail = mails.first
|
111
|
-
# assert_equal "purple", mail.sender, "Should send from smtp settings"
|
112
|
-
# end
|
113
|
-
# end
|
114
|
-
|
115
|
-
# context 'Fail to send email via smtp ' do
|
116
|
-
# setup {
|
117
|
-
# # Kill the reporting of the error so it doesn't look like an error on the test run.
|
118
|
-
# EmailNotification.any_instance.expects(:log_error).at_least_once
|
119
|
-
# FactoryBot.create(:member_has_role_view, account: @account)
|
120
|
-
# @admin = FactoryBot.create(:member_has_role_admin, account: @account)
|
121
|
-
# @account.smtp_configuration = FactoryBot.build(:active_smtp_configuration)
|
122
|
-
# assert @account.save
|
123
|
-
# @account.fetch_or_build_smtp_configuration.set(confirmed: true)
|
124
|
-
# EmailNotification.destroy_all
|
125
|
-
# email = EmailNotification.new
|
126
|
-
# email.account = @account
|
127
|
-
# email.to = 'a@app47.com'
|
128
|
-
# email.subject = 'Fail' # This matches the exception below in the monkey patch
|
129
|
-
# email.message = "me"
|
130
|
-
# assert email.save
|
131
|
-
# assert email.deliver
|
132
|
-
# }
|
133
|
-
# should 'have an email to the admin that the notification failed' do
|
134
|
-
# mails = Mail::TestMailer.deliveries
|
135
|
-
# assert_equal 1, mails.count, "Email should be to admin though"
|
136
|
-
# mail = mails.first
|
137
|
-
# assert_equal @admin.email, mail.to.first, "Should send to the smtp admin"
|
138
|
-
# assert_equal "Failed to send email notification", mail.subject
|
139
|
-
#
|
140
|
-
# email = EmailNotification.excludes(account_id: nil).first
|
141
|
-
# assert_not_nil email
|
142
|
-
# assert email.state.eql? NotificationState::INVALID
|
143
|
-
# email = EmailNotification.where(account_id: nil).first
|
144
|
-
# assert_not_nil email
|
145
|
-
# assert email.state.eql? NotificationState::PROCESSED
|
146
|
-
# end
|
147
|
-
#
|
148
|
-
# end
|
149
|
-
|
150
|
-
context 'Set reply to and from addresses on email correctly' do
|
151
|
-
should 'No reply to and from based on system configuration' do
|
152
|
-
email = EmailNotification.new(account: @account)
|
153
|
-
email.to = 'a@app47.com'
|
154
|
-
email.from_template('notification_failure', test_values)
|
155
|
-
assert email.save
|
156
|
-
assert_nothing_raised { email.send_notification }
|
157
|
-
|
158
|
-
mails = Mail::TestMailer.deliveries
|
159
|
-
assert_equal 1, mails.count, "Should only send one email"
|
160
|
-
mail = mails.first
|
161
|
-
|
162
|
-
assert_equal SystemConfiguration.default_email, mail.from.first, "Should send from default mailer"
|
163
|
-
assert_nil mail.reply_to, "Reply to should be nil: #{mail.inspect}"
|
164
|
-
end
|
165
|
-
|
166
|
-
# should 'no reply to and from address from SMTP configuration' do
|
167
|
-
# @account.smtp_configuration = FactoryBot.build(:active_smtp_configuration)
|
168
|
-
# assert @account.save
|
169
|
-
# @account.smtp_configuration.set(confirmed: true)
|
170
|
-
# email = EmailNotification.new(account: @account)
|
171
|
-
# email.to = 'a@app47.com'
|
172
|
-
# email.from_template(AccountEmailTemplate::APP_STORE_USER_INVITE, test_values)
|
173
|
-
# assert email.save
|
174
|
-
# assert_nothing_raised { email.deliver }
|
175
|
-
#
|
176
|
-
# mails = Mail::TestMailer.deliveries
|
177
|
-
# assert_equal 1, mails.count, "Should only send one email"
|
178
|
-
# mail = mails.first
|
179
|
-
#
|
180
|
-
# assert_equal @account.smtp_configuration.email_address, mail.from.first, mail.inspect
|
181
|
-
# assert_nil mail.reply_to, "Reply to should be nil: #{mail.inspect}"
|
182
|
-
# end
|
183
|
-
# should 'no reply to and from address from system configuration because smtp is not confirmed' do
|
184
|
-
# @account.smtp_configuration = FactoryBot.build(:active_smtp_configuration)
|
185
|
-
# assert @account.save
|
186
|
-
# email = EmailNotification.new(account: @account)
|
187
|
-
# email.to = 'a@app47.com'
|
188
|
-
# email.from_template(AccountEmailTemplate::APP_STORE_USER_INVITE, test_values)
|
189
|
-
# assert email.save
|
190
|
-
# assert_nothing_raised { email.deliver }
|
191
|
-
#
|
192
|
-
# mails = Mail::TestMailer.deliveries
|
193
|
-
# assert_equal 1, mails.count, "Should only send one email"
|
194
|
-
# mail = mails.first
|
195
|
-
#
|
196
|
-
# assert_equal SystemConfiguration.default_email, mail.from.first, mail.inspect
|
197
|
-
# assert_nil mail.reply_to, "Reply to should be nil: #{mail.inspect}"
|
198
|
-
# end
|
199
|
-
|
200
|
-
end
|
201
|
-
|
202
|
-
def test_values
|
203
|
-
{
|
204
|
-
'app_store_name' => 'Test app store name',
|
205
|
-
'device_description' => 'Tom\'s iPad',
|
206
|
-
'device_unique_identifier' => 'abc123def132afd1213afas',
|
207
|
-
'device_model' => 'iPad 3',
|
208
|
-
'app_name' => 'Test app name',
|
209
|
-
'build_version' => '1.3',
|
210
|
-
'profile_expiration_date' => 'July 31, 1968 20:45Z',
|
211
|
-
'profile_name' => 'Test Ad Hoc Distro',
|
212
|
-
'builds_url' => "#{SystemConfiguration.base_url}/builds",
|
213
|
-
'show_branding' => true,
|
214
|
-
'release_notes' => 'Fixed app bugs, software is perfect now!!',
|
215
|
-
'invitation_message' => 'You are invited, join the fun!!',
|
216
|
-
'registration_url' => "#{SystemConfiguration.base_url}/register",
|
217
|
-
'invitation_url' => "#{SystemConfiguration.base_url}/invitation",
|
218
|
-
'reset_password_url' => "#{SystemConfiguration.base_url}/reset_password",
|
219
|
-
'require_authentication' => false,
|
220
|
-
'passphrase' => 'letmein123',
|
221
|
-
'passphrase_expiration' => '48 hours',
|
222
|
-
'user_name' => 'Test User',
|
223
|
-
'user_email' => 'test@abc.com',
|
224
|
-
'app_names' => ['app1', 'app2', 'app3'],
|
225
|
-
'user_url' => "#{SystemConfiguration.base_url}/users?search=test@abc.com"
|
226
|
-
}
|
227
|
-
end
|
228
|
-
|
229
|
-
# context 'email attachments' do
|
230
|
-
# should 'not have any attachments' do
|
231
|
-
# email = EmailNotification.new(account: @account)
|
232
|
-
# email.to = 'a@app47.com'
|
233
|
-
# email.from_template('notification_failure', test_values)
|
234
|
-
# assert email.save
|
235
|
-
# assert_nothing_raised { email.send_notification }
|
236
|
-
#
|
237
|
-
# assert_emails_attachment_count @account, 0
|
238
|
-
#
|
239
|
-
# mails = Mail::TestMailer.deliveries
|
240
|
-
# assert_equal 1, mails.count, 'Should only send one email'
|
241
|
-
# mail = mails.first
|
242
|
-
# assert_empty mail.attachments
|
243
|
-
# end
|
244
|
-
#
|
245
|
-
# should 'send one attachment' do
|
246
|
-
# email = EmailNotification.new(account: @account)
|
247
|
-
# email.to = 'a@app47.com'
|
248
|
-
# email.from_template('notification_failure', test_values)
|
249
|
-
# email.add_file 'test/etc/images/featured.jpg'
|
250
|
-
# assert email.save
|
251
|
-
# assert_nothing_raised { email.send_notification }
|
252
|
-
#
|
253
|
-
# assert_not_nil email.reload
|
254
|
-
# assert_equal Notification::STATE_PROCESSED, email.state
|
255
|
-
#
|
256
|
-
# assert_emails_attachment_count @account
|
257
|
-
#
|
258
|
-
# mails = Mail::TestMailer.deliveries
|
259
|
-
# assert_equal 1, mails.count, 'Should only send one email'
|
260
|
-
# mail = mails.first
|
261
|
-
# assert_equal 1, mail.attachments.count
|
262
|
-
# end
|
263
|
-
# should 'send two attachment' do
|
264
|
-
# email = EmailNotification.new(account: @account)
|
265
|
-
# email.to = 'a@app47.com'
|
266
|
-
# email.from_template('notification_failure', test_values)
|
267
|
-
# email.add_file 'test/etc/images/featured.jpg'
|
268
|
-
# email.add_file 'test/etc/images/featured.jpg'
|
269
|
-
# assert email.save
|
270
|
-
# assert_nothing_raised { email.send_notification }
|
271
|
-
#
|
272
|
-
# assert_not_nil email.reload
|
273
|
-
# assert_equal Notification::STATE_PROCESSED, email.state
|
274
|
-
#
|
275
|
-
# assert_emails_attachment_count @account, 2
|
276
|
-
#
|
277
|
-
# mails = Mail::TestMailer.deliveries
|
278
|
-
# assert_equal 1, mails.count, 'Should only send one email'
|
279
|
-
# mail = mails.first
|
280
|
-
# assert_equal 2, mail.attachments.count
|
281
|
-
# end
|
282
|
-
# end
|
283
|
-
|
284
|
-
end
|
285
|
-
|
286
|
-
# Override this method to thrown an exception if the subject is 'Fail'
|
287
|
-
module Mail
|
288
|
-
class TestMailer
|
289
|
-
|
290
|
-
def deliver!(mail)
|
291
|
-
throw Exception('Fail') if mail.subject.eql? 'Fail'
|
292
|
-
# check_delivery_params(mail)
|
293
|
-
Mail::TestMailer.deliveries << mail
|
294
|
-
end
|
295
|
-
|
296
|
-
end
|
297
|
-
end
|