rpush 4.2.0 → 5.4.0

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.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +248 -163
  3. data/README.md +103 -17
  4. data/lib/generators/templates/add_gcm.rb +4 -4
  5. data/lib/generators/templates/add_rpush.rb +4 -4
  6. data/lib/generators/templates/rpush.rb +4 -0
  7. data/lib/generators/templates/rpush_3_3_1_updates.rb +2 -2
  8. data/lib/rpush/cli.rb +1 -1
  9. data/lib/rpush/client/active_model.rb +4 -1
  10. data/lib/rpush/client/active_model/adm/data_validator.rb +1 -1
  11. data/lib/rpush/client/active_model/apns/device_token_format_validator.rb +2 -2
  12. data/lib/rpush/client/active_model/apns/notification.rb +9 -1
  13. data/lib/rpush/client/active_model/apns/notification_payload_size_validator.rb +15 -0
  14. data/lib/rpush/client/active_model/apns2/notification.rb +14 -0
  15. data/lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb +1 -1
  16. data/lib/rpush/client/active_model/gcm/notification.rb +2 -2
  17. data/lib/rpush/client/active_model/payload_data_size_validator.rb +1 -1
  18. data/lib/rpush/client/active_model/registration_ids_count_validator.rb +1 -1
  19. data/lib/rpush/client/active_model/webpush/app.rb +41 -0
  20. data/lib/rpush/client/active_model/webpush/notification.rb +66 -0
  21. data/lib/rpush/client/active_record.rb +4 -0
  22. data/lib/rpush/client/active_record/apns/active_record_serializable_notification.rb +65 -0
  23. data/lib/rpush/client/active_record/apns/notification.rb +1 -57
  24. data/lib/rpush/client/active_record/apns2/notification.rb +4 -1
  25. data/lib/rpush/client/active_record/apnsp8/notification.rb +1 -0
  26. data/lib/rpush/client/active_record/webpush/app.rb +11 -0
  27. data/lib/rpush/client/active_record/webpush/notification.rb +12 -0
  28. data/lib/rpush/client/redis.rb +3 -0
  29. data/lib/rpush/client/redis/apns2/notification.rb +1 -0
  30. data/lib/rpush/client/redis/apnsp8/notification.rb +2 -0
  31. data/lib/rpush/client/redis/pushy/notification.rb +0 -1
  32. data/lib/rpush/client/redis/webpush/app.rb +15 -0
  33. data/lib/rpush/client/redis/webpush/notification.rb +15 -0
  34. data/lib/rpush/configuration.rb +3 -2
  35. data/lib/rpush/daemon.rb +4 -1
  36. data/lib/rpush/daemon/apns/feedback_receiver.rb +1 -1
  37. data/lib/rpush/daemon/apns2/delivery.rb +13 -2
  38. data/lib/rpush/daemon/apnsp8/delivery.rb +7 -2
  39. data/lib/rpush/daemon/app_runner.rb +1 -1
  40. data/lib/rpush/daemon/batch.rb +12 -5
  41. data/lib/rpush/daemon/delivery.rb +1 -2
  42. data/lib/rpush/daemon/store/active_record/reconnectable.rb +1 -1
  43. data/lib/rpush/daemon/webpush.rb +10 -0
  44. data/lib/rpush/daemon/webpush/delivery.rb +114 -0
  45. data/lib/rpush/logger.rb +1 -0
  46. data/lib/rpush/version.rb +2 -2
  47. data/spec/functional/apns2_spec.rb +97 -2
  48. data/spec/functional/gcm_priority_spec.rb +40 -0
  49. data/spec/functional/webpush_spec.rb +30 -0
  50. data/spec/spec_helper.rb +2 -0
  51. data/spec/support/simplecov_helper.rb +1 -1
  52. data/spec/unit/client/active_record/adm/app_spec.rb +2 -54
  53. data/spec/unit/client/active_record/adm/notification_spec.rb +2 -39
  54. data/spec/unit/client/active_record/apns/app_spec.rb +3 -26
  55. data/spec/unit/client/active_record/apns/feedback_spec.rb +1 -5
  56. data/spec/unit/client/active_record/apns/notification_spec.rb +29 -293
  57. data/spec/unit/client/active_record/apns2/app_spec.rb +4 -0
  58. data/spec/unit/client/active_record/apns2/notification_spec.rb +65 -0
  59. data/spec/unit/client/active_record/apnsp8/notification_spec.rb +28 -0
  60. data/spec/unit/client/active_record/app_spec.rb +1 -26
  61. data/spec/unit/client/active_record/gcm/app_spec.rb +3 -1
  62. data/spec/unit/client/active_record/gcm/notification_spec.rb +6 -88
  63. data/spec/unit/client/active_record/notification_spec.rb +3 -11
  64. data/spec/unit/client/active_record/pushy/app_spec.rb +2 -13
  65. data/spec/unit/client/active_record/pushy/notification_spec.rb +2 -55
  66. data/spec/unit/client/active_record/shared/app.rb +14 -0
  67. data/spec/unit/{notification_shared.rb → client/active_record/shared/notification.rb} +12 -7
  68. data/spec/unit/client/active_record/webpush/app_spec.rb +6 -0
  69. data/spec/unit/client/active_record/webpush/notification_spec.rb +6 -0
  70. data/spec/unit/client/active_record/wns/badge_notification_spec.rb +1 -11
  71. data/spec/unit/client/active_record/wns/raw_notification_spec.rb +3 -12
  72. data/spec/unit/client/active_record/wpns/app_spec.rb +3 -1
  73. data/spec/unit/client/active_record/wpns/notification_spec.rb +2 -17
  74. data/spec/unit/client/redis/adm/app_spec.rb +5 -0
  75. data/spec/unit/client/redis/adm/notification_spec.rb +5 -0
  76. data/spec/unit/client/redis/apns/app_spec.rb +5 -0
  77. data/spec/unit/client/redis/apns/feedback_spec.rb +5 -0
  78. data/spec/unit/client/redis/apns/notification_spec.rb +50 -0
  79. data/spec/unit/client/redis/apns2/app_spec.rb +4 -0
  80. data/spec/unit/client/redis/apns2/notification_spec.rb +50 -0
  81. data/spec/unit/client/redis/apnsp8/notification_spec.rb +29 -0
  82. data/spec/unit/client/redis/app_spec.rb +5 -0
  83. data/spec/unit/client/redis/gcm/app_spec.rb +5 -0
  84. data/spec/unit/client/redis/gcm/notification_spec.rb +5 -0
  85. data/spec/unit/client/redis/notification_spec.rb +5 -0
  86. data/spec/unit/client/redis/pushy/app_spec.rb +5 -0
  87. data/spec/unit/client/redis/pushy/notification_spec.rb +5 -0
  88. data/spec/unit/client/redis/webpush/app_spec.rb +5 -0
  89. data/spec/unit/client/redis/webpush/notification_spec.rb +5 -0
  90. data/spec/unit/client/redis/wns/badge_notification_spec.rb +5 -0
  91. data/spec/unit/client/redis/wns/raw_notification_spec.rb +22 -0
  92. data/spec/unit/client/redis/wpns/app_spec.rb +5 -0
  93. data/spec/unit/client/redis/wpns/notification_spec.rb +5 -0
  94. data/spec/unit/client/shared/adm/app.rb +51 -0
  95. data/spec/unit/client/shared/adm/notification.rb +39 -0
  96. data/spec/unit/client/shared/apns/app.rb +29 -0
  97. data/spec/unit/client/shared/apns/feedback.rb +9 -0
  98. data/spec/unit/client/shared/apns/notification.rb +262 -0
  99. data/spec/unit/client/shared/app.rb +17 -0
  100. data/spec/unit/client/shared/gcm/app.rb +4 -0
  101. data/spec/unit/client/shared/gcm/notification.rb +77 -0
  102. data/spec/unit/client/shared/notification.rb +10 -0
  103. data/spec/unit/client/shared/pushy/app.rb +17 -0
  104. data/spec/unit/client/shared/pushy/notification.rb +55 -0
  105. data/spec/unit/client/shared/webpush/app.rb +33 -0
  106. data/spec/unit/client/shared/webpush/notification.rb +83 -0
  107. data/spec/unit/client/shared/wns/badge_notification.rb +15 -0
  108. data/spec/unit/client/shared/wns/raw_notification.rb +21 -0
  109. data/spec/unit/client/shared/wpns/app.rb +4 -0
  110. data/spec/unit/client/shared/wpns/notification.rb +18 -0
  111. data/spec/unit/daemon/batch_spec.rb +50 -2
  112. data/spec/unit/daemon/delivery_spec.rb +10 -0
  113. data/spec/unit/daemon/pushy/delivery_spec.rb +5 -3
  114. data/spec/unit/daemon/shared/store.rb +312 -0
  115. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +7 -7
  116. data/spec/unit/daemon/store/active_record_spec.rb +2 -290
  117. data/spec/unit/daemon/store/redis_spec.rb +2 -291
  118. data/spec/unit/daemon/webpush/delivery_spec.rb +144 -0
  119. data/spec/unit_spec_helper.rb +3 -0
  120. metadata +135 -12
  121. data/lib/rpush/client/active_model/apns/binary_notification_validator.rb +0 -16
