web47core 0.0.9 → 0.0.10

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.
@@ -12,6 +12,47 @@ class SlackNotificationTest < ActiveSupport::TestCase
12
12
  config.update_attribute :slack_api_url, 'https://slack.com?api_key'
13
13
  end
14
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
15
56
  context 'No slack notification' do
16
57
  should 'not create a slack notification with log_debug' do
17
58
  App47Logger.expects(:log_message).with(:warn, 'Test log message').once
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,66 @@
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
@@ -18,9 +18,11 @@ require 'rubygems'
18
18
  require 'aws-sdk-ec2'
19
19
  require 'mongoid'
20
20
  require 'delayed_job_mongoid'
21
+ require 'email_format'
21
22
  require 'liquid'
22
23
  require 'jwt'
23
24
  require 'rest-client'
25
+ require 'twilio-ruby'
24
26
  require_relative 'rails_setup'
25
27
  require 'rails/test_help'
26
28
  require 'test/unit'
@@ -40,13 +42,14 @@ else
40
42
  Minitest::Reporters.use!(Minitest::Reporters::RubyMineReporter.new)
41
43
  end
42
44
 
43
- require 'test_models_helper'
45
+ require_relative 'test_models_helper'
44
46
 
45
47
  module ActiveSupport
46
48
  class TestCase
47
49
  FactoryBot.find_definitions
48
50
  Shoulda.autoload_macros Rails.root.to_s
49
51
  Mongoid.load!('./test/fixtures/mongoid.yml')
52
+ DatabaseCleaner.strategy = :truncation
50
53
  setup do
51
54
  mocha_setup
52
55
  DatabaseCleaner.clean
@@ -69,6 +72,7 @@ module ActionDispatch
69
72
  class IntegrationTest
70
73
  # include Devise::Test::IntegrationHelpers
71
74
  Shoulda.autoload_macros Rails.root.to_s
75
+ DatabaseCleaner.strategy = :truncation
72
76
  Mongoid.load!('./test/fixtures/mongoid.yml')
73
77
  setup do
74
78
  mocha_setup
@@ -1,14 +1,14 @@
1
1
  #
2
2
  # Spec of App47 Web Core GEM
3
3
  #
4
- lib = File.expand_path('../lib', __FILE__)
4
+ lib = File.expand_path('lib', __dir__)
5
5
 
6
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
7
 
8
8
  Gem::Specification.new do |spec|
9
9
  spec.required_ruby_version = '~> 2.4.1'
10
10
  spec.name = 'web47core'
11
- spec.version = '0.0.9'
11
+ spec.version = '0.0.10'
12
12
  spec.authors = ['Chris Schroeder']
13
13
  spec.email = ['chris@app47.com']
14
14
  spec.summary = 'App47 Web Core Library.'
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  # spec.add_dependency 'json'
25
- spec.add_runtime_dependency 'aws-sdk-ec2', '> 1.140', '<= 1.160'
26
25
  spec.add_runtime_dependency 'activesupport', '~> 5.0'
26
+ spec.add_runtime_dependency 'aws-sdk-ec2', '> 1.140', '<= 1.160'
27
27
  spec.add_runtime_dependency 'delayed_job_mongoid', '~> 2.3'
28
+ spec.add_runtime_dependency 'email_format'
28
29
  spec.add_runtime_dependency 'haml'
29
30
  spec.add_runtime_dependency 'jwt'
30
31
  spec.add_runtime_dependency 'liquid'
@@ -33,6 +34,8 @@ Gem::Specification.new do |spec|
33
34
  spec.add_runtime_dependency 'redis', '~> 4.1'
34
35
  spec.add_runtime_dependency 'redis-rails', '> 5', '< 6'
35
36
  spec.add_runtime_dependency 'rest-client', '<= 2.1.0', '>=0'
