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,25 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class JobCronTabTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
#
|
6
|
-
# Temp class for testing
|
7
|
-
#
|
8
|
-
class EmailModel
|
9
|
-
include Mongoid::Document
|
10
|
-
include Mongoid::Timestamps
|
11
|
-
include EmailAble
|
12
|
-
field :once, type: String
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
context 'ensure_cron_tabs' do
|
17
|
-
should 'start out with no cron tabs' do
|
18
|
-
assert_empty Cron::JobTab.all
|
19
|
-
end
|
20
|
-
should 'load everything in the cron tab' do
|
21
|
-
Cron::JobTab.ensure_cron_tabs
|
22
|
-
assert_not_empty Cron::JobTab.all
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class NotificationTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
should_have_field :retries, type: Integer, default: 0, klass: Notification
|
6
|
-
should_have_field :state, type: String, default: 'new', klass: Notification
|
7
|
-
should_have_field :to, type: String, klass: Notification
|
8
|
-
should_have_field :message, type: String, klass: Notification
|
9
|
-
should_have_field :error_message, type: String, klass: Notification
|
10
|
-
should_have_field :last_viewed_at, type: Time, klass: Notification
|
11
|
-
should_have_field :viewed_count, type: Integer, default: 0, klass: Notification
|
12
|
-
|
13
|
-
setup do
|
14
|
-
@account = FactoryBot.create(:account)
|
15
|
-
end
|
16
|
-
|
17
|
-
should 'Determine which states are deletable' do
|
18
|
-
notification = FactoryBot.create(:notification)
|
19
|
-
assert notification.deletable?
|
20
|
-
notification.set(state: Notification::STATE_SUBMITTED)
|
21
|
-
refute notification.deletable?
|
22
|
-
notification.set(state: Notification::STATE_PROCESSING)
|
23
|
-
refute notification.deletable?
|
24
|
-
notification.set(state: Notification::STATE_PROCESSED)
|
25
|
-
assert notification.deletable?
|
26
|
-
notification.set(state: Notification::STATE_INVALID)
|
27
|
-
assert notification.deletable?
|
28
|
-
notification.set(state: Notification::STATE_RETRYING)
|
29
|
-
refute notification.deletable?
|
30
|
-
notification.set(state: Notification::STATE_VIEWED)
|
31
|
-
assert notification.deletable?
|
32
|
-
end
|
33
|
-
|
34
|
-
should 'Determine which states are sendable' do
|
35
|
-
notification = FactoryBot.create(:notification)
|
36
|
-
assert notification.sendable?
|
37
|
-
notification.set(state: Notification::STATE_SUBMITTED)
|
38
|
-
refute notification.sendable?
|
39
|
-
notification.set(state: Notification::STATE_PROCESSING)
|
40
|
-
refute notification.sendable?
|
41
|
-
notification.set(state: Notification::STATE_PROCESSED)
|
42
|
-
assert notification.sendable?
|
43
|
-
notification.set(state: Notification::STATE_INVALID)
|
44
|
-
assert notification.sendable?
|
45
|
-
notification.set(state: Notification::STATE_RETRYING)
|
46
|
-
refute notification.sendable?
|
47
|
-
notification.set(state: Notification::STATE_VIEWED)
|
48
|
-
assert notification.sendable?
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
should 'find file based template' do
|
53
|
-
notification = FactoryBot.create(:notification, account: @account)
|
54
|
-
notification.message_from_template('notification_failure', {error_message: 'Yo, Adrian'})
|
55
|
-
assert notification.message.include? 'Failed to send the following notification'
|
56
|
-
assert notification.message.include? 'Yo, Adrian'
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
# should 'find account based template' do
|
61
|
-
# template = AccountEmailTemplate.new
|
62
|
-
# template.account = @account
|
63
|
-
# template.name = 'enterprise_app_store_user_invite'
|
64
|
-
# template.template = 'custom baby {{ name }}'
|
65
|
-
# template.subject = 'yo'
|
66
|
-
# assert template.save
|
67
|
-
#
|
68
|
-
# notification = FactoryBot.create(:notification, account: @account)
|
69
|
-
# notification.message_from_template('enterprise_app_store_user_invite', {'name'=> 'foo'})
|
70
|
-
# assert_equal '<body><pre>custom baby foo</pre></body>', notification.message
|
71
|
-
# end
|
72
|
-
|
73
|
-
should 'mark notification as viewed' do
|
74
|
-
notification = FactoryBot.create(:notification, account:@account)
|
75
|
-
assert_not_nil notification
|
76
|
-
assert_equal 0, notification.viewed_count
|
77
|
-
assert_nil notification.last_viewed_at
|
78
|
-
|
79
|
-
# Allow some breather room
|
80
|
-
sleep 1
|
81
|
-
|
82
|
-
notification.viewed
|
83
|
-
assert_not_nil notification.reload
|
84
|
-
assert_equal Notification::STATE_VIEWED, notification.state
|
85
|
-
assert_equal 1, notification.viewed_count
|
86
|
-
first_date = notification.last_viewed_at
|
87
|
-
|
88
|
-
# Allow some breather room
|
89
|
-
sleep 1
|
90
|
-
|
91
|
-
# view it a second time, should up the counter
|
92
|
-
notification.viewed
|
93
|
-
assert_not_nil notification.reload
|
94
|
-
assert_equal Notification::STATE_VIEWED, notification.state
|
95
|
-
assert_equal 2, notification.viewed_count
|
96
|
-
assert_not_equal first_date, notification.last_viewed_at, notification.inspect
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
context 'use both token and strings' do
|
101
|
-
setup do
|
102
|
-
@liquid_text = 'Yo {{ name }}'
|
103
|
-
@notification = Notification.new
|
104
|
-
end
|
105
|
-
|
106
|
-
should 'work with strings' do
|
107
|
-
params = { 'name' => 'chris' }
|
108
|
-
assert_equal 'Yo chris', @notification.send(:render_liquid_text, @liquid_text, params)
|
109
|
-
end
|
110
|
-
|
111
|
-
should 'work with tokens' do
|
112
|
-
params = { name: 'chris' }
|
113
|
-
assert_equal 'Yo chris', @notification.send(:render_liquid_text, @liquid_text, params)
|
114
|
-
end
|
115
|
-
|
116
|
-
should 'handle true values' do
|
117
|
-
liquid_text = 'Yo{% if show %} {{ name }}{% endif %}'
|
118
|
-
params = { name: 'chris', show: true}
|
119
|
-
assert_equal 'Yo chris', @notification.send(:render_liquid_text, liquid_text, params)
|
120
|
-
end
|
121
|
-
should 'handle false values' do
|
122
|
-
liquid_text = 'Yo{% if show %} {{ name }}{% endif %}'
|
123
|
-
params = { name: 'chris', show: false}
|
124
|
-
assert_equal 'Yo', @notification.send(:render_liquid_text, liquid_text, params)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
#
|
4
|
-
# Test the RedisConfiguration model
|
5
|
-
#
|
6
|
-
class RedisConfigurationTest < ActiveSupport::TestCase
|
7
|
-
context 'default file' do
|
8
|
-
should 'return the default configuration file the config file' do
|
9
|
-
config = RedisConfiguration.load
|
10
|
-
refute config[:url].eql?('redis://127.0.0.1:6379'), config.inspect
|
11
|
-
assert_equal 0, config[:db], config.inspect
|
12
|
-
end
|
13
|
-
should 'override the database' do
|
14
|
-
config = RedisConfiguration.load(9)
|
15
|
-
refute config[:url].eql?('redis://127.0.0.1:6379'), config.inspect
|
16
|
-
assert_equal 9, config[:db], config.inspect
|
17
|
-
end
|
18
|
-
end
|
19
|
-
context 'no file' do
|
20
|
-
setup do
|
21
|
-
RedisConfiguration.expects(:config_file_path).returns('config/nothing').at_least_once
|
22
|
-
end
|
23
|
-
should 'return default' do
|
24
|
-
config = RedisConfiguration.load
|
25
|
-
assert_equal '127.0.0.1', config[:host], config.inspect
|
26
|
-
assert_equal 6379, config[:port], config.inspect
|
27
|
-
assert_equal 0, config[:db], config.inspect
|
28
|
-
end
|
29
|
-
should 'set the database' do
|
30
|
-
config = RedisConfiguration.load(5)
|
31
|
-
assert_equal '127.0.0.1', config[:host], config.inspect
|
32
|
-
assert_equal 6379, config[:port], config.inspect
|
33
|
-
assert_equal 5, config[:db], config.inspect
|
34
|
-
end
|
35
|
-
end
|
36
|
-
context 'url' do
|
37
|
-
setup do
|
38
|
-
RedisConfiguration.expects(:config_file_path).returns('test/fixtures/redis/url.yml').at_least_once
|
39
|
-
end
|
40
|
-
should 'return url configuration' do
|
41
|
-
config = RedisConfiguration.load
|
42
|
-
# assert_equal 'redis://localhost:6379/0', config[:url], config.inspect
|
43
|
-
end
|
44
|
-
end
|
45
|
-
context 'host' do
|
46
|
-
setup do
|
47
|
-
RedisConfiguration.expects(:config_file_path).returns('test/fixtures/redis/host.yml').at_least_once
|
48
|
-
end
|
49
|
-
should 'load from file' do
|
50
|
-
config = RedisConfiguration.load
|
51
|
-
assert_equal '127.0.0.1', config[:host], config.inspect
|
52
|
-
assert_equal 6378, config[:port], config.inspect
|
53
|
-
assert_equal 8, config[:db], config.inspect
|
54
|
-
assert_equal 'cache', config[:namespace], config.inspect
|
55
|
-
end
|
56
|
-
should 'load from file and override database number' do
|
57
|
-
config = RedisConfiguration.load(6)
|
58
|
-
assert_equal '127.0.0.1', config[:host], config.inspect
|
59
|
-
assert_equal 6378, config[:port], config.inspect
|
60
|
-
assert_equal 6, config[:db], config.inspect
|
61
|
-
end
|
62
|
-
end
|
63
|
-
context 'sentinel' do
|
64
|
-
setup do
|
65
|
-
RedisConfiguration.expects(:config_file_path).returns('test/fixtures/redis/sentinel.yml').at_least_once
|
66
|
-
end
|
67
|
-
should 'load file' do
|
68
|
-
config = RedisConfiguration.load
|
69
|
-
assert_equal 'redis://production', config[:url], config.inspect
|
70
|
-
assert_equal 'master', config[:role], config.inspect
|
71
|
-
sentinels = config[:sentinels]
|
72
|
-
assert_not_nil sentinels
|
73
|
-
assert_equal 3, sentinels.count
|
74
|
-
assert_equal 'host1', sentinels.first[:host]
|
75
|
-
assert_equal 0, config[:db], config.inspect
|
76
|
-
assert_equal 'cache', config[:namespace], config.inspect
|
77
|
-
end
|
78
|
-
should 'load file and set database' do
|
79
|
-
config = RedisConfiguration.load(8)
|
80
|
-
sentinels = config[:sentinels]
|
81
|
-
assert_not_nil sentinels
|
82
|
-
assert_equal 3, sentinels.count, config.inspect
|
83
|
-
assert_equal 8, config[:db], config.inspect
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'notification_test_helper'
|
3
|
-
|
4
|
-
class SlackNotificationTest < ActiveSupport::TestCase
|
5
|
-
include App47Logger
|
6
|
-
include NotificationTestHelper
|
7
|
-
|
8
|
-
should_have_field :from, type: String, klass: SlackNotification
|
9
|
-
|
10
|
-
setup do
|
11
|
-
config = SystemConfiguration.configuration
|
12
|
-
config.update_attribute :slack_api_url, 'https://slack.com?api_key'
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'send messages' do
|
16
|
-
should 'an array' do
|
17
|
-
stub = stub_request(:post, "https://slack.com/?api_key").
|
18
|
-
with(body: "{\"text\":\"one\\ntwo\\nthree\",\"channel\":\"support\",\"username\":\"test\"}").
|
19
|
-
to_return(status: 200, body: "", headers: {})
|
20
|
-
SlackNotification.say %w[one two three]
|
21
|
-
assert_requested stub
|
22
|
-
end
|
23
|
-
should 'to fred' do
|
24
|
-
stub = stub_request(:post, "https://slack.com/?api_key").
|
25
|
-
with(body: "{\"text\":\"one\\ntwo\\nthree\",\"channel\":\"fred\",\"username\":\"test\"}").
|
26
|
-
to_return(status: 200, body: "", headers: {})
|
27
|
-
SlackNotification.say %w[one two three], to: 'fred'
|
28
|
-
assert_requested stub
|
29
|
-
end
|
30
|
-
should 'sysconfig slack_support_channel' do
|
31
|
-
assert SystemConfiguration.configuration.update slack_support_channel: 'a'
|
32
|
-
stub = stub_request(:post, "https://slack.com/?api_key").
|
33
|
-
with(body: "{\"text\":\"one\\ntwo\\nthree\",\"channel\":\"a\",\"username\":\"test\"}").
|
34
|
-
to_return(status: 200, body: "", headers: {})
|
35
|
-
SlackNotification.say %w[one two three]
|
36
|
-
assert_requested stub
|
37
|
-
end
|
38
|
-
should 'handle errors' do
|
39
|
-
RestClient.expects(:post).once.raises('Doh')
|
40
|
-
App47Logger.expects(:log_warn).once
|
41
|
-
SlackNotification.say %w[one two three]
|
42
|
-
slack = SlackNotification.first
|
43
|
-
assert_not_nil slack
|
44
|
-
refute slack.successful?, slack.inspect
|
45
|
-
assert_equal 'Doh', slack.error_message, slack.inspect
|
46
|
-
end
|
47
|
-
should 'record error on not configured' do
|
48
|
-
assert SystemConfiguration.configuration.update slack_api_url: nil
|
49
|
-
SlackNotification.say %w[one two three]
|
50
|
-
slack = SlackNotification.first
|
51
|
-
assert_not_nil slack
|
52
|
-
refute slack.successful?, slack.inspect
|
53
|
-
assert_equal 'Slack is not configured', slack.error_message, slack.inspect
|
54
|
-
end
|
55
|
-
end
|
56
|
-
context 'No slack notification' do
|
57
|
-
should 'not create a slack notification with log_debug' do
|
58
|
-
App47Logger.expects(:log_message).with(:warn, 'Test log message').once
|
59
|
-
log_warn 'Test log message'
|
60
|
-
assert_no_slacks
|
61
|
-
end
|
62
|
-
end
|
63
|
-
context 'send notification' do
|
64
|
-
should 'Log error message' do
|
65
|
-
stub = stub_request(:post, "https://slack.com/?api_key").
|
66
|
-
with(body: "{\"text\":\"*ERROR:* `Test log message`\",\"channel\":\"support\",\"username\":\"test\"}").
|
67
|
-
to_return(status: 200, body: "", headers: {})
|
68
|
-
App47Logger.expects(:log_message).with(:error, 'Test log message').once
|
69
|
-
log_error 'Test log message'
|
70
|
-
assert_slacks_count
|
71
|
-
assert_slacks_includes('Test log message')
|
72
|
-
assert_requested stub
|
73
|
-
end
|
74
|
-
should 'Log error with exception' do
|
75
|
-
stub = stub_request(:post, "https://slack.com/?api_key").
|
76
|
-
with(body: "{\"text\":\"*ERROR:* `Test log message` - `Ex`\",\"channel\":\"support\",\"username\":\"test\"}").
|
77
|
-
to_return(status: 200, body: "", headers: {})
|
78
|
-
App47Logger.expects(:log_message).with(:error, 'Test log message').once
|
79
|
-
App47Logger.expects(:log_message).with(:error, 'Ex').once
|
80
|
-
ex = Exception.new('Ex')
|
81
|
-
log_error 'Test log message', ex
|
82
|
-
assert_slacks_count
|
83
|
-
assert_slacks_includes(['Test log message', ex.message])
|
84
|
-
assert_requested stub
|
85
|
-
end
|
86
|
-
should 'send a message to slack' do
|
87
|
-
stub_request(:post, SystemConfiguration.slack_api_url).to_return(status: 200)
|
88
|
-
SlackNotification.say 'mess'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'notification_test_helper'
|
3
|
-
|
4
|
-
class SmsNotificationTest < ActiveSupport::TestCase
|
5
|
-
include App47Logger
|
6
|
-
include NotificationTestHelper
|
7
|
-
|
8
|
-
should_have_field :sid, type: String, klass: SmsNotification
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
context 'No twilio configuration' do
|
13
|
-
should 'not create a slack notification with log_debug' do
|
14
|
-
sms = SmsNotification.new to: '+15713326267'
|
15
|
-
assert_equal 'sms', sms.delivery_channel
|
16
|
-
sms.message = 'test my sms'
|
17
|
-
assert sms.valid?, sms.errors.inspect
|
18
|
-
sms.send_notification
|
19
|
-
assert sms.reload
|
20
|
-
assert sms.successful?, sms.inspect
|
21
|
-
assert_sms_count
|
22
|
-
end
|
23
|
-
end
|
24
|
-
context 'Twilio configured' do
|
25
|
-
setup do
|
26
|
-
assert SystemConfiguration.configuration.update twilio_account_id: 'a1',
|
27
|
-
twilio_auth_token: 'abc123',
|
28
|
-
twilio_phone_number: '123456789'
|
29
|
-
assert SystemConfiguration.twilio_configured?
|
30
|
-
end
|
31
|
-
should 'send message' do
|
32
|
-
stub = stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/a1/Messages.json").
|
33
|
-
with( body: {"Body"=>"test my sms", "From"=>"123456789", "To"=>"+15713326267"}).
|
34
|
-
to_return(status: 200, body: {
|
35
|
-
"sid": "SM91256e0d99b54ae5a52efdec70b12f0d",
|
36
|
-
"date_created": "Thu, 26 Mar 2020 14:52:03 +0000",
|
37
|
-
"date_updated": "Thu, 26 Mar 2020 14:52:03 +0000",
|
38
|
-
"date_sent": nil,
|
39
|
-
"account_sid": "AC59d5e7ec06ddb4ea3843feb75daeb276",
|
40
|
-
"to": "+15713326267",
|
41
|
-
"from": "+12404938962",
|
42
|
-
"messaging_service_sid": nil,
|
43
|
-
"body": "Hi",
|
44
|
-
"status": "queued",
|
45
|
-
"num_segments": "1",
|
46
|
-
"num_media": "0",
|
47
|
-
"direction": "outbound-api",
|
48
|
-
"api_version": "2010-04-01",
|
49
|
-
"price": nil,
|
50
|
-
"price_unit": "USD",
|
51
|
-
"error_code": nil,
|
52
|
-
"error_message": nil,
|
53
|
-
"uri": "/2010-04-01/Accounts/AC59d5e7ec06ddb4ea3843feb75daeb276/Messages/SM91256e0d99b54ae5a52efdec70b12f0d.json",
|
54
|
-
"subresource_uris": {
|
55
|
-
"media": "/2010-04-01/Accounts/AC59d5e7ec06ddb4ea3843feb75daeb276/Messages/SM91256e0d99b54ae5a52efdec70b12f0d/Media.json"
|
56
|
-
}
|
57
|
-
}.to_json, headers: {})
|
58
|
-
sms = SmsNotification.new to: '+15713326267'
|
59
|
-
sms.message = 'test my sms'
|
60
|
-
assert sms.valid?, sms.errors.inspect
|
61
|
-
sms.send_notification
|
62
|
-
assert sms.reload
|
63
|
-
assert_equal 'SM91256e0d99b54ae5a52efdec70b12f0d', sms.sid
|
64
|
-
assert sms.successful?, sms.inspect
|
65
|
-
assert_sms_count
|
66
|
-
assert_requested stub
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SmtpConfigurationTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
should_have_field :email_address, type: String, klass: SmtpConfiguration
|
6
|
-
should_have_field :domain, type: String, klass: SmtpConfiguration
|
7
|
-
should_have_field :port, type: Integer, default: 587, klass: SmtpConfiguration
|
8
|
-
should_have_field :authentication_method, type: String, klass: SmtpConfiguration
|
9
|
-
should_have_field :confirmation_token, type: String, klass: SmtpConfiguration
|
10
|
-
should_have_field :confirmed, type: Mongoid::Boolean, default: false, klass: SmtpConfiguration
|
11
|
-
should_have_field :verification_message, type: String, klass: SmtpConfiguration
|
12
|
-
|
13
|
-
|
14
|
-
setup do
|
15
|
-
@account = FactoryBot.create(:account)
|
16
|
-
assert_not_nil @account
|
17
|
-
end
|
18
|
-
|
19
|
-
context 'get the config' do
|
20
|
-
should 'not get a nil smtp configuration' do
|
21
|
-
assert_not_nil @account.fetch_smtp_configuration
|
22
|
-
end
|
23
|
-
should 'update token when active' do
|
24
|
-
smtp = @account.fetch_smtp_configuration
|
25
|
-
smtp.active = true
|
26
|
-
assert_nil smtp.confirmation_token
|
27
|
-
refute smtp.confirmed?
|
28
|
-
assert_nil smtp.verification_message
|
29
|
-
smtp.update_token
|
30
|
-
assert_not_nil smtp.verification_message, smtp.inspect
|
31
|
-
assert_not_nil smtp.confirmation_token, smtp.inspect
|
32
|
-
refute smtp.confirmed?, smtp.inspect
|
33
|
-
end
|
34
|
-
should 'dont update token when inactive' do
|
35
|
-
smtp = @account.fetch_smtp_configuration
|
36
|
-
smtp.active = false
|
37
|
-
assert_nil smtp.confirmation_token
|
38
|
-
refute smtp.confirmed?
|
39
|
-
assert_nil smtp.verification_message
|
40
|
-
smtp.update_token
|
41
|
-
assert_not_nil smtp.verification_message, smtp.inspect
|
42
|
-
assert_nil smtp.confirmation_token, smtp.inspect
|
43
|
-
refute smtp.confirmed?, smtp.inspect
|
44
|
-
end
|
45
|
-
should 'validate the token' do
|
46
|
-
smtp = @account.fetch_smtp_configuration
|
47
|
-
smtp.active = true
|
48
|
-
refute smtp.confirmed?
|
49
|
-
smtp.update_token
|
50
|
-
smtp.validate_token(smtp.confirmation_token)
|
51
|
-
assert smtp.confirmed?
|
52
|
-
assert_nil smtp.confirmation_token
|
53
|
-
assert_nil smtp.verification_message
|
54
|
-
end
|
55
|
-
should 'not validate the token' do
|
56
|
-
smtp = @account.fetch_smtp_configuration
|
57
|
-
smtp.active = true
|
58
|
-
refute smtp.confirmed?
|
59
|
-
smtp.update_token
|
60
|
-
smtp.validate_token('abc123')
|
61
|
-
refute smtp.confirmed?
|
62
|
-
assert_not_nil smtp.confirmation_token
|
63
|
-
assert_not_nil smtp.verification_message
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|