@@ -1,9 +1,10 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::Wns::RawNotification do
4
+ it_behaves_like 'Rpush::Client::Wns::RawNotification'
4
5
  let(:notification) do
5
- notif = Rpush::Client::ActiveRecord::Wns::RawNotification.new
6
- notif.app = Rpush::Client::ActiveRecord::Wns::App.new(name: "aname")
6
+ notif = described_class.new
7
+ notif.app = Rpush::Wns::App.create!(name: "MyApp", client_id: "someclient", client_secret: "somesecret")
7
8
  notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
8
9
  notif.data = { foo: 'foo', bar: 'bar' }
9
10
  notif
@@ -13,14 +14,4 @@ describe Rpush::Client::ActiveRecord::Wns::RawNotification do
13
14
  allow(notification).to receive(:payload_data_size) { 5121 }
14
15
  expect(notification.valid?).to be(false)
15
16
  end
16
-
17
- it 'allows exact payload of 5 KB' do
18
- allow(notification).to receive(:payload_data_size) { 5120 }
19
- expect(notification.valid?).to be(true)
20
- end
21
-
22
- it 'allows the size of payload under 5 KB' do
23
- allow(notification).to receive(:payload_data_size) { 5119 }
24
- expect(notification.valid?).to be(true)
25
- end
26
17
  end if active_record?