37
+ spec.add_runtime_dependency 'twilio-ruby', '<= 4.13', '>= 3.0'
38
+ spec.add_runtime_dependency 'tzinfo'
36
39
  spec.add_development_dependency 'bundler'
37
40
  spec.add_development_dependency 'codacy-coverage', '~> 2.1.0'
38
41
  spec.add_development_dependency 'database_cleaner'
@@ -45,7 +48,7 @@ Gem::Specification.new do |spec|
45
48
  spec.add_development_dependency 'minitest-reporters'
46
49
  spec.add_development_dependency 'mocha'
47
50
  spec.add_development_dependency 'shoulda', '= 3.6.0'
48
- spec.add_development_dependency 'shoulda-matchers', '= 3.1.2'
51
+ spec.add_development_dependency 'shoulda-matchers'
49
52
  spec.add_development_dependency 'simplecov', '= 0.16.1'
50
53
  spec.add_development_dependency 'test-unit'
51
54
  spec.add_development_dependency 'vcr'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web47core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schroeder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-26 00:00:00.000000000 Z
11
+ date: 2020-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: aws-sdk-ec2
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,33 +45,33 @@ dependencies:
31
45
  - !ruby/object:Gem::Version
32
46
  version: '1.160'
33
47
  - !ruby/object:Gem::Dependency
34
- name: activesupport
48
+ name: delayed_job_mongoid
35
49
  requirement: !ruby/object:Gem::Requirement
36
50
  requirements:
37
51
  - - "~>"
38
52
  - !ruby/object:Gem::Version
39
- version: '5.0'
53
+ version: '2.3'
40
54
  type: :runtime
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
58
  - - "~>"
45
59
  - !ruby/object:Gem::Version
46
- version: '5.0'
60
+ version: '2.3'
47
61
  - !ruby/object:Gem::Dependency
48
- name: delayed_job_mongoid
62
+ name: email_format
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
- - - "~>"
65
+ - - ">="
52
66
  - !ruby/object:Gem::Version
53
- version: '2.3'
67
+ version: '0'
54
68
  type: :runtime
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
- - - "~>"
72
+ - - ">="
59
73
  - !ruby/object:Gem::Version
60
- version: '2.3'
74
+ version: '0'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: haml
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +208,40 @@ dependencies:
194
208
  - - "<="
195
209
  - !ruby/object:Gem::Version
196
210
  version: 2.1.0
211
+ - !ruby/object:Gem::Dependency
212
+ name: twilio-ruby
213
+ requirement: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - ">="
216
+ - !ruby/object:Gem::Version
217
+ version: '3.0'
218
+ - - "<="
219
+ - !ruby/object:Gem::Version
220
+ version: '4.13'
221
+ type: :runtime
222
+ prerelease: false
223
+ version_requirements: !ruby/object:Gem::Requirement
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ version: '3.0'
228
+ - - "<="
229
+ - !ruby/object:Gem::Version
230
+ version: '4.13'
231
+ - !ruby/object:Gem::Dependency
232
+ name: tzinfo
233
+ requirement: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ type: :runtime
239
+ prerelease: false
240
+ version_requirements: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - ">="
243
+ - !ruby/object:Gem::Version
244
+ version: '0'
197
245
  - !ruby/object:Gem::Dependency
198
246
  name: bundler
199
247
  requirement: !ruby/object:Gem::Requirement
@@ -366,16 +414,16 @@ dependencies:
366
414
  name: shoulda-matchers
367
415
  requirement: !ruby/object:Gem::Requirement
368
416
  requirements:
369
- - - '='
417
+ - - ">="
370
418
  - !ruby/object:Gem::Version
371
- version: 3.1.2
419
+ version: '0'
372
420
  type: :development
373
421
  prerelease: false
374
422
  version_requirements: !ruby/object:Gem::Requirement
375
423
  requirements:
376
- - - '='
424
+ - - ">="
377
425
  - !ruby/object:Gem::Version