@@ -1,4 +1,6 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Client::ActiveRecord::Wpns::App do
4
- end
4
+ it_behaves_like 'Rpush::Client::Wpns::App'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::App'
6
+ end if active_record?
@@ -1,21 +1,6 @@
1
1
  require 'unit_spec_helper'
2
- require 'unit/notification_shared.rb'
3
2
 
4
3
  describe Rpush::Client::ActiveRecord::Wpns::Notification do
5
- it_should_behave_like 'an Notification subclass'
6
- let(:app) { Rpush::Client::ActiveRecord::Wpns::App.create!(name: 'test', auth_key: 'abc') }
7
- let(:notification_class) { Rpush::Client::ActiveRecord::Wpns::Notification }
8
- let(:notification) { notification_class.new }
9
-
10
- it "should have an url in the uri parameter" do
11
- notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(uri: "somthing")
12
- notification.valid?
13
- expect(notification.errors[:uri]).to include('is invalid')
14
- end
15
-
16
- it "should be invalid if there's no data" do
17
- notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(data: {})
18
- notification.valid?
19
- expect(notification.errors[:data]).to include("can't be blank")
20
- end
4
+ it_behaves_like 'Rpush::Client::Wpns::Notification'
5
+ it_behaves_like 'Rpush::Client::ActiveRecord::Notification'
21
6
  end if active_record?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Adm::App do
4
+ it_behaves_like 'Rpush::Client::Adm::App'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Adm::Notification do
4
+ it_behaves_like 'Rpush::Client::Adm::Notification'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Apns::App do
4
+ it_behaves_like 'Rpush::Client::Apns::App'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Apns::Feedback do
4
+ it_behaves_like 'Rpush::Client::Apns::Feedback'
5
+ end if redis?
@@ -0,0 +1,50 @@
1
+ # encoding: US-ASCII
2
+
3
+ require "unit_spec_helper"
4
+
5
+ describe Rpush::Client::Redis::Apns::Notification do
6
+ it_behaves_like 'Rpush::Client::Apns::Notification'
7
+
8
+ it "should validate the length of the binary conversion of the notification" do
9
+ notification = described_class.new
10
+ notification.app = Rpush::Apns2::App.create(name: 'test', environment: 'development')
11
+ notification.device_token = "a" * 108
12
+ notification.alert = ""
13
+
14
+ notification.alert << "a" until notification.payload.bytesize == 2048
15
+ expect(notification.valid?).to be_truthy
16
+ expect(notification.errors[:base]).to be_empty
17
+
18
+ notification.alert << "a"
19
+ expect(notification.valid?).to be_falsey
20
+ expect(notification.errors[:base].include?("APN notification cannot be larger than 2048 bytes. Try condensing your alert and device attributes.")).to be_truthy
21
+ end
22
+
23
+ it "should default the sound to 'default'" do
24
+ notification = described_class.new
25
+ expect(notification.sound).to eq('default')
26
+ end
27
+
28
+ # skipping these tests because data= for redis doesn't merge existing data
29
+ xit 'does not overwrite the mutable-content flag when setting attributes for the device' do
30
+ notification.mutable_content = true
31
+ notification.data = { 'hi' => 'mom' }
32
+ expect(notification.as_json['aps']['mutable-content']).to eq 1
33
+ expect(notification.as_json['hi']).to eq 'mom'
34
+ end
35
+
36
+ xit 'does not overwrite the content-available flag when setting attributes for the device' do
37
+ notification.content_available = true
38
+ notification.data = { 'hi' => 'mom' }
39
+ expect(notification.as_json['aps']['content-available']).to eq 1
40
+ expect(notification.as_json['hi']).to eq 'mom'
41
+ end
42
+
43
+ # redis does not use alert_is_json - unclear if that is a bug or desired behavior
44
+ xit 'does confuse a JSON looking string as JSON if the alert_is_json attribute is not present' do
45
+ notification = described_class.new
46
+ allow(notification).to receive_messages(has_attribute?: false)
47
+ notification.alert = "{\"one\":2}"
48
+ expect(notification.alert).to eq('one' => 2)
49
+ end
50
+ end if redis?
@@ -0,0 +1,4 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Apns2::App do
4
+ end if redis?
@@ -0,0 +1,50 @@
1
+ # encoding: US-ASCII
2
+
3
+ require "unit_spec_helper"
4
+
5
+ describe Rpush::Client::Redis::Apns2::Notification do
6
+ it_behaves_like 'Rpush::Client::Apns::Notification'
7
+
8
+ it "should validate the length of the binary conversion of the notification" do
9
+ notification = described_class.new
10
+ notification.app = Rpush::Apns2::App.create(name: 'test', environment: 'development')
11
+ notification.device_token = "a" * 108
12
+ notification.alert = ""
13
+
14
+ notification.alert << "a" until notification.payload.bytesize == 4096
15
+ expect(notification.valid?).to be_truthy
16
+ expect(notification.errors[:base]).to be_empty
17
+
18
+ notification.alert << "a"
19
+ expect(notification.valid?).to be_falsey
20
+ expect(notification.errors[:base].include?("APN notification cannot be larger than 4096 bytes. Try condensing your alert and device attributes.")).to be_truthy
21
+ end
22
+
23
+ it "should default the sound to 'default'" do
24
+ notification = described_class.new
25
+ expect(notification.sound).to eq('default')
26
+ end
27
+
28
+ # skipping these tests because data= for redis doesn't merge existing data
29
+ xit 'does not overwrite the mutable-content flag when setting attributes for the device' do
30
+ notification.mutable_content = true
31
+ notification.data = { 'hi' => 'mom' }
32
+ expect(notification.as_json['aps']['mutable-content']).to eq 1
33
+ expect(notification.as_json['hi']).to eq 'mom'
34
+ end
35
+
36
+ xit 'does not overwrite the content-available flag when setting attributes for the device' do
37
+ notification.content_available = true
38
+ notification.data = { 'hi' => 'mom' }
39
+ expect(notification.as_json['aps']['content-available']).to eq 1
40
+ expect(notification.as_json['hi']).to eq 'mom'
41
+ end
42
+
43
+ # redis does not use alert_is_json - unclear if that is a bug or desired behavior
44
+ xit 'does confuse a JSON looking string as JSON if the alert_is_json attribute is not present' do
45
+ notification = described_class.new
46
+ allow(notification).to receive_messages(has_attribute?: false)
47
+ notification.alert = "{\"one\":2}"
48
+ expect(notification.alert).to eq('one' => 2)
49
+ end
50
+ end if redis?
@@ -0,0 +1,29 @@
1
+ require "unit_spec_helper"
2
+
3
+ describe Rpush::Client::Redis::Apnsp8::Notification do
4
+ after do
5
+ Rpush::Apnsp8::App.all.select { |a| a.environment == "development" && a.apn_key == "1" }.each(&:destroy)
6
+ end
7
+
8
+ it_behaves_like "Rpush::Client::Apns::Notification"
9
+
10
+ it "should validate the length of the binary conversion of the notification", :aggregate_failures do
11
+ notification = described_class.new
12
+ notification.app = Rpush::Apnsp8::App.create(apn_key: "1",
13
+ apn_key_id: "2",
14
+ name: 'test',
15
+ environment: 'development',
16
+ team_id: "3",
17
+ bundle_id: "4")
18
+ notification.device_token = "a" * 108
19
+ notification.alert = ""
20
+
21
+ notification.alert << "a" until notification.payload.bytesize == 4096
22
+ expect(notification.valid?).to be_truthy
23
+ expect(notification.errors[:base]).to be_empty
24
+
25
+ notification.alert << "a"
26
+ expect(notification.valid?).to be_falsey
27
+ expect(notification.errors[:base].include?("APN notification cannot be larger than 4096 bytes. Try condensing your alert and device attributes.")).to be_truthy
28
+ end
29
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::App do
4
+ it_behaves_like 'Rpush::Client::App'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Gcm::App do
4
+ it_behaves_like 'Rpush::Client::Gcm::App'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Gcm::Notification do
4
+ it_behaves_like 'Rpush::Client::Gcm::Notification'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Notification do
4
+ it_behaves_like 'Rpush::Client::Notification'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Pushy::App do
4
+ it_behaves_like 'Rpush::Client::Pushy::App'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Pushy::Notification do
4
+ it_behaves_like 'Rpush::Client::Pushy::Notification'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Webpush::App do
4
+ it_behaves_like 'Rpush::Client::Webpush::App'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Webpush::Notification do
4
+ it_behaves_like 'Rpush::Client::Webpush::Notification'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Wns::BadgeNotification do
4
+ it_behaves_like 'Rpush::Client::Wns::BadgeNotification'
5
+ end if redis?
@@ -0,0 +1,22 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Wns::RawNotification do
4
+ it_behaves_like 'Rpush::Client::Wns::RawNotification'
5
+
6
+ subject(:notification) do
7
+ notif = described_class.new
8
+ notif.app = Rpush::Wns::App.create!(name: "MyApp", client_id: "someclient", client_secret: "somesecret")
9
+ notif.uri = 'https://db5.notify.windows.com/?token=TOKEN'
10
+ notif.data = { foo: 'foo', bar: 'bar' }
11
+ notif
12
+ end
13
+
14
+ # This fails because the length validation is only on active record
15
+ # Attempting to move to active model in rails 6 fails
16
+ # because wns_notification#as_json is not defined
17
+ # and the active_model#as_json version results in a stack level too deep error
18
+ xit 'does not allow the size of payload over 5 KB' do
19
+ allow(notification).to receive(:payload_data_size) { 5121 }
20
+ expect(notification.valid?).to be(false)
21
+ end
22
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Wpns::App do
4
+ it_behaves_like 'Rpush::Client::Wpns::App'
5
+ end if redis?
@@ -0,0 +1,5 @@
1
+ require 'unit_spec_helper'
2
+
3
+ describe Rpush::Client::Redis::Wpns::Notification do
4
+ it_behaves_like 'Rpush::Client::Wpns::Notification'
5
+ end if redis?
@@ -0,0 +1,51 @@
1
+ require 'unit_spec_helper'
2
+
3
+ shared_examples 'Rpush::Client::Adm::App' do
4
+ subject { described_class.new(name: 'test', environment: 'development', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
5
+
6
+ it 'should be valid if properly instantiated' do
7
+ expect(subject).to be_valid
8
+ end
9
+
10
+ it 'should be invalid if name' do
11
+ subject.name = nil
12
+ expect(subject).not_to be_valid
13
+ expect(subject.errors[:name]).to eq ["can't be blank"]
14
+ end
15
+
16
+ it 'should be invalid if missing client_id' do
17
+ subject.client_id = nil
18
+ expect(subject).not_to be_valid
19
+ expect(subject.errors[:client_id]).to eq ["can't be blank"]
20
+ end
21
+
22
+ it 'should be invalid if missing client_secret' do
23
+ subject.client_secret = nil
24
+ expect(subject).not_to be_valid
25
+ expect(subject.errors[:client_secret]).to eq ["can't be blank"]
26
+ end
27
+
28
+ describe '#access_token_expired?' do
29
+ before(:each) do
30
+ Timecop.freeze(Time.now)
31
+ end
32
+
33
+ after do
34
+ Timecop.return
35
+ end
36
+
37
+ it 'should return true if access_token_expiration is nil' do
38
+ expect(subject.access_token_expired?).to eq(true)
39
+ end
40
+
41
+ it 'should return true if expired' do
42
+ subject.access_token_expiration = Time.now - 5.minutes
43
+ expect(subject.access_token_expired?).to eq(true)
44
+ end
45
+
46
+ it 'should return false if not expired' do
47
+ subject.access_token_expiration = Time.now + 5.minutes
48
+ expect(subject.access_token_expired?).to eq(false)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,39 @@
1
+ require 'unit_spec_helper'
2
+
3
+ shared_examples 'Rpush::Client::Adm::Notification' do
4
+ let(:app) { Rpush::Adm::App.create!(name: 'test', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET') }
5
+ let(:notification) { described_class.new }
6
+
7
+ it "has a 'data' payload limit of 6144 bytes" do
8
+ notification.data = { key: "a" * 6144 }
9
+ expect(notification.valid?).to eq(false)
10
+ expect(notification.errors[:base]).to eq ["Notification payload data cannot be larger than 6144 bytes."]
11
+ end
12
+
13
+ it 'limits the number of registration ids to 100' do
14
+ notification.registration_ids = ['a'] * (100 + 1)
15
+ expect(notification.valid?).to eq(false)
16
+ expect(notification.errors[:base]).to eq ["Number of registration_ids cannot be larger than 100."]
17
+ end
18
+
19
+ it 'validates data can be blank if collapse_key is set' do
20
+ notification.app = app
21
+ notification.registration_ids = ['a']
22
+ notification.collapse_key = 'test'
23
+ notification.data = nil
24
+ expect(notification.valid?).to eq(true)
25
+ expect(notification.errors[:data]).to be_empty
26
+ end
27
+
28
+ it 'validates data is present if collapse_key is not set' do
29
+ notification.collapse_key = nil
30
+ notification.data = nil
31
+ expect(notification.valid?).to eq(false)
32
+ expect(notification.errors[:data]).to eq ['must be set unless collapse_key is specified']
33
+ end
34
+
35
+ it 'includes expiresAfter in the payload' do
36
+ notification.expiry = 100
37
+ expect(notification.as_json['expiresAfter']).to eq 100
38
+ end
39
+ end
@@ -0,0 +1,29 @@
1
+ require 'unit_spec_helper'
2
+
3
+ shared_examples 'Rpush::Client::Apns::App' do
4
+ it 'does not validate an app with an invalid certificate' do
5
+ app = described_class.new(name: 'test', environment: 'development', certificate: 'foo')
6
+ app.valid?
7
+ expect(app.errors[:certificate]).to eq ['value must contain a certificate and a private key.']
8
+ end
9
+
10
+ it 'validates a certificate without a password' do
11
+ app = described_class.new name: 'test', environment: 'development', certificate: TEST_CERT
12
+ app.valid?
13
+ expect(app.errors[:certificate]).to eq []
14
+ end
15
+
16
+ it 'validates a certificate with a password' do
17
+ app = described_class.new name: 'test', environment: 'development',
18
+ certificate: TEST_CERT_WITH_PASSWORD, password: 'fubar'
19
+ app.valid?
20
+ expect(app.errors[:certificate]).to eq []
21
+ end
22
+
23
+ it 'validates a certificate with an incorrect password' do
24
+ app = described_class.new name: 'test', environment: 'development',
25
+ certificate: TEST_CERT_WITH_PASSWORD, password: 'incorrect'
26
+ app.valid?
27
+ expect(app.errors[:certificate]).to eq ['value must contain a certificate and a private key.']
28
+ end
29
+ end