378
- version: 3.1.2
426
+ version: '0'
379
427
  - !ruby/object:Gem::Dependency
380
428
  name: simplecov
381
429
  requirement: !ruby/object:Gem::Requirement
@@ -447,15 +495,20 @@ files:
447
495
  - LICENSE
448
496
  - README.md
449
497
  - Rakefile
498
+ - config/locales/en.yml
450
499
  - lib/app/models/concerns/app47_logger.rb
451
500
  - lib/app/models/concerns/cdn_url.rb
452
501
  - lib/app/models/concerns/core_account.rb
453
502
  - lib/app/models/concerns/core_system_configuration.rb
503
+ - lib/app/models/concerns/email_able.rb
504
+ - lib/app/models/concerns/search_able.rb
454
505
  - lib/app/models/concerns/standard_model.rb
506
+ - lib/app/models/concerns/time_zone_able.rb
455
507
  - lib/app/models/email_notification.rb
456
508
  - lib/app/models/email_template.rb
457
509
  - lib/app/models/notification.rb
458
510
  - lib/app/models/notification_template.rb
511
+ - lib/app/models/redis_configuration.rb
459
512
  - lib/app/models/slack_notification.rb
460
513
  - lib/app/models/sms_notification.rb
461
514
  - lib/app/models/smtp_configuration.rb
@@ -467,13 +520,23 @@ files:
467
520
  - test/factories/account_factories.rb
468
521
  - test/factories/notification_factories.rb
469
522
  - test/fixtures/mongoid.yml
523
+ - test/fixtures/redis/host.yml
524
+ - test/fixtures/redis/options.yml
525
+ - test/fixtures/redis/sentinel.yml
526
+ - test/fixtures/redis/url.yml
470
527
  - test/models/app47_logger_test.rb
471
528
  - test/models/concerns/cdn_url_test.rb
529
+ - test/models/concerns/email_able_test.rb
530
+ - test/models/concerns/search_able_test.rb
472
531
  - test/models/concerns/standard_model_test.rb
473
532
  - test/models/concerns/system_configuration_test.rb
533
+ - test/models/concerns/time_zone_able_test.rb
474
534
  - test/models/email_notification_test.rb
475
535
  - test/models/notification_test.rb
536
+ - test/models/redis_configuration_test.rb
476
537
  - test/models/slack_notification_test.rb
538
+ - test/models/sms_notification_test.rb
539
+ - test/models/smtp_configuration_test.rb
477
540
  - test/notification_test_helper.rb
478
541
  - test/rails_setup.rb
479
542
  - test/shoulda_macros/mongoid.rb
@@ -507,13 +570,23 @@ test_files:
507
570
  - test/factories/account_factories.rb
508
571
  - test/factories/notification_factories.rb
509
572
  - test/fixtures/mongoid.yml
573
+ - test/fixtures/redis/host.yml
574
+ - test/fixtures/redis/options.yml
575
+ - test/fixtures/redis/sentinel.yml
576
+ - test/fixtures/redis/url.yml
510
577
  - test/models/app47_logger_test.rb
511
578
  - test/models/concerns/cdn_url_test.rb
579
+ - test/models/concerns/email_able_test.rb
580
+ - test/models/concerns/search_able_test.rb
512
581
  - test/models/concerns/standard_model_test.rb
513
582
  - test/models/concerns/system_configuration_test.rb
583
+ - test/models/concerns/time_zone_able_test.rb
514
584
  - test/models/email_notification_test.rb
515
585
  - test/models/notification_test.rb
586
+ - test/models/redis_configuration_test.rb
516
587
  - test/models/slack_notification_test.rb
588
+ - test/models/sms_notification_test.rb
589
+ - test/models/smtp_configuration_test.rb
517
590
  - test/notification_test_helper.rb
518
591
  - test/rails_setup.rb
519
592
  - test/shoulda_macros/mongoid.